diff --git a/board/NUCLEO_STM32L073RZ/BSP/Src/lora_demo.c b/board/NUCLEO_STM32L073RZ/BSP/Src/lora_demo.c new file mode 100644 index 00000000..accc7323 --- /dev/null +++ b/board/NUCLEO_STM32L073RZ/BSP/Src/lora_demo.c @@ -0,0 +1,116 @@ +#include "lora_demo.h" +#include "HTS221.h" +#include "RHF76.h" + +/* + ================================================================================== + data template: + + Type Name Token DataType RW Attribute + property temperature temperature integer readonly range: [-100, 155] + initial: 0 + step: 1 + unit: centigrade + + property humidity humidity integer readonly range: [-0, 100] + initial: 0 + step: 1 + unit: % + + property report_period period integer read-write range: [0, 3600] + initial: 0 + step: 1 + unit: second + + ================================================================================== + up-link parser javascript: + + function RawToProtocol(fPort, bytes) { + var data = { + "method": "report", + "clientToken" : new Date(), + "params" : {} + }; + data.params.temperature = bytes[0]; + data.params.humidity = bytes[1]; + data.params.period = bytes[2] | (bytes[3] << 8); + return data; + } + + ================================================================================== + down-link parser javascript: + + function ProtocolToRaw(obj) { + var data = new Array(); + data[0] = 5;// fport=5 + data[1] = 0;// unconfirmed mode + data[2] = obj.params.period & 0x00FF; + data[3] = (obj.params.period >> 8) & 0x00FF; + return data; + } + + */ + +uint16_t report_period = 10; + +typedef struct device_data_st { + uint8_t temperature; + uint8_t humidity; + uint16_t period; +} __PACKED__ dev_data_t; + +typedef struct device_data_wrapper_st { + union { + dev_data_t dev_data; + uint8_t serialize[sizeof(dev_data_t)]; + } u; +} dev_data_wrapper_t; + +dev_data_wrapper_t dev_data_wrapper; + +void recv_callback(uint8_t *data, uint8_t len) +{ + int i = 0; + + printf("len: %d\n", len); + + for (i = 0; i < len; ++i) { + printf("data[%d]: %d\n", i, data[i]); + } + + if (len == 1) { + report_period = data[0]; + } else if (len >= 2) { + report_period = data[0] | (data[1] << 8); + } + printf("report_period: %d\n", report_period); +} + +void application_entry(void *arg) +{ + int16_t temperature; + int16_t humidity; + + HTS221_Init(); + + rhf76_lora_init(HAL_UART_PORT_1); + tos_lora_module_recvcb_register(recv_callback); + + tos_lora_module_join_otaa("8cf957200000fa57", "8cf957200000fa572059aaaaad204a72"); + + while (1) { + HTS221_Get_Temperature(&temperature); + HTS221_Get_Humidity(&humidity); + + printf("temperature: %2.1f\n", temperature / 10.0); + printf("humidity : %2.1f\n", humidity / 10.0); + + dev_data_wrapper.u.dev_data.temperature = temperature / 10; + dev_data_wrapper.u.dev_data.humidity = humidity / 10; + dev_data_wrapper.u.dev_data.period = report_period; + + tos_lora_module_send(dev_data_wrapper.u.serialize, sizeof(dev_data_t)); + tos_task_delay(report_period * 1000); + } +} + diff --git a/board/NUCLEO_STM32L073RZ/KEIL/lorawan/TencentOS_tiny.uvoptx b/board/NUCLEO_STM32L073RZ/KEIL/lorawan/TencentOS_tiny.uvoptx index d20f7ce7..7fb6906d 100644 --- a/board/NUCLEO_STM32L073RZ/KEIL/lorawan/TencentOS_tiny.uvoptx +++ b/board/NUCLEO_STM32L073RZ/KEIL/lorawan/TencentOS_tiny.uvoptx @@ -899,7 +899,7 @@ examples - 0 + 1 0 0 0 @@ -910,7 +910,7 @@ 0 0 0 - ..\..\..\..\examples\LoRaWAN\lora_demo.c + ..\..\BSP\Src\lora_demo.c lora_demo.c 0 0 diff --git a/board/NUCLEO_STM32L073RZ/KEIL/lorawan/TencentOS_tiny.uvprojx b/board/NUCLEO_STM32L073RZ/KEIL/lorawan/TencentOS_tiny.uvprojx index 548e9d16..4bcbaf30 100644 --- a/board/NUCLEO_STM32L073RZ/KEIL/lorawan/TencentOS_tiny.uvprojx +++ b/board/NUCLEO_STM32L073RZ/KEIL/lorawan/TencentOS_tiny.uvprojx @@ -338,7 +338,7 @@ USE_HAL_DRIVER,STM32L073xx,USE_HAL_DRIVER,STM32L073xx - ..\..\BSP\Inc;../../../../platform/vendor_bsp/st/STM32L0xx_HAL_Driver/Inc;../../../../platform/vendor_bsp/st/STM32L0xx_HAL_Driver/Inc/Legacy;../../../../platform/vendor_bsp/st/CMSIS/Device/ST/STM32L0xx/Include;../../../../platform/vendor_bsp/st/CMSIS/Include;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m0+\armcc;..\..\..\..\kernel\core\include;..\..\..\..\kernel\pm\include;..\..\..\..\kernel\hal\include;..\..\..\..\osal\cmsis_os;..\..\TOS_CONFIG;..\..\..\..\devices\rhf76_lora;..\..\..\..\net\at\include;..\..\..\..\net\lora_module_wrapper;..\..\BSP\HardWare\HTS221 + ..\..\BSP\Inc;../../../../platform/vendor_bsp/st/STM32L0xx_HAL_Driver/Inc;../../../../platform/vendor_bsp/st/STM32L0xx_HAL_Driver/Inc/Legacy;../../../../platform/vendor_bsp/st/CMSIS/Device/ST/STM32L0xx/Include;../../../../platform/vendor_bsp/st/CMSIS/Include;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m0+\armcc;..\..\..\..\kernel\core\include;..\..\..\..\kernel\pm\include;..\..\..\..\kernel\hal\include;..\..\..\..\osal\cmsis_os;..\..\TOS_CONFIG;..\..\..\..\devices\rhf76_lora;..\..\..\..\net\at\include;..\..\..\..\net\lora_module_wrapper;..\..\BSP\HardWare\HTS221;..\..\..\..\examples\LoRaWAN @@ -695,7 +695,7 @@ lora_demo.c 1 - ..\..\..\..\examples\LoRaWAN\lora_demo.c + ..\..\BSP\Src\lora_demo.c diff --git a/board/TencentOS_tiny_EVB_MX/KEIL/lorawan/TencentOS_tiny.uvoptx b/board/TencentOS_tiny_EVB_MX/KEIL/lorawan/TencentOS_tiny.uvoptx index 6c73c5b7..2dc613b7 100644 --- a/board/TencentOS_tiny_EVB_MX/KEIL/lorawan/TencentOS_tiny.uvoptx +++ b/board/TencentOS_tiny_EVB_MX/KEIL/lorawan/TencentOS_tiny.uvoptx @@ -270,7 +270,7 @@ Application/User - 1 + 0 0 0 0 @@ -398,7 +398,7 @@ examples - 0 + 1 0 0 0 @@ -778,7 +778,7 @@ kernel - 1 + 0 0 0 0 diff --git a/board/TencentOS_tiny_EVB_MX/KEIL/lorawan/TencentOS_tiny.uvprojx b/board/TencentOS_tiny_EVB_MX/KEIL/lorawan/TencentOS_tiny.uvprojx index ba3067dc..fd66a99b 100644 --- a/board/TencentOS_tiny_EVB_MX/KEIL/lorawan/TencentOS_tiny.uvprojx +++ b/board/TencentOS_tiny_EVB_MX/KEIL/lorawan/TencentOS_tiny.uvprojx @@ -338,7 +338,7 @@ USE_HAL_DRIVER,STM32L431xx,WITH_TOS_NET_ADAPTER,USE_ESP8266 - ..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32L4xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\kernel\core\include;..\..\TOS-CONFIG;..\..\..\..\platform\arch\arm\cortex-m4\keil;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc;..\..\BSP\Hardware\DHT11;..\..\BSP\Hardware\BH1750;..\..\BSP\Hardware\OLED;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\..\..\net\lora_module_wrapper;..\..\..\..\components\connectivity\Eclipse-Paho-MQTT\wrapper\include;..\..\..\..\components\connectivity\Eclipse-Paho-MQTT\3rdparty\include;..\..\..\..\examples\mqtt;..\..\..\..\devices\rhf76_lora + ..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32L4xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\kernel\core\include;..\..\TOS-CONFIG;..\..\..\..\platform\arch\arm\cortex-m4\keil;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc;..\..\BSP\Hardware\DHT11;..\..\BSP\Hardware\BH1750;..\..\BSP\Hardware\OLED;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\..\..\net\lora_module_wrapper;..\..\..\..\components\connectivity\Eclipse-Paho-MQTT\wrapper\include;..\..\..\..\components\connectivity\Eclipse-Paho-MQTT\3rdparty\include;..\..\..\..\examples\LoRaWAN;..\..\..\..\devices\rhf76_lora diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvoptx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvoptx index 6c73c5b7..2dc613b7 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvoptx +++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvoptx @@ -270,7 +270,7 @@ Application/User - 1 + 0 0 0 0 @@ -398,7 +398,7 @@ examples - 0 + 1 0 0 0 @@ -778,7 +778,7 @@ kernel - 1 + 0 0 0 0 diff --git a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvprojx b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvprojx index ba3067dc..fd66a99b 100644 --- a/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvprojx +++ b/board/TencentOS_tiny_EVB_MX_Plus/KEIL/lorawan/TencentOS_tiny.uvprojx @@ -338,7 +338,7 @@ USE_HAL_DRIVER,STM32L431xx,WITH_TOS_NET_ADAPTER,USE_ESP8266 - ..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32L4xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\kernel\core\include;..\..\TOS-CONFIG;..\..\..\..\platform\arch\arm\cortex-m4\keil;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc;..\..\BSP\Hardware\DHT11;..\..\BSP\Hardware\BH1750;..\..\BSP\Hardware\OLED;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\..\..\net\lora_module_wrapper;..\..\..\..\components\connectivity\Eclipse-Paho-MQTT\wrapper\include;..\..\..\..\components\connectivity\Eclipse-Paho-MQTT\3rdparty\include;..\..\..\..\examples\mqtt;..\..\..\..\devices\rhf76_lora + ..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32L4xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\kernel\core\include;..\..\TOS-CONFIG;..\..\..\..\platform\arch\arm\cortex-m4\keil;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc;..\..\BSP\Hardware\DHT11;..\..\BSP\Hardware\BH1750;..\..\BSP\Hardware\OLED;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\..\..\net\lora_module_wrapper;..\..\..\..\components\connectivity\Eclipse-Paho-MQTT\wrapper\include;..\..\..\..\components\connectivity\Eclipse-Paho-MQTT\3rdparty\include;..\..\..\..\examples\LoRaWAN;..\..\..\..\devices\rhf76_lora diff --git a/examples/LoRaWAN/lora_demo.c b/examples/LoRaWAN/lora_demo.c index accc7323..b2b55146 100644 --- a/examples/LoRaWAN/lora_demo.c +++ b/examples/LoRaWAN/lora_demo.c @@ -1,5 +1,4 @@ #include "lora_demo.h" -#include "HTS221.h" #include "RHF76.h" /* @@ -91,7 +90,6 @@ void application_entry(void *arg) int16_t temperature; int16_t humidity; - HTS221_Init(); rhf76_lora_init(HAL_UART_PORT_1); tos_lora_module_recvcb_register(recv_callback); @@ -99,9 +97,9 @@ void application_entry(void *arg) tos_lora_module_join_otaa("8cf957200000fa57", "8cf957200000fa572059aaaaad204a72"); while (1) { - HTS221_Get_Temperature(&temperature); - HTS221_Get_Humidity(&humidity); - + temperature = 300; + humidity = 800; + printf("temperature: %2.1f\n", temperature / 10.0); printf("humidity : %2.1f\n", humidity / 10.0);