本帖最后由 lustao 于 2021-10-9 12:33 编辑
在前两文章 单通道lora网关搭建环境 和 Cubecell AB01 lora节点开发板搭建环境
基础上 作 运行一个例程上腾讯云平台调试节点数据
运行一个例程上腾讯云平台调试节点数据需要
1. 正确配置工具菜单
2.在腾讯云上注册节点
3.节点程序
1. 正确配置工具菜单
在“工具”菜单中,有以下选项:
Board – 选择正确的硬件连接到电脑;
LORAWAN_REGION – 严格遵守LORAWAN协议区域规定 LoRaWAN™ 1.0.2 Regional Parameters rB;
LORAWAN_CLASS – 现在支持Class A 和 Class C;
LORAWAN_DEVEUI – LoRaWAN参数DevEUI的来源
o CUSTOM -- 使用.ino文件中devEui数组中定义的值,可以是任何值,但可能与其他序列号冲突。
o Generate by ChipID -- 根据ASR650x的唯一芯片ID生成。
LORAWAN_NETMODE – OTAA or ABP;
LORAWAN_ADR – ON or OFF ADR (自适应数据速率);
LORAWAN_Net_Reservation – 这是LoRaWAN协议之外的功能,仅在OTAA模式下有效。如果启用此选项,则系统复位时不需要再次加入。智能路灯等项目可能有用;
LORAWAN_UPLINKMODE – LoRa上行确认/未确认信息。确认后的消息需要服务器发送下行链路到节点,但有些LoRa服务器下行链路受限(如TTN)。
LORAWAN_AT_SUPPORT – AT命令将提供许多有用的功能,例如,用户可以使用串行端口来配置LoRa节点的DevEui、AppKey或使节点休眠、复位等。
LORAWAN_RGB – LoRaWAN状态的RGB灯:
o 紫色 -- 入网;
o 蓝色 -- 第一接收窗口;
o 黄色 -- 第二接收窗口;
o 绿色 -- 入网成功.
LoRaWan Debug Level – 通过串行端口打印LoRaWAN相关信息
o None -- 默认;
o Freq -- 发送/接收频率;
o Freq && DIO -- 发送/接收频率和DIO引脚中断信息。
COM Port – 设备在计算机中的串行端口。
注解
LORAWAN_Net_Reservation:例如,城市发生大规模停电,恢复供电后,数千台设备同时接入网络,可能导致LoRa网关或服务器 故障。启用此功能将避免这种情况。启用LORAWAN_Net_Reservation必须禁用LoRa服务器中的帧计数器(fCnt)。
2.在腾讯云上注册节点
在之前 单通道lora网关搭建环境 中建立的项目基础上
在左侧工具栏列表中,选择【产品开发】>【新建产品】。
在新建的产品中新建功能,根据实际情况添加需要使用到的数据,本文中需要监测”温度”,”湿度”,”电池电压”,所以新建三个功能。功能中的”数据类型”应与解析出的数据类型相匹配。
“新建功能”完成后,可在”设备开发”配置相应数据解析脚本。
- function RawToProtocol(fPort, bytes) {
- var temperature = tofloat32(bytes[3],bytes[2],bytes[1],bytes[0]);
- var humidity = tofloat32(bytes[7],bytes[6],bytes[5],bytes[4]);
- var voltge = bytes[8]<<8|bytes[9];
- var result={
- "sensor":{
- "Temperature":temperature,
- "Humidity":humidity,
- "Voltge":voltge,
- }
- }
- return result;
- }
- function tofloat32(a1,a2,a3,a4){
- var s=(a1&0xff)>>7;
- var E=(a1<<1&0xff)|a2>>7;
- var M0=(a2&0x7f)<<16|a3<<8|a4;
- var M=1;
- for(var i=0;i<23;i++)
- {
- if(M0>>i&0x01==1)
- {
- M=M+Math.pow(2,i-23);
- }
- }
- var result=Math.pow(-1,s)*M*Math.pow(2,E-127);
- return result;
- }
复制代码
在”设备调试”中点击”新建设备”新建节点。新建节点的”DevEUI”,”AppKey”必须与程序18、20行相对应。
3.节点程序
选择一个例程
修改程序为
- #include "LoRaWan_APP.h"
- #include "Arduino.h"
- #include
- //#include "HDC1080.h"
- #include "LoRaWan_APP.h"
- #include "Arduino.h"
- /*
- * set LoraWan_RGB to Active,the RGB active in loraWan
- * RGB red means sending;
- * RGB purple means joined done;
- * RGB blue means RxWindow1;
- * RGB yellow means RxWindow2;
- * RGB green means received done;
- */
- /* OTAA para*/
- uint8_t devEui[] = { 0x22, 0x32, 0x33, 0x00, 0x00, 0x88, 0x88, 0x05 };
- uint8_t appEui[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- uint8_t appKey[] = { 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x66, 0x01 };
- /* ABP para*/
- uint8_t nwkSKey[] = { 0x15, 0xb1, 0xd0, 0xef, 0xa4, 0x63, 0xdf, 0xbe, 0x3d, 0x11, 0x18, 0x1e, 0x1e, 0xc7, 0xda,0x85 };
- uint8_t appSKey[] = { 0xd7, 0x2c, 0x78, 0x75, 0x8c, 0xdc, 0xca, 0xbf, 0x55, 0xee, 0x4a, 0x77, 0x8d, 0x16, 0xef,0x67 };
- uint32_t devAddr = ( uint32_t )0x007e6ae1;
- /*LoraWan channelsmask, default channels 0-7*/
- uint16_t userChannelsMask[6]={ 0x0001,0x0000,0x0000,0x0000,0x0000,0x0000 };
- /*LoraWan region, select in arduino IDE tools*/
- LoRaMacRegion_t loraWanRegion = ACTIVE_REGION;
- /*LoraWan Class, Class A and Class C are supported*/
- DeviceClass_t loraWanClass = LORAWAN_CLASS;
- /*the application data transmission duty cycle. value in [ms].*/
- uint32_t appTxDutyCycle = 15000;
- /*OTAA or ABP*/
- bool overTheAirActivation = LORAWAN_NETMODE;
- /*ADR enable*/
- bool loraWanAdr = LORAWAN_ADR;
- /* set LORAWAN_Net_Reserve ON, the node could save the network info to flash, when node reset not need to join again */
- bool keepNet = LORAWAN_NET_RESERVE;
- /* Indicates if the node is sending confirmed or unconfirmed messages */
- bool isTxConfirmed = LORAWAN_UPLINKMODE;
- /* Application port */
- uint8_t appPort = 2;
- /*!
- * Number of trials to transmit the frame, if the LoRaMAC layer did not
- * receive an acknowledgment. The MAC performs a datarate adaptation,
- * according to the LoRaWAN Specification V1.0.2, chapter 18.4, according
- * to the following table:
- *
- * Transmission nb | Data Rate
- * ----------------|-----------
- * 1 (first) | DR
- * 2 | DR
- * 3 | max(DR-1,0)
- * 4 | max(DR-1,0)
- * 5 | max(DR-2,0)
- * 6 | max(DR-2,0)
- * 7 | max(DR-3,0)
- * 8 | max(DR-3,0)
- *
- * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease
- * the datarate, in case the LoRaMAC layer did not receive an acknowledgment
- */
- uint8_t confirmedNbTrials = 4;
- /*!
- * brief Prepares the payload of the frame
- */
- //HDC1080 hdc1080;
- static void prepareTxFrame( uint8_t port )
- {
- /*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in "commissioning.h".
- *appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE.
- *if enabled AT, don't modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure.
- *if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF.
- *for example, if use REGION_CN470,
-
- *the max value for different DR can be found in
- MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in
- "RegionCN470.h".
- */
- pinMode(Vext,OUTPUT);
- digitalWrite(Vext,LOW);
- // hdc1080.begin(0x40);
- float temperature =12.34;/* (float)(hdc1080.readTemperature());*/
- float humidity =23.56;/* (float)(hdc1080.readHumidity());*/
- // hdc1080.end();
- digitalWrite(Vext,HIGH);
- uint16_t batteryVoltage = getBatteryVoltage();
- unsigned char *puc;
- puc = (unsigned char *)(&temperature);
- appDataSize = 10;
- appData[0] = puc[0];
- appData[1] = puc[1];
- appData[2] = puc[2];
- appData[3] = puc[3];
- puc = (unsigned char *)(&humidity);
- appData[4] = puc[0];
- appData[5] = puc[1];
- appData[6] = puc[2];
- appData[7] = puc[3];
- appData[8] = (uint8_t)(batteryVoltage>>8);
- appData[9] = (uint8_t)batteryVoltage;
- Serial.print("T=");
- Serial.print(temperature);
- Serial.print("C, RH=");
- Serial.print(humidity);
- Serial.print("%,");
- Serial.print("BatteryVoltage:");
- Serial.println(batteryVoltage);
- }
- void setup() {
- Serial.begin(115200);
- #if(AT_SUPPORT)
- enableAt();
- #endif
- deviceState = DEVICE_STATE_INIT;
- LoRaWAN.ifskipjoin();
- }
- void loop()
- {
- switch( deviceState )
- {
- case DEVICE_STATE_INIT:
- {
- #if(LORAWAN_DEVEUI_AUTO)
- LoRaWAN.generateDeveuiByChipID();
- #endif
- #if(AT_SUPPORT)
- getDevParam();
- #endif
- printDevParam();
- LoRaWAN.init(loraWanClass,loraWanRegion);
- deviceState = DEVICE_STATE_JOIN;
- break;
- }
- case DEVICE_STATE_JOIN:
- {
- LoRaWAN.join();
- break;
- }
- case DEVICE_STATE_SEND:
- {
- prepareTxFrame( appPort );
- LoRaWAN.send();
-
-
- deviceState = DEVICE_STATE_CYCLE;
- break;
- }
- case DEVICE_STATE_CYCLE:
- {
- // Schedule next packet transmission
- txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND );
- LoRaWAN.cycle(txDutyCycleTime);
- deviceState = DEVICE_STATE_SLEEP;
- break;
- }
- case DEVICE_STATE_SLEEP:
- {
- LoRaWAN.sleep();
- break;
- }
- default:
- {
- deviceState = DEVICE_STATE_INIT;
- break;
- }
- }
- }
复制代码
项目使用了 90032 字节,占用了 (68%) 程序存储空间。最大为 131072 字节。
上传。
lora网关上电正常连接后
节点开发板com口显示
lora节点上传到腾讯云数据 正常
腾讯云上
云端日志原始
解析后
|