add lora reconnect code for pm2.5 project

add lora reconnect code for pm2.5 project
This commit is contained in:
supowang
2020-06-08 16:52:11 +08:00
parent 92eda5fddc
commit 8c488a8dfb
3 changed files with 37 additions and 9 deletions

View File

@@ -95,7 +95,8 @@ uint8_t pool[DATA_CNT];
void application_entry(void *arg)
{
int i = 0;
int ret = 0;
int send_failed_count = 0;
rhf76_lora_init(HAL_UART_PORT_1);
tos_lora_module_recvcb_register(recv_callback);
@@ -113,7 +114,20 @@ void application_entry(void *arg)
}
printf("\n\n");
tos_lora_module_send(&dev_data.data, mail_size);
ret = tos_lora_module_send(&dev_data.data, mail_size);
if (ret < 0 )
{
printf("LoRa Send data faild! count is %d\r\n",send_failed_count);
send_failed_count++;
if (send_failed_count > 10)
{
eclic_system_reset();// when lora send faied more than 10 times , cpu reset to reconnect.
}
}
else
{
send_failed_count = 0;
}
}
}

View File

@@ -95,7 +95,8 @@ uint8_t pool[DATA_CNT];
void application_entry(void *arg)
{
int i = 0;
int ret = 0;
int send_failed_count = 0;
rhf76_lora_init(HAL_UART_PORT_0);
tos_lora_module_recvcb_register(recv_callback);
@@ -113,7 +114,20 @@ void application_entry(void *arg)
}
printf("\n\n");
tos_lora_module_send(&dev_data.data, mail_size);
ret = tos_lora_module_send(&dev_data.data, mail_size);
if (ret < 0 )
{
printf("LoRa Send data faild!, count is %d\r\n",send_failed_count);
send_failed_count++;
if (send_failed_count > 10)
{
NVIC_SystemReset();// when lora send faied more than 10 times , cpu reset to reconnect.
}
}
else
{
send_failed_count = 0;
}
}
}

View File

@@ -526,12 +526,12 @@ static int rhf76_send(const void *buf, size_t len)
snprintf(cmd, sizeof(cmd), RHF76_ATCMD_FMT_SEND_CMSGHEX, str_buf);
cmd[sizeof(cmd) - 1] = '\0';
tos_mmheap_free(str_buf);
tos_at_echo_create(&echo, NULL, 0, "+CMSG: ACK Received");
tos_at_echo_create(&echo, NULL, 0, "+CMSGHEX: ACK Received");
tos_at_cmd_exec(&echo, 6000, cmd);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return -1;
return len;
}
return len;
return -1;
}
static int rhf76_send_unconfirmed(const void *buf, size_t len)
@@ -552,9 +552,9 @@ static int rhf76_send_unconfirmed(const void *buf, size_t len)
tos_at_echo_create(&echo, NULL, 0, "+MSGHEX: Done");
tos_at_cmd_exec(&echo, 6000, cmd);
if (echo.status == AT_ECHO_STATUS_OK || echo.status == AT_ECHO_STATUS_EXPECT) {
return -1;
return len;
}
return len;
return -1;
}
static int rhf76_close(void)