应用如何根据 LoRa App Server 提供的北向 API 进行开发呢? 那么多的 API 都是怎么使用,这篇笔记梳理了主要API的调用逻辑。
小能手最近在学习 LoRa Server 项目,应该是最有影响力的 LoRaWAN 服务器开源项目。它组件丰富,代码可读性强,是个很好的学习资料。更多学习笔记,可点此查看。
请求
POST /api/applications
{
"application":{
"name":"demoapp",
"description":"demo",
"organizationID":"1","serviceProfileID":"38d7f9dd-549e-4b9b-9634-cf96655a6371"
}
}
回复
200 OK
{
"id":"2"
}
serviceProfile 将应用的通用参数做了抽象提出,这里必须填入,以前倒是没有。
请求
GET /api/device-profiles?limit=10&organizationID=1
回复
200 OK
{
"totalCount":"2",
"result":[
{
"id":"8d185e44-75d9-43f8-a7db-98ae7534b7d7",
"name":"ClassA_ABP",
"organizationID":"1",
"networkServerID":"6",
"createdAt":"2019-10-30T03:13:07.864454Z",
"updatedAt":"2019-10-30T03:13:07.864454Z"
},{
"id":"97e5262e-48f7-4aa8-9c76-9427c18dcbf5",
"name":"ClassA_OTAA",
"organizationID":"1",
"networkServerID":"6",
"createdAt":"2019-10-29T11:10:15.457647Z",
"updatedAt":"2019-10-29T11:10:15.457647Z"
}
]
}
UI 参数名 | UI 参数数值 | 是否必填 | API 对应参数 | API 参数说明 |
---|---|---|---|---|
organizationID | int | * | organizationID | 以前其实是 application,后来把 profile 提出来,profile 可以给多个应用共用 |
请求
POST /api/device-profiles
{
"deviceProfile":{
"name":"ClassA_OTAA",
"networkServerID":"6",
"macVersion":"1.0.2",
"regParamsRevision":"A",
"supportsJoin":true,
"organizationID":"1"
}
}
回复
200 OK
{
"id": "619d2aac-75a6-47bd-9c19-e89658c0adc5"
}
UI 参数名 | UI 参数数值 | 是否必填 | API 对应参数 | API 参数说明 |
---|---|---|---|---|
Device-profile name | string | * | name | |
Network-server | 整数:NS ID | * | networkServerID | |
协议版本 | 枚举:V1.0.0V1.0.1V1.0.2V1.0.3V1.1.0 | * | mac_version | string:1.0.01.0.11.0.21.0.31.1.0 |
Regional Parameters revision | 枚举 | | regParamsRevision | |
加网方式 | 枚举:OTAA / ABP默认是ABP | | supports_join | true: OTAA / false: ABP |
设备类型 | 枚举:CLASS A / CLASS B / CLASS C默认是CLASS A | | supports_class_b,supports_class_c | CLASS A:supports_class_b=false supports_class_c=false;CLASS B: supports_class_b=true supports_class_c=false;CLASS C: supports_class_b=false supports_class_c=true |
组织 ID | 枚举 | | organizationID | |
设备最大发射功率 | 整数:默认为0,0~15 | | maxEIRP | 等于《region param》 的 TXPower |
RX1 Delay | 整数:默认1 s | | rx_delay_1 | |
RX2 DR | 整数:默认 0 | | rx_datarate_2 | |
RX2 Frequency | 整数:默认 505.3 MHz | | rx_freq_2 | |
请求
GET /api/device-profiles/{id}
回复
200 OK
{
"deviceProfile":{
"id":"8d185e44-75d9-43f8-a7db-98ae7534b7d7",
"name":"ClassA_ABP",
"organizationID":"1",
"networkServerID":"6",
"supportsClassB":false,
"classBTimeout":0,
"pingSlotPeriod":0,
"pingSlotDR":0,
"pingSlotFreq":0,
"supportsClassC":false,
"classCTimeout":0,
"macVersion":"1.0.2",
"regParamsRevision":"A",
"rxDelay1":0,
"rxDROffset1":0,
"rxDataRate2":0,
"rxFreq2":0,
"factoryPresetFreqs":[],
"maxEIRP":0,
"maxDutyCycle":0,
"supportsJoin":false,
"rfRegion":"CN470",
"supports32BitFCnt":false,
"payloadCodec":"",
"payloadEncoderScript":"",
"payloadDecoderScript":"",
"geolocBufferTTL":0,
"geolocMinBufferSize":0
},
"createdAt":"2019-10-30T03:13:07.864454Z","updatedAt":"2019-10-30T03:13:07.864454Z"
}
这边涉及3条API,搞个序列图会比较好点。
WebLoRaAppServerPOST /api/devicesResponse status=200POST /api/devices/{device_keys.dev_eui}/keysPOST /api/devices/{device_activation.dev_eui}/activatealt 设备模板支持 OTAA Response status=200WebLoRaAppServer
请求
POST /api/devices
{
"device":{
"name":"device1",
"description":"1",
"deviceProfileID":"8d185e44-75d9-43f8-a7db-98ae7534b7d7","devEUI":"0000000000000001",
"applicationID":"2"
}
}
参数说明
创建设备,依赖此前创建的 deviceProfileID 及 applicationID,以及web输入的DevEUI
回复
200 OK
请求
POST /api/devices/{device_keys.dev_eui}/keys
{
"deviceKeys":{
"nwkKey":"00000000000000010000000000000001",
"devEUI":"0000000000000002"
}
}
参数说明
这里感觉有问题,WebUI 上填的是 appKey,API 传递进来却变成了 nwkKey。
回复
200 OK
请求
POST /api/devices/0000000000000001/activate
{
"deviceActivation":{
"devAddr":"00000001",
"nwkSEncKey":"9aeebc8d7875455993331715d5776999",
"appSKey":"c78d932e67659811477755d5da9812d3",
"devEUI":"0000000000000001",
"fNwkSIntKey":"9aeebc8d7875455993331715d5776999",
"sNwkSIntKey":"9aeebc8d7875455993331715d5776999"
}
}
参数说明
根据web输入的 devAddr、appSKey、nwkSKey,其中 nwkSEncKey=fNwkSIntKey=sNwkSIntKey。
回复
200 OK
请求
POST /api/gateways
{
"gateway":{
"location":{},
"name":"gw2",
"description":"2",
"id":"0000e1abb6975616",
"gatewayProfileID":null,
"networkServerID":"6",
"organizationID":"1"
}
}
回复
200 OK