如何配置LoRa设备接入物联网平台 您所在的位置:网站首页 iot网关数据对接 如何配置LoRa设备接入物联网平台

如何配置LoRa设备接入物联网平台

2023-11-19 07:44| 来源: 网络整理| 查看: 265

配置LoRa网关后,您需要在物联网平台上创建LoRa产品和设备,定义物模型,编写和提交LoRa设备的数据解析脚本。

创建产品和设备

在物联网平台注册LoRa产品和设备。

登录物联网平台控制台。 在实例概览页面,找到对应的实例,单击实例进入实例详情页面。 注意 目前华东2(上海)、华北2(北京)、华南1(深圳)地域开通了企业版实例服务。其他地域,请跳过此步骤。 实例概览 在左侧导航栏,选择设备管理 > 产品。 在产品页面,单击创建产品,创建一个连网方式为LoRaWAN的产品。 参数 说明 产品名称 自定义产品名称。 所属品类 选择为自定义品类。 节点类型 选择直连设备。 连网方式 选择为LoRaWAN。 说明 首次创建连网方式为LoRaWAN的产品,需单击立即授权,授权物联网平台访问物联网络管理平台。 入网凭证 选择您在物联网络平台中创建并已授权的入网凭证。 数据格式 选择为透传/自定义。 认证方式 选择为设备密钥。 在左侧导航栏,选择设备管理 > 设备。 在设备页面,单击添加设备,在刚创建的产品下添加设备。 说明 设备的DevEUI和PIN Code,请在您的设备标签上查看。 测试设备连接物联网平台。按照设备上的标识,为设备连接天线、GPS天线、电池或电源。设备 设备上电约2分钟后,在物联网平台控制台对应实例下的设备页面的设备列表中,该设备的状态会显示为在线。 定义物模型

本示例中,气象监测设备上报温度、湿度、气压、地理位置坐标等信息。因此,先在物联网平台上,为以上信息定义数据模型,即定义对应的属性。

在物联网平台控制台对应实例下的左侧导航栏,选择设备管理 > 产品 。 在产品页面,找到已创建的LoRa产品,单击对应的查看。 在产品详情页面功能定义页签下,选择编辑草稿 > 添加自定义功能,在默认模块下,添加以下自定义功能,其中读写类型全部为读写。

新增物模型的详细操作,请参见单个添加物模型。

本文提供了示例的物模型TSL,您也可批量导入物模型。具体内容,请参见附录:物模型TSL和批量添加物模型。

属性名 标识符 类型 取值范围 步长 单位 温度 Temperature double -99~100 0.01 摄氏度/℃ 湿度 Humidity double 1~100 0.01 百分比/% 大气压 Atmosphere float 550~1060 0.01 百帕/hPa 经度 Longitude double -180~180 0.01 度/° 纬度 Latitude double -90~90 0.01 度/° 海拔 Altitude float 0~9999 0.01 米/m X加速度 Acceleration_X float -1000~1000 0.01 毫克/mg Y加速度 Acceleration_Y float -1000~1000 0.01 毫克/mg Z加速度 Acceleration_Z float -1000~1000 0.01 毫克/mg 运行速度 Speed float -10000~10000 0.01 Km/h 电池电压 Battery_voltage float 0~100000 0.01 伏特/V 气体阻力 Gas_resistance float -10000~10000 0.01 无 单击发布上线将物模型发布为正式版。 编写数据解析脚本

本示例中LoRa设备上报的数据是二进制格式,例如01880537A5109D5A00846C。其中 1、2 字节为数据标识码01 88;3、4、5字节为海拔数据altitude:339m;6、7、8字节为纬度数据latitude:34.1925;9、10、11字节为经度数据longitude:108.8858。

阿里云物联网平台的标准数据格式为Alink JSON格式,不能直接使用二进制数据进行业务处理,且物联网平台下发的数据也是Alink JSON格式。对此,物联网平台提供数据解析功能,您可以依据设备数据格式和物模型,编写数据解析脚本,提交至物联网平台,以供物联网平台调用来解析设备的上下行数据。

登录物联网平台控制台,在对应实例的产品详情页面,单击数据解析页签。 在编辑脚本输入框中,输入数据解析脚本。 说明 脚本代码中属性的标识符必须与定义物模型时定义的一致。

数据解析脚本的编写指导,请参见LoRaWAN设备数据解析。

本示例的数据解析脚本如下:

// var COMMAND_REPORT = 02; // var COMMAND_SET = 01; var ALINK_PROP_REPORT_METHOD = 'thing.event.property.post'; //标准ALink JSON格式Topic,设备上传属性数据到云端。 var ALINK_PROP_SET_METHOD = 'thing.service.property.set'; var ALINK_VERSION = "1.1"; function rawDataToProtocol(bytes) { var uint8Array = new Uint8Array(bytes.length); for (var i = 0; i < bytes.length; i++) { uint8Array[i] = bytes[i] & 0xff; } var dataView = new DataView(uint8Array.buffer, 0); var jsonMap = {}; // var fHead = uint8Array[0]; // 第0个BYTE为上报协议。// if (fHead == COMMAND_REPORT){ jsonMap['method'] = ALINK_PROP_REPORT_METHOD; //ALink JSON格式 - 属性上报。 jsonMap['version'] = ALINK_VERSION; //ALink JSON格式 - 协议版本号固定字段。 jsonMap['id'] = '' + 12345; //ALink JSON格式 - 标示该次请求id值。 var params = {}; switch (dataView.getInt16(0)) { case 0x0267: params['Temperature'] = Math.floor(dataView.getInt16(2) * 0.1 * 10) / 10;//保留两位小数。 params['Humidity'] = Math.floor(100 * dataView.getUint8(6) * 0.01 / 2 * 10) / 10; params['Atmosphere'] = Math.floor(dataView.getInt16(9) * 0.1 * 10) / 10; break; case 0x0188: var buffer = new Uint8Array(4); buffer[0] = 0; buffer[1] = uint8Array[2]; buffer[2] = uint8Array[3]; buffer[3] = uint8Array[4]; var latitude = new DataView(buffer.buffer, 0); params['Latitude'] = Math.floor(latitude.getInt32(0) * 0.0001 * 10000) / 10000; buffer[0] = 0; buffer[1] = uint8Array[5]; buffer[2] = uint8Array[6]; buffer[3] = uint8Array[7]; var longitude = new DataView(buffer.buffer, 0); params['Longitude'] = Math.floor(longitude.getInt32(0) * 0.0001 * 10000) / 10000; buffer[0] = 0; buffer[1] = uint8Array[8]; buffer[2] = uint8Array[9]; buffer[3] = uint8Array[10]; var altitude = new DataView(buffer.buffer, 0); params['Altitude'] = Math.floor(altitude.getInt32(0) * 0.01 * 100) / 100; break; case 0x0371: params['Acceleration_X'] = dataView.getInt16(2); params['Acceleration_Y'] = dataView.getInt16(4); params['Acceleration_Z'] = dataView.getInt16(6); break; case 0x0702: params['Battery_voltage'] = dataView.getInt16(2)/10; params['Speed'] = Math.floor(dataView.getInt16(6) * 0.01 * 100) / 100; break; case 0x0902: params['Gas_resistance'] = dataView.getInt16(2); break; } jsonMap['params'] = params; //ALink JSON 格式 - params 标准字段 } return jsonMap; } function protocolToRawData(bytes) { var method = json['method']; var id = json['id']; var version = json['version']; var payloadArray = []; return payloadArray; } 测试脚本。 选择模拟类型为设备上报数据。 在模拟输入下的输入框中,输入一个模拟数据:01880537A5109D5A00846C。 单击执行。 解析结果显示在运行结果中。运行结果 确认脚本能正确解析数据后,单击提交,将脚本提交到物联网平台系统。 说明 物联网平台不能调用草稿状态的脚本,只有已提交的脚本才会被调用来解析数据。 设备上报的属性数据经脚本成功解析后,您可以在该设备的设备详情页面的物模型数据 > 运行状态页签下,查看设备上报的属性数据。 附录:物模型TSL

使用时,请替换productKey值为您实际产品的ProductKey值。

{ "schema": "https://iotx-tsl.oss-ap-southeast-1.aliyuncs.com/schema.json", "profile": { "version": "1.0", "productKey": "a1****WRg" }, "properties": [ { "identifier": "Temperature", "name": "温度", "accessMode": "rw", "required": false, "dataType": { "type": "double", "specs": { "min": "-99", "max": "100", "unit": "°C", "unitName": "摄氏度", "step": "0.01" } } }, { "identifier": "Humidity", "name": "湿度", "accessMode": "rw", "required": false, "dataType": { "type": "double", "specs": { "min": "1", "max": "100", "unit": "%", "unitName": "百分比", "step": "0.01" } } }, { "identifier": "Atmosphere", "name": "大气压", "accessMode": "rw", "required": false, "dataType": { "type": "float", "specs": { "min": "550", "max": "1060", "unit": "hPa", "unitName": "百帕", "step": "0.01" } } }, { "identifier": "Longitude", "name": "经度", "accessMode": "rw", "required": false, "dataType": { "type": "double", "specs": { "min": "-180", "max": "180", "unit": "°", "unitName": "度", "step": "0.01" } } }, { "identifier": "Latitude", "name": "纬度", "accessMode": "rw", "required": false, "dataType": { "type": "double", "specs": { "min": "-90", "max": "90", "unit": "°", "unitName": "度", "step": "0.01" } } }, { "identifier": "Altitude", "name": "海拔", "accessMode": "rw", "required": false, "dataType": { "type": "float", "specs": { "min": "0", "max": "9999", "unit": "m", "unitName": "米", "step": "0.01" } } }, { "identifier": "Acceleration_X", "name": "X加速度", "accessMode": "rw", "required": false, "dataType": { "type": "float", "specs": { "min": "-1000", "max": "1000", "unit": "mg", "unitName": "毫克", "step": "0.01" } } }, { "identifier": "Acceleration_Y", "name": "Y加速度", "accessMode": "rw", "required": false, "dataType": { "type": "float", "specs": { "min": "-1000", "max": "1000", "unit": "mg", "unitName": "毫克", "step": "0.01" } } }, { "identifier": "Acceleration_Z", "name": "Z加速度", "accessMode": "rw", "required": false, "dataType": { "type": "float", "specs": { "min": "-1000", "max": "1000", "unit": "mg", "unitName": "毫克", "step": "0.01" } } }, { "identifier": "Speed", "name": "运行速度", "accessMode": "rw", "required": false, "dataType": { "type": "float", "specs": { "min": "-10000", "max": "10000", "unit": "km/h", "unitName": "千米每小时", "step": "0.01" } } }, { "identifier": "Battery_voltage", "name": "电池电压", "accessMode": "rw", "required": false, "dataType": { "type": "float", "specs": { "min": "0", "max": "100000", "unit": "V", "unitName": "伏特", "step": "0.01" } } }, { "identifier": "Gas_resistance", "name": "气体阻力", "accessMode": "rw", "required": false, "dataType": { "type": "float", "specs": { "min": "-10000", "max": "10000", "step": "0.01" } } } ], "events": [ { "identifier": "post", "name": "post", "type": "info", "required": true, "desc": "属性上报", "method": "thing.event.property.post", "outputData": [ { "identifier": "Temperature", "name": "温度", "dataType": { "type": "double", "specs": { "min": "-99", "max": "100", "unit": "°C", "unitName": "摄氏度", "step": "0.01" } } }, { "identifier": "Humidity", "name": "湿度", "dataType": { "type": "double", "specs": { "min": "1", "max": "100", "unit": "%", "unitName": "百分比", "step": "0.01" } } }, { "identifier": "Atmosphere", "name": "大气压", "dataType": { "type": "float", "specs": { "min": "550", "max": "1060", "unit": "hPa", "unitName": "百帕", "step": "0.01" } } }, { "identifier": "Longitude", "name": "经度", "dataType": { "type": "double", "specs": { "min": "-180", "max": "180", "unit": "°", "unitName": "度", "step": "0.01" } } }, { "identifier": "Latitude", "name": "纬度", "dataType": { "type": "double", "specs": { "min": "-90", "max": "90", "unit": "°", "unitName": "度", "step": "0.01" } } }, { "identifier": "Altitude", "name": "海拔", "dataType": { "type": "float", "specs": { "min": "0", "max": "9999", "unit": "m", "unitName": "米", "step": "0.01" } } }, { "identifier": "Acceleration_X", "name": "X加速度", "dataType": { "type": "float", "specs": { "min": "-1000", "max": "1000", "unit": "mg", "unitName": "毫克", "step": "0.01" } } }, { "identifier": "Acceleration_Y", "name": "Y加速度", "dataType": { "type": "float", "specs": { "min": "-1000", "max": "1000", "unit": "mg", "unitName": "毫克", "step": "0.01" } } }, { "identifier": "Acceleration_Z", "name": "Z加速度", "dataType": { "type": "float", "specs": { "min": "-1000", "max": "1000", "unit": "mg", "unitName": "毫克", "step": "0.01" } } }, { "identifier": "Speed", "name": "运行速度", "dataType": { "type": "float", "specs": { "min": "-10000", "max": "10000", "unit": "km/h", "unitName": "千米每小时", "step": "0.01" } } }, { "identifier": "Battery_voltage", "name": "电池电压", "dataType": { "type": "float", "specs": { "min": "0", "max": "100000", "unit": "V", "unitName": "伏特", "step": "0.01" } } }, { "identifier": "Gas_resistance", "name": "气体阻力", "dataType": { "type": "float", "specs": { "min": "-10000", "max": "10000", "step": "0.01" } } } ] } ], "services": [ { "identifier": "set", "name": "set", "required": true, "callType": "async", "desc": "属性设置", "method": "thing.service.property.set", "inputData": [ { "identifier": "Temperature", "name": "温度", "dataType": { "type": "double", "specs": { "min": "-99", "max": "100", "unit": "°C", "unitName": "摄氏度", "step": "0.01" } } }, { "identifier": "Humidity", "name": "湿度", "dataType": { "type": "double", "specs": { "min": "1", "max": "100", "unit": "%", "unitName": "百分比", "step": "0.01" } } }, { "identifier": "Atmosphere", "name": "大气压", "dataType": { "type": "float", "specs": { "min": "550", "max": "1060", "unit": "hPa", "unitName": "百帕", "step": "0.01" } } }, { "identifier": "Longitude", "name": "经度", "dataType": { "type": "double", "specs": { "min": "-180", "max": "180", "unit": "°", "unitName": "度", "step": "0.01" } } }, { "identifier": "Latitude", "name": "纬度", "dataType": { "type": "double", "specs": { "min": "-90", "max": "90", "unit": "°", "unitName": "度", "step": "0.01" } } }, { "identifier": "Altitude", "name": "海拔", "dataType": { "type": "float", "specs": { "min": "0", "max": "9999", "unit": "m", "unitName": "米", "step": "0.01" } } }, { "identifier": "Acceleration_X", "name": "X加速度", "dataType": { "type": "float", "specs": { "min": "-1000", "max": "1000", "unit": "mg", "unitName": "毫克", "step": "0.01" } } }, { "identifier": "Acceleration_Y", "name": "Y加速度", "dataType": { "type": "float", "specs": { "min": "-1000", "max": "1000", "unit": "mg", "unitName": "毫克", "step": "0.01" } } }, { "identifier": "Acceleration_Z", "name": "Z加速度", "dataType": { "type": "float", "specs": { "min": "-1000", "max": "1000", "unit": "mg", "unitName": "毫克", "step": "0.01" } } }, { "identifier": "Speed", "name": "运行速度", "dataType": { "type": "float", "specs": { "min": "-10000", "max": "10000", "unit": "km/h", "unitName": "千米每小时", "step": "0.01" } } }, { "identifier": "Battery_voltage", "name": "电池电压", "dataType": { "type": "float", "specs": { "min": "0", "max": "100000", "unit": "V", "unitName": "伏特", "step": "0.01" } } }, { "identifier": "Gas_resistance", "name": "气体阻力", "dataType": { "type": "float", "specs": { "min": "-10000", "max": "10000", "step": "0.01" } } } ], "outputData": [] }, { "identifier": "get", "name": "get", "required": true, "callType": "async", "desc": "属性获取", "method": "thing.service.property.get", "inputData": [ "Temperature", "Humidity", "Atmosphere", "Longitude", "Latitude", "Altitude", "Acceleration_X", "Acceleration_Y", "Acceleration_Z", "Speed", "Battery_voltage", "Gas_resistance" ], "outputData": [ { "identifier": "Temperature", "name": "温度", "dataType": { "type": "double", "specs": { "min": "-99", "max": "100", "unit": "°C", "unitName": "摄氏度", "step": "0.01" } } }, { "identifier": "Humidity", "name": "湿度", "dataType": { "type": "double", "specs": { "min": "1", "max": "100", "unit": "%", "unitName": "百分比", "step": "0.01" } } }, { "identifier": "Atmosphere", "name": "大气压", "dataType": { "type": "float", "specs": { "min": "550", "max": "1060", "unit": "hPa", "unitName": "百帕", "step": "0.01" } } }, { "identifier": "Longitude", "name": "经度", "dataType": { "type": "double", "specs": { "min": "-180", "max": "180", "unit": "°", "unitName": "度", "step": "0.01" } } }, { "identifier": "Latitude", "name": "纬度", "dataType": { "type": "double", "specs": { "min": "-90", "max": "90", "unit": "°", "unitName": "度", "step": "0.01" } } }, { "identifier": "Altitude", "name": "海拔", "dataType": { "type": "float", "specs": { "min": "0", "max": "9999", "unit": "m", "unitName": "米", "step": "0.01" } } }, { "identifier": "Acceleration_X", "name": "X加速度", "dataType": { "type": "float", "specs": { "min": "-1000", "max": "1000", "unit": "mg", "unitName": "毫克", "step": "0.01" } } }, { "identifier": "Acceleration_Y", "name": "Y加速度", "dataType": { "type": "float", "specs": { "min": "-1000", "max": "1000", "unit": "mg", "unitName": "毫克", "step": "0.01" } } }, { "identifier": "Acceleration_Z", "name": "Z加速度", "dataType": { "type": "float", "specs": { "min": "-1000", "max": "1000", "unit": "mg", "unitName": "毫克", "step": "0.01" } } }, { "identifier": "Speed", "name": "运行速度", "dataType": { "type": "float", "specs": { "min": "-10000", "max": "10000", "unit": "km/h", "unitName": "千米每小时", "step": "0.01" } } }, { "identifier": "Battery_voltage", "name": "电池电压", "dataType": { "type": "float", "specs": { "min": "0", "max": "100000", "unit": "V", "unitName": "伏特", "step": "0.01" } } }, { "identifier": "Gas_resistance", "name": "气体阻力", "dataType": { "type": "float", "specs": { "min": "-10000", "max": "10000", "step": "0.01" } } } ] } ] }


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有