nbiot电信云北向开发---基于LiteNAdemo_https例程

本文将借助于官方的例程实现nbiot的定位功能。

 

一.功能分析

1.数据上报

当bc20上报数据时,电信云平台能够将数据自动推送到后台服务器。(目前暂时由后台服务器发送请求,自动推送需要ca证书)

 

 

(1)鉴权

电信云采用token来保障安全。使用对应的appid和secret获取token。调用其他接口时需要附上token。

请求示例:

Method: POST

request:

https://server:port/iocm/app/sec/v1.1.0/login

Content-Type:application/x-www-form-urlencoded

Body:

{

appId=******,

secret=******

}

响应示例:

response:

Status Code: 200 OK

Content-Type: application/json

Body:

{

"scope": "default",

"tokenType": "bearer",

"expiresIn": "*******",

"accessToken": "*******",

"refreshToken": "*******"

}

使用官方例程,修改对应的appid和secret,运行,得到如下结果

nbiot电信云北向开发---基于LiteNAdemo_https例程_第1张图片

 

(2)后台服务器向电信云平台请求数据

请求示例:

Method: GET

request:

https://server:port/iocm/app/dm/v1.4.0/devices/{deviceId}?select=imsi

Header:

"app_key: **"

"Authorization:Bearer**"

Content-Type:application/json

响应示例:

response:

Status Code: 200 OK

Content-Type: application/json

Body:

{

"deviceId": "xxxxx",

"gatewayId": "xxxxx",

"nodeType": "xxxxx",

"deviceInfo": {

"name": "Sensor_12",

"manufacturerName": "wulian",

"deviceType": "gateway",

"model": "90",

"mac": "C7EA1904004B1204",

"swVersion": "th",

"fwVersion": "seu",

"hwVersion": "sru",

"protocolType": "zigbee",

"description": "smockdetector",

"imsi": "xxxxx"

},

"services": [

{

"serviceType": "air_conditioner",

"serviceId": "1",

"data"{

"battery_low": 1

}

},

{

"serviceType": "air_conditioner",

"serviceId": "jkh",

"data": {

"battery_low": "jhj"

}

}

]

}

修改例程的相关参数,运行结果如下

nbiot电信云北向开发---基于LiteNAdemo_https例程_第2张图片

 

 

2.命令下发

后台服务器可以将命令下发到bc20设备,当设备不在线的时候命令缓存在电信云平台。

Method: POST

request: https://server:port/iocm/app/cmd/v1.4.0/deviceCommands

Header:

"app_key: ******"

"Authorization:Bearer******"

Content-Type:application/json

Body:

{

"deviceId": "********",

"command": {

"serviceId": "********",

"method": "********",

"paras": {

"paraName1": "paraValue1",

"paraName2": "paraValue2"

}

},

"callbackUrl": "http://127.0.0.1:9999/cmd/callbackUrl",

"maxRetransmit":******,

}

响应示例

response:

Status Code: 201 OK

Content-Type:application/json

Body:

{

"commandId": "********",

"appId": "********",

"deviceId": "********",

"command": {

"serviceId": "********",

"method": "********",

"paras": {

"paraName1": "paraValue1",

"paraName2": "paraValue2"

}

},

"callbackUrl": "http://127.0.0.1:9999/cmd/callbackUrl",

"expireTime": null,

"status": "PENDDING",

"creationTime": "20170222T164000Z",

"executeTime": null,

"platformIssuedTime": null,

"deliveredTime": null,

"issuedTimes": null,

"maxRetransmit":******

}

修改相关参数,运行结果如下

nbiot电信云北向开发---基于LiteNAdemo_https例程_第3张图片

设备接收到相关信息

nbiot电信云北向开发---基于LiteNAdemo_https例程_第4张图片

 

 

 

 

 

3.可以通过后台服务器在电信云平台注册设备

当需要添加新设备的时候,可以通过后台服务器向电信云平台注册。

 

请求示例

Method: POST

request:

https://server:port/iocm/app/reg/v1.1.0/deviceCredentials?appId=*********

Header:

"app_key: ******"

"Authorization:Bearer ******"

Content-Type:application/json

Body:

{

"endUserId": "***********",

"verifyCode": "****************",

"nodeId": "****************",

"psk": "********************************",

"timeout": 300,

}

响应示例

response:

Status Code: 200 OK

Content-Type: application/json

Body:

{

"deviceId": "*******",

"verifyCode": "*******",

"psk": "*********",

"timeout": 300

}

nbiot电信云北向开发---基于LiteNAdemo_https例程_第5张图片

最上一行的设备就是刚才注册的。

nbiot电信云北向开发---基于LiteNAdemo_https例程_第6张图片

 

也可以删除设备

nbiot电信云北向开发---基于LiteNAdemo_https例程_第7张图片

 

你可能感兴趣的:(智慧安全社区云服务器搭建)