當(dāng)前位置:中美貿(mào)易網(wǎng) > 技術(shù)中心 > 所有分類
目錄
本文主要描述如何使用網(wǎng)關(guān)MQTT API接口對網(wǎng)關(guān)內(nèi)置的NS功能進(jìn)行遠(yuǎn)程配置管理。
將網(wǎng)關(guān)成功連接到MQTT服務(wù)器中。參考
進(jìn)入MQTT應(yīng)用主題,Request data與Respond data是MQTT API接口遠(yuǎn)程管理的主題,可自定義主題。
通過MQTT客戶端軟件(MQTT.fx或MQTTX)進(jìn)行模擬測試,如下以MQTTX為例,將其連接到與網(wǎng)關(guān)同樣MQTT服務(wù)器,且配置對應(yīng)的主題,如下圖:
MQTTX向Request data主題/test/request推送內(nèi)容,推送成功后,網(wǎng)關(guān)將會通過該主題接收的內(nèi)容進(jìn)行配置處理。
網(wǎng)關(guān)在配置完成后會向Respond data主題/test/respond 推送回復(fù)內(nèi)容,MQTTX將會通過該主題接收回復(fù)內(nèi)容。
如下舉例幾種常用MQTT API接口進(jìn)行介紹,可下載API文件了解完整的MQTT API功能。
添加一條入網(wǎng)方式為OTAA,工作方式為Class C,信道8-15,名為test的profile文件。
推送內(nèi)容:
{
"type": "ns-api",
"id": "1",
"method": "POST",
"url": "/api/urprofiles",
"body": {
"name": "test",
"profile": {
"factoryPresetFreqs": [],
"macVersion": "1.0.2",
"maxEIRP": 0,
"regParamsRevision": "B",
"rxDROffset1": 0,
"rxDataRate2": 0,
"rxFreq2": 505300000,
"supports32bitFCnt": true,
"supportsClassB": false,
"supportsClassC": false,
"supportsJoin": true,
"pingSlotPeriod": 0,
"pingSlotDR": 2,
"pingSlotFreq": 508300000,
"classBTimeout": 10,
"classCTimeout": 10,
"enableUplinkChannels": [8,9,10,11,12,13,14,15]
}
}
}
網(wǎng)關(guān)回復(fù):
{"id":"1","gatewayEUI":"24E124FFFEF2F213","method":"POST","url":"/api/urprofiles","body":{"profileID":"4cf616c0-ee30-4686-b4a6-7ef7ed284cf7"}}
查詢網(wǎng)關(guān)Profile配置信息。
推送內(nèi)容:
{
"type":"ns-api",
"id": "1",
"method": "GET",
"url": "/api/urprofiles"
}
網(wǎng)關(guān)回復(fù):
刪除網(wǎng)關(guān)Profile配置文件。
推送內(nèi)容:
{
"type": "ns-api",
"id": "1",
"method": "DELETE",
"url": "/api/urprofiles/4cf616c0-ee30-4686-b4a6-7ef7ed284cf7"
}
注意:url中profileID信息需要匹配才能刪除成功。在添加或查詢Profile配置后,網(wǎng)關(guān)會在回復(fù)包中帶上“profileID”,為該P(yáng)rofile配置文件的標(biāo)識。
網(wǎng)關(guān)回復(fù):
若回復(fù)包中含有error信息則代表刪除失敗。
添加一個入網(wǎng)方式為OTAA的終端節(jié)點(diǎn)設(shè)備。
推送內(nèi)容:
{
"type":"ns-api",
"id":"1",
"method":"POST",
"url":"/api/urdevices",
"body":{
"name":"testdevice",
"devEUI":"24E124600B252019",
"description":"",
"fPort":1,
"skipFCntCheck":true,
"profileID":"ba238d8e-4cff-4455-b230-280b059740b9",
"appKey":"5572404c696e6b4c6f52613230313823",
"applicationID":"1"
}
}
網(wǎng)關(guān)回復(fù):
網(wǎng)關(guān)頁面上看到設(shè)備成功添加。
查詢網(wǎng)關(guān)所有已添加設(shè)備的信息。
推送內(nèi)容:
{
"type": "ns-api",
"id": "1",
"method": "GET",
"url": "/api/urdevices?&offset=0&limit=9999"
}
網(wǎng)關(guān)回復(fù):
修改4.2.1中創(chuàng)建devEUI為24E124600B252019的設(shè)備的appKey。
推送內(nèi)容:
{
"type": "ns-api",
"id": "1",
"method": "PUT",
"url": "/api/urdevices/24E124600B252019",
"body": {
"name":"testdevice",
"applicationID":"1",
"description":"",
"profileID":"ba238d8e-4cff-4455-b230-280b059740b9",
"fCntUp":0,
"fCntDown":0,
"skipFCntCheck":false,
"appKey":"66666666666666666666666666666666",
"devAddr":"",
"appSKey":"",
"nwkSKey":"",
"mbMode":"",
"mbFramePort":0,
"mbTcpPort":0,
"fPort":1
}
}
網(wǎng)關(guān)回復(fù):
網(wǎng)關(guān)頁面上可以看到設(shè)備appKey已成功修改。
刪除devEUI為24E124600B252019的設(shè)備。
推送內(nèi)容:
{
"type": "ns-api",
"id": "1",
"method": "DELETE",
"url": "/api/urdevices/24E124600B252019"
}
網(wǎng)關(guān)回復(fù):
推送內(nèi)容:
{
"type":"ns-api",
"id":"1",
"method":"POST",
"url":"/api/multicast-groups",
"body":{
"multicastGroup":{
"mcAddr":"",
"name":"group1",
"mcNwkSKey":"5572404c696e6b4c6f52613230313823",
"mcAppSKey":"5572404c696e6b4c6f52613230313823",
"groupType":"CLASS_C",
"fCnt":0,
"dr":0,
"pingSlotPeriod":128,
"frequency":505300000,
"applicationID" :"2"
}
}
}
網(wǎng)關(guān)回復(fù):
{
"id":"1",
"method":"POST",
"url":"/api/multicast-groups",
"body":{
"id":"03881b5e-9af0-4a38-860c-bdc25347f739" //成功返回multicastGroupID,失敗詳細(xì)見通用返回值對照表
}
}
推送內(nèi)容:
{
"type":"ns-api",
"id":"1",
"method":"POST",
"url":"/api/multicast-groups/03881b5e-9af0-4a38-860c-bdc25347f739/devices",
"body":{ "devEUIs": } }
網(wǎng)關(guān)回復(fù):
{
"id":"1",
"method":"POST",
"url":"/api/multicast-groups/03881b5e-9af0-4a38-860c-bdc25347f739/devices",
"body": { //body為空時表示添加成功 } }
推送內(nèi)容:
{
"type": "ns-api",
"id": "1",
"method": "DELETE",
"url": "/api/multicast-groups/8cc84500-9587-4256-bd7e-4f265c56f8ee"
}
網(wǎng)關(guān)回復(fù):
{
"id":"1",
"method":"DELETE",
"url":"/api/multicast-groups/8cc84500-9587-4256-bd7e-4f265c56f8ee",
"body":{
"code": , //body為空時表示刪除成功,失敗會返回code和error
"error":""
}
}
推送內(nèi)容:
{
"type": "ns-api",
"id": "1",
"method": "POST",
"url": "/api/multicast-groups/0663aff7-3223-4874-ad6a-b306c63a38e7/deletedevices",
"body":{
"devEUIs":[
"24E124136A456467"
]}
}
網(wǎng)關(guān)回復(fù):
{
"id":"1",
"method":"POST",
"url":"/api/multicast-groups/0663aff7-3223-4874-ad6a-b306c63a38e7/deletedevices",
"body":{
"code": , //body為空時表示刪除成功,失敗會返回code和error
"error":""
}
}
1.查詢網(wǎng)關(guān)下所有組播信息
{
"type": "ns-api",
"id": "1",
"method": "GET",
"url": "/api/multicast-groups?search=&order=asc&offset=0&limit=9999"
}
2.查詢網(wǎng)關(guān)某個組播信息
{
"type": "ns-api",
"id": "2",
"method": "GET",
"url": "/api/multicast-groups?search=group1&offset=0&limit=9999"
}
網(wǎng)關(guān)回復(fù):
{
"id":"1",
"method":"GET",
"url":"/api/multicast-groups?search=&order=asc&offset=0&limit=9999",
"body":{
"totalCount":"1",
"result":[
{
"id":"0663aff7-3223-4874-ad6a-b306c63a38e7",
"name":"group1",
"mcAddr":"",
"mcNwkSKey":"5572404c696e6b4c6f52613230313823",
"mcAppSKey":"5572404c696e6b4c6f52613230313823",
"fCnt":0,
"groupType":"CLASS_C",
"dr":0,
"frequency":505300000,
"pingSlotPeriod":128,
"createdAt":"2023-02-02 01:18:10",
"updatedAt":"2023-02-02 01:27:10",
"applicationID": "2",
"applicationName": "gym",
"devices":[
{
"devEUI":"24E124136A456467",
"name":"em300-470",
"applicationID":"1",
"description":"em300",
"deviceProfileID":"940dcdbe-8d5b-4a1e-b7c6-4e5437162015",
"deviceProfileName":"ClassA-OTAA",
"deviceStatusBattery":0,
"deviceStatusMargin":0,
"lastSeenAt":""
}
]}
]}
}
若使用修改接口需要填充所有參數(shù),請先調(diào)用查詢接口獲取當(dāng)前數(shù)據(jù)在對需要修改的參數(shù)進(jìn)行修改,以保證修改的準(zhǔn)確性。
推送內(nèi)容:
{
"type":"ns-api",
"id":"1",
"method":"PUT",
"url":"/api/multicast-groups/0663aff7-3223-4874-ad6a-b306c63a38e7",
"body":{
"multicastGroup":{
"name":"group2",
"mcAddr":"",
"mcNwkSKey":"5572404c696e6b4c6f52613230313823",
"mcAppSKey":"5572404c696e6b4c6f52613230313823",
"fCnt":0,
"groupType":"CLASS_C",
"dr":0,
"frequency":505300000,
"pingSlotPeriod":128
}
}
}
網(wǎng)關(guān)回復(fù):
{
"id":"1",
"method":"PUT",
"url":"/api/multicast-groups/0663aff7-3223-4874-ad6a-b306c63a38e7",
"body":{ //成功返回為空,失敗會返回code和error詳細(xì)信息見通用返回值對照表
}
}