diff --git a/Core/Src/main.c b/Core/Src/main.c index 6393797..2fc0a88 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -100,8 +100,20 @@ int main(void) MX_I2C2_Init(); MX_DMA_Init(); + if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB) == RESET) + { + + MX_LoRaWAN_Init(); + } else + { + __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB); + + /* Enable access to RTC domain for following wake-up source configuration */ + //HAL_PWR_EnableBkUpAccess(); + //__HAL_RCC_RTCAPB_CLK_ENABLE(); + + } - MX_LoRaWAN_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 2e67930..9f3c5fb 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -1080,6 +1080,7 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams) LmHandlerParams.IsTxConfirmed = true; LmHandlerErrorStatus_t status = LmHandlerSend(&AppData, LmHandlerParams.IsTxConfirmed, false); if (status ==LORAMAC_HANDLER_SUCCESS ) LmHandlerParams.IsTxConfirmed = false; + } else { @@ -1426,26 +1427,26 @@ static void OnYunhornSTSHeartBeatTimerEvent(void *context) * @brief Yunhorn STS Heart Beat Periodicity Chagne function * @param duration of periodicty in ms (1/1000 sec) */ -void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity) +void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t newperiodicity) { /* USER CODE BEGIN OnYunhornSTSHeartBeatPeriodicityChanged_1 */ /* USER CODE END OnYunhornSTSHeartBeatPeriodicityChanged_1 */ - if (periodicity == 0) + if (newperiodicity == 0) { /* Revert to application default Heat-beat periodicity */ - periodicity = 10*APP_TX_DUTYCYCLE; //10*10 000 ms + newperiodicity = 10*APP_TX_DUTYCYCLE; //10*10 000 ms } /* Update timer YunhornSTSHeartBeatTimer */ UTIL_TIMER_Stop(&YunhornSTSHeartBeatTimer); - UTIL_TIMER_SetPeriod(&YunhornSTSHeartBeatTimer, periodicity); + UTIL_TIMER_SetPeriod(&YunhornSTSHeartBeatTimer, newperiodicity); UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); /* USER CODE BEGIN OnYunhornSTSHeartBeatPeriodicityChanged_2 */ - APP_LOG(TS_OFF, VLEVEL_M,"* STS HeartBeatPeriodicity = %u (sec)\r\n", periodicity/1000 ); + APP_LOG(TS_OFF, VLEVEL_H,"* STS HeartBeatPeriodicity = %u (sec)\r\n", newperiodicity/1000 ); /* USER CODE END OnYunhornSTSHeartBeatPeriodicityChanged_2 */ } @@ -1478,6 +1479,6 @@ void OnYunhornSTSTxPeriodicityChanged(uint32_t periodicity) UTIL_TIMER_Start(&TxTimer); /* USER CODE BEGIN OnYunhornSTSTxPeriodicityChanged */ - APP_LOG(TS_OFF, VLEVEL_M,"* STS TxPeriodicity = %u (sec)\r\n", TxPeriodicity/1000 ); + APP_LOG(TS_OFF, VLEVEL_H,"* STS TxPeriodicity = %u (sec)\r\n", TxPeriodicity/1000 ); /* USER CODE END OnYunhornSTSTxPeriodicityChanged */ } diff --git a/LoRaWAN/App/lora_app.h b/LoRaWAN/App/lora_app.h index 52f4d16..ae4a403 100644 --- a/LoRaWAN/App/lora_app.h +++ b/LoRaWAN/App/lora_app.h @@ -68,7 +68,7 @@ extern "C" { /*! * LoRaWAN default class */ -#define LORAWAN_DEFAULT_CLASS CLASS_C +#define LORAWAN_DEFAULT_CLASS CLASS_A /*! * LoRaWAN default confirm state diff --git a/LoRaWAN/Target/lorawan_conf.h b/LoRaWAN/Target/lorawan_conf.h index 1706743..9ddccb0 100644 --- a/LoRaWAN/Target/lorawan_conf.h +++ b/LoRaWAN/Target/lorawan_conf.h @@ -109,7 +109,7 @@ extern "C" { * - CHANNEL_PLAN_GROUP_AS923_4 (Freq offset = -5.90 MHz / Freq range = 917-920MHz) * - CHANNEL_PLAN_GROUP_AS923_1_JP (Freq offset = 0.0 MHz / Freq range = 920.6-923.4MHz) */ -#define REGION_AS923_DEFAULT_CHANNEL_PLAN CHANNEL_PLAN_GROUP_AS923_1 +#define REGION_AS923_DEFAULT_CHANNEL_PLAN CHANNEL_PLAN_GROUP_AS923_1_JP /*! * @brief Limits the number usable channels by default for AU915, CN470 and US915 regions diff --git a/STM32CubeIDE/Release/makefile b/STM32CubeIDE/Release/makefile index 2173897..7427775 100644 --- a/STM32CubeIDE/Release/makefile +++ b/STM32CubeIDE/Release/makefile @@ -15,6 +15,8 @@ RM := rm -rf -include Drivers/STM32WLxx_HAL_Driver/subdir.mk -include Drivers/CMSIS/subdir.mk -include Drivers/BSP/STM32WLxx_Nucleo/subdir.mk +-include Drivers/BSP/Components/subdir.mk +-include Drivers/BSP/53L8A1/subdir.mk -include Application/User/Startup/subdir.mk -include Application/User/STS/TOF/vl53l0x/subdir.mk -include Application/User/STS/TOF/Target/subdir.mk diff --git a/STM32CubeIDE/Release/sources.mk b/STM32CubeIDE/Release/sources.mk index a6f330f..f021f94 100644 --- a/STM32CubeIDE/Release/sources.mk +++ b/STM32CubeIDE/Release/sources.mk @@ -30,6 +30,8 @@ Application/User/STS/TOF/App \ Application/User/STS/TOF/Target \ Application/User/STS/TOF/vl53l0x \ Application/User/Startup \ +Drivers/BSP/53L8A1 \ +Drivers/BSP/Components \ Drivers/BSP/STM32WLxx_Nucleo \ Drivers/CMSIS \ Drivers/STM32WLxx_HAL_Driver \ diff --git a/STS/Core/Src/yunhorn_sts_process.c b/STS/Core/Src/yunhorn_sts_process.c index f48a1cd..a05e377 100644 --- a/STS/Core/Src/yunhorn_sts_process.c +++ b/STS/Core/Src/yunhorn_sts_process.c @@ -108,7 +108,7 @@ volatile uint8_t sts_work_mode=4; volatile uint32_t rfac_timer=0; volatile uint16_t sts_sensor_install_height=3000; volatile uint8_t sensor_data_ready=0; -volatile uint32_t STS_TOFScanPeriod_msec=50, STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=60; +volatile uint32_t STS_TOFScanPeriod_msec=50, STS_TxPeriod_sec=300, STS_HeartBeatTimerPeriod_sec=3600; static uint8_t outbuf[128]={0x0}; extern volatile hmac_result_t hmac_result; extern uint16_t sensor_id; @@ -1330,7 +1330,11 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s sts_cfg_nvm.sts_service_mask = sts_service_mask; OnStoreSTSCFGContextRequest(); - + i=0; + UTIL_MEM_set_8((void*)outbuf, 0x0, sizeof(outbuf)); + UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf, parse_buffer_size); + i = parse_buffer_size; + STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf); } else { sts_service_mask = STS_SERVICE_MASK_L2; @@ -1338,12 +1342,6 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s sts_ac_code[19] =0x0; } - i=0; - UTIL_MEM_set_8((void*)outbuf, 0x0, sizeof(outbuf)); - UTIL_MEM_cpy_8((void*)outbuf,(void*)tlv_buf, parse_buffer_size); - i = parse_buffer_size; - STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf); - } break; default: @@ -1578,7 +1576,8 @@ void OnRestoreSTSCFGContextProcess(void) APP_LOG(TS_OFF, VLEVEL_H, "\n\n Tx periodicity in NVM =%u sec\n",periodicity); TxPeriodicity= periodicity*1000; // to ms - + STS_TxPeriod_sec = periodicity; + //STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=60; uint32_t sampling_heartbeat_periodicity = (sts_cfg_nvm.sampling); //Heart-beat or Sampling interval if ((char)sts_cfg_nvm.s_unit =='M') { sampling_heartbeat_periodicity *= 60; @@ -1587,7 +1586,7 @@ void OnRestoreSTSCFGContextProcess(void) } else if ((char) sts_cfg_nvm.s_unit =='S') { sampling_heartbeat_periodicity *= 1; } - + STS_HeartBeatTimerPeriod_sec = sampling_heartbeat_periodicity; APP_LOG(TS_OFF, VLEVEL_H, "\n\n sampling or heartbeat periodicity in NVM =%u sec\n",sampling_heartbeat_periodicity); if ((sts_cfg_nvm.ac[0] ==0x0 )&& (sts_cfg_nvm.ac[19]==0x0))