fix bug with bad data from modbus: add 15 tries

This commit is contained in:
Edward Emelianov 2022-06-14 09:40:00 +03:00
parent 77ca453860
commit d62a4ec59d
2 changed files with 3 additions and 1 deletions

View File

@ -155,7 +155,8 @@ params_ans check_meteo_params(){
struct timeval timeout; struct timeval timeout;
fd_set set; fd_set set;
time_t tstart = time(NULL); time_t tstart = time(NULL);
while(n_bytes){ int ctr = 15; // max 15 tries
while(ctr--) while(n_bytes){
FD_ZERO(&set); FD_ZERO(&set);
FD_SET(portfd, &set); FD_SET(portfd, &set);
timeout.tv_sec = 0; timeout.tv_sec = 0;

View File

@ -116,6 +116,7 @@ int main(int argc, char *argv[]){
params_ans a = check_meteo_params(); params_ans a = check_meteo_params();
if(a == ANS_LOSTCONN){ if(a == ANS_LOSTCONN){
LOG("Lost connection with device, reconnect!"); LOG("Lost connection with device, reconnect!");
clear_flags();
return 1; return 1;
} }
if(a == ANS_OK){ if(a == ANS_OK){