diff -r 49eb753a958b -r e3edc783006b thermferm/thermferm.c --- a/thermferm/thermferm.c Sat Mar 23 12:18:14 2024 +0100 +++ b/thermferm/thermferm.c Sat Mar 23 16:01:24 2024 +0100 @@ -46,12 +46,17 @@ extern sys_config Config; extern int lcdHandle; extern int slcdHandle; +extern int my_devices_state; +extern int my_panel_state; +extern int my_server_state; +extern int my_simulator_state; int setupmenu = MENU_NONE; units_list *current_unit = NULL; /* In panel editor this points to the current unit. */ float temp_temp = 20.0; pthread_t threads[5]; pthread_mutex_t mutexes[5]; + extern const char UNITMODE[5][8]; extern const char PROFSTATE[4][6]; @@ -1900,16 +1905,14 @@ } syslog(LOG_NOTICE, "Unit `%s' stopped in mode %s", unit->alias, UNITMODE[unit->mode]); } - - usleep(100000); - mqtt_disconnect(); - syslog(LOG_NOTICE, "Out of loop"); /* - * Give threads time to cleanup + * Note that we don't care if the command server is stopped, this one + * does almost certain keep running but tat doesn't harm. */ - usleep(1500000); + while ((my_devices_state + my_panel_state + my_simulator_state) > 0) {}; + mqtt_disconnect(); stopLCD(); if (sock != -1) {