--- a/main/iotbalkon.c Thu Apr 06 20:53:06 2023 +0200 +++ b/main/iotbalkon.c Thu Apr 06 22:01:08 2023 +0200 @@ -388,7 +388,7 @@ xTaskCreate(&task_out, "task_out", 2560, NULL, 9, &xTaskOUT); // esp_log_level_set("MQTT_CLIENT", ESP_LOG_ERROR); xTaskCreate(&task_mqtt, "task_mqtt", 4096, NULL, 5, &xTaskMQTT); - // esp_log_level_set("wifi", ESP_LOG_ERROR); + esp_log_level_set("wifi", ESP_LOG_ERROR); xTaskCreate(&task_wifi, "task_wifi", 4096, NULL, 3, &xTaskWifi); vTaskDelay(10 / portTICK_PERIOD_MS); @@ -529,16 +529,21 @@ // } } getTempBaro(); + vTaskDelay(2000 / portTICK_PERIOD_MS); publish(); State = State_WorkDone; - gTimeNext = millis() + SUB_TIME; + /* + * Wait an extra second so the publish message will reach + * the broker and the subscriptions are really here. + */ + gTimeNext = millis() + 1000; break; - case State_WorkDone: vTaskDelay(20 / portTICK_PERIOD_MS); - if (gTimeInMillis > gTimeNext) { + case State_WorkDone: if (gTimeInMillis > gTimeNext) { State = State_Disconnect_MQTT; request_mqtt(false); } + vTaskDelay(50 / portTICK_PERIOD_MS); break; case State_Disconnect_MQTT: wait_mqtt(10000); @@ -577,12 +582,6 @@ DS_Active = 1; nvsio_write_u32((char *)"ds_time", ds_time); DS_Time = ds_time; - // if ((! EEPROM.read(EM_DS_Active)) || (EEPROM.read(EM_DS_Time) != ds_time)) { - // EEPROM.write(EM_DS_Active, 1); - // EEPROM.write(EM_DS_Time, ds_time); - // EEPROM.commit(); - // Serial.println("wrote new deep-sleep settings"); - // } State = State_GoSleep; } break;