diff --git a/BTA_modbusmeteo/bta_meteo_modbus.c b/BTA_modbusmeteo/bta_meteo_modbus.c index 4d17cd5..9f4bbdd 100644 --- a/BTA_modbusmeteo/bta_meteo_modbus.c +++ b/BTA_modbusmeteo/bta_meteo_modbus.c @@ -155,7 +155,8 @@ params_ans check_meteo_params(){ struct timeval timeout; fd_set set; time_t tstart = time(NULL); - while(n_bytes){ + int ctr = 15; // max 15 tries + while(ctr--) while(n_bytes){ FD_ZERO(&set); FD_SET(portfd, &set); timeout.tv_sec = 0; diff --git a/BTA_modbusmeteo/main.c b/BTA_modbusmeteo/main.c index 59c9444..0fcbf2b 100644 --- a/BTA_modbusmeteo/main.c +++ b/BTA_modbusmeteo/main.c @@ -116,6 +116,7 @@ int main(int argc, char *argv[]){ params_ans a = check_meteo_params(); if(a == ANS_LOSTCONN){ LOG("Lost connection with device, reconnect!"); + clear_flags(); return 1; } if(a == ANS_OK){