sitwhere REST 测试

        为了加深对sitewhere REST api的了解,本文将对sitewhere所提供的REST api进行测试并进行梳理。笔者能力有限,望不吝赐教。


站点

创建一下新站点:POST/sitewhere/api/sites/

http://localhost:8080/sitewhere/api/sites

{
  "token" : "",
  "name" : "REST Site",
  "description" : "REST site that contains many heavy equipment assets",
  "imageUrl" : "https://s3.amazonaws.com/sitewhere-demo/construction/construction.jpg",
  "map" : {
    "type" : "mapquest",
    "metadata" : {
      "zoomLevel" : "15",
      "centerLatitude" : "33.10469794977326",
      "centerLongitude" : "-83.23966646194458"
    }
  },
  "metadata" : { }
}
=====================================================================================
{
  "createdDate": "2018-04-16T12:46:45.060+0800",
  "createdBy": "admin",
  "deleted": false,
  "token": "",
  "name": "REST Site",
  "description": "REST site that contains many heavy equipment assets",
  "imageUrl": "https://s3.amazonaws.com/sitewhere-demo/construction/construction.jpg",
  "map": {
    "type": "mapquest",
    "metadata": {
      "zoomLevel": "15",
      "centerLatitude": "33.10469794977326",
      "centerLongitude": "-83.23966646194458"
    }
  },
  "metadata": {}
}

注:token,如果请求中没有带token,则系统自动生成唯一token。


按照token删除站点:DELETE/sitewhere/api/sites/{siteToken}

siteTokenUnique token that identifies site
forceDelete permanentlyfalse
http://localhost:8080/sitewhere/api/sites/ef2f82cf-e164-4a5c-b054-ac6ea8484e77?force=true
==================================================================================
{
  "createdDate": "2018-04-16T13:51:40.058+0800",
  "createdBy": "admin",
  "deleted": false,
  "token": "ef2f82cf-e164-4a5c-b054-ac6ea8484e77",
  "name": "12",
  "description": "12",
  "imageUrl": "12",
  "map": {
    "type": "mapquest",
    "metadata": {
      "zoomLevel": "",
      "centerLatitude": "",
      "centerLongitude": ""
    }
  },
  "metadata": {}
}

租户

创建一个新租户:POST/sitewhere/api/tenants/


用户

创建一个新用户:POST/sitewhere/api/users/

http://localhost:8080/sitewhere/api/users

{
  "username" : "orchid",
  "password" : "orchid",
  "firstName" : "orchid",
  "lastName" : "Ocean",
  "authorities" : [ "ROLE_REST", "ROLE_ADMIN_CONSOLE", "ROLE_ADMINISTER_USERS" ],
  "metadata" : { }
}

{
  "createdDate": "2018-04-16T14:03:37.381+0800",
  "createdBy": "admin",
  "deleted": false,
  "username": "orchid",
  "hashedPassword": "cce6d302e13b5371bc588f0c4fc078bc4d34b871",
  "firstName": "orchid",
  "lastName": "Ocean",
  "status": "Active",
  "authorities": [
    "ROLE_REST",
    "ROLE_ADMIN_CONSOLE",
    "ROLE_ADMINISTER_USERS"
  ],
  "metadata": {}
}


事件

根据事件ID获取事件:GET/sitewhere/api/events/{eventId}

如果结果是测量事件,则响应将与以下内容类似:

{
  "id" : "234203504574",
  "eventType" : "Measurements",
  "siteToken" : "bb105f8d-3150-41f5-b9d1-db04965668d3",
  "deviceAssignmentToken" : "1ad74fe3-2cbf-443f-aede-9ec70a9a4ab5",
  "assignmentType" : "Associated",
  "assetModuleId" : "ac-persons",
  "assetId" : "derek",
  "eventDate" : "2016-12-10T13:11:45.119-0500",
  "receivedDate" : "2016-12-10T13:11:45.119-0500",
  "measurements" : {
    "engine.temperature" : 86.21,
    "fuel.level" : 32.68
  },
  "measurementsSummary" : "engine.temperature: 86.21, fuel.level: 32.68",
  "metadata" : { }
}
响应
如果结果是位置事件,则回复将与以下内容类似:

{
  "id" : "203948023656",
  "eventType" : "Location",
  "siteToken" : "bb105f8d-3150-41f5-b9d1-db04965668d3",
  "deviceAssignmentToken" : "1ad74fe3-2cbf-443f-aede-9ec70a9a4ab5",
  "assignmentType" : "Associated",
  "assetModuleId" : "ac-persons",
  "assetId" : "derek",
  "eventDate" : "2016-12-10T13:11:45.117-0500",
  "receivedDate" : "2016-12-10T13:11:45.117-0500",
  "latitude" : 34.103270338359664,
  "longitude" : -84.23874458667342,
  "elevation" : 0.0,
  "metadata" : { }
}
响应
如果结果是一个警报事件,则该响应将与以下内容类似:

{
  "id" : "239472398473",
  "eventType" : "Alert",
  "siteToken" : "bb105f8d-3150-41f5-b9d1-db04965668d3",
  "deviceAssignmentToken" : "1ad74fe3-2cbf-443f-aede-9ec70a9a4ab5",
  "assignmentType" : "Associated",
  "assetModuleId" : "ac-persons",
  "assetId" : "derek",
  "eventDate" : "2016-12-10T13:11:45.120-0500",
  "receivedDate" : "2016-12-10T13:11:45.120-0500",
  "source" : "Device",
  "level" : "Warning",
  "type" : "engine.overheat",
  "message" : "Engine temperature is at top of operating range.",
  "metadata" : { }
}

设备

创建一个新设备:POST/sitewhere/api/devices/

http://localhost:8080/sitewhere/api/devices

{
  "hardwareId" : "test1234567",
  "siteToken" : "bb105f8d-3150-41f5-b9d1-db04965668d3",
  "specificationToken" : "82043707-9e3d-441f-bdcc-33cf0f4f7260",
  "comments" : "Equipment tracker."
}

{
  "createdDate": "2018-04-16T14:30:29.735+0800",
  "createdBy": "admin",
  "deleted": false,
  "hardwareId": "test1234567",
  "siteToken": "bb105f8d-3150-41f5-b9d1-db04965668d3",
  "deviceElementMappings": [],
  "comments": "Equipment tracker.",
  "specification": {
    "createdDate": "2018-03-22T15:40:56.162+0800",
    "createdBy": "system",
    "deleted": false,
    "token": "82043707-9e3d-441f-bdcc-33cf0f4f7260",
    "name": "MeiTrack GPS",
    "assetModuleId": "fs-devices",
    "assetId": "175",
    "assetName": "MeiTrack MT90",
    "assetImageUrl": "https://s3.amazonaws.com/sitewhere-demo/construction/meitrack/mt90.jpg",
    "containerPolicy": "Standalone",
    "metadata": {}
  },
  "metadata": {}
}



参考:https://blog.csdn.net/orchidofocean/article/details/79678768#t14

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值