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,运行,得到如下结果

 

(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"

}

}

]

}

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

 

 

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":******

}

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

设备接收到相关信息

 

 

 

 

 

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

}

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

 

也可以删除设备

 

评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值