diff -r 9c0bcc91fe1a -r 2cc30d828d6e main/iotbalkon.c --- a/main/iotbalkon.c Tue Apr 11 11:11:13 2023 +0200 +++ b/main/iotbalkon.c Tue Apr 11 19:41:53 2023 +0200 @@ -395,8 +395,8 @@ /* * Main application loop. */ - int State = State_Init; - int OldState = State_Init + 1; + int State = State_Init; + int OldState = State_Init + 1; uint8_t ds_time = DS_Time; @@ -435,10 +435,10 @@ DisCounter = 0; } else { /* - * 30 seconds connection try. + * 15 seconds connection try. */ DisCounter++; - vTaskDelay(1000 / portTICK_PERIOD_MS); + vTaskDelay(500 / portTICK_PERIOD_MS); ESP_LOGI(TAG, "* Counter WiFi %d", DisCounter); if (DisCounter > 30) { Alarm |= AL_NOWIFI; @@ -543,7 +543,7 @@ gTimeNext = millis() + 1000; break; - case State_WorkDone: if (gTimeInMillis > gTimeNext) { + case State_WorkDone: if (gTimeInMillis >= gTimeNext) { State = State_Disconnect_MQTT; request_mqtt(false); } @@ -556,20 +556,16 @@ case State_Disconnect_Wifi: request_WiFi(false); // // Reset values for average current measurement. - // HaveIP = false; loopno = 0; gLastTime = millis(); - //vTaskDelay(10 / portTICK_PERIOD_MS); /* * If any output is on, use 6 10 seconds loops. * If nothing on, do a deep sleep. */ if (Relay1 || Relay2 || Dimmer3 || Dimmer4) { - if (DS_Active != 0) { - DS_Active = 0; - nvsio_write_u8((char *)"ds_active", 0); - } + DS_Active = 0; + nvsio_write_u8((char *)"ds_active", 0); // Active mode, 60 seconds loop ST_LOOPS = 6; @@ -578,10 +574,10 @@ State = State_Wait; } else { ds_time = DS_TIME; - // if (solarVolts < 6) { - // // At night, increase the deep-sleep time. - // ds_time *= 4; - // } + if (solarVolts < 6) { + // At night, increase the deep-sleep time. + ds_time *= 4; + } nvsio_write_u8((char *)"ds_active", 1); DS_Active = 1; nvsio_write_u32((char *)"ds_time", ds_time); @@ -590,14 +586,14 @@ } break; - case State_Wait: if (gTimeInMillis > gTimeNext) { + case State_Wait: if (gTimeInMillis >= gTimeNext) { State = State_Measure; } - vTaskDelay(10 / portTICK_PERIOD_MS); + vTaskDelay(50 / portTICK_PERIOD_MS); break; - case State_Measure: getVoltsCurrent(); - gTimeNext = millis() + ST_INTERVAL; + case State_Measure: gTimeNext = millis() + ST_INTERVAL; + getVoltsCurrent(); if (loopno >= ST_LOOPS) { ESP_LOGI(TAG, "Enough loops, do connect"); getLightValues(); @@ -614,7 +610,6 @@ esp_deep_sleep_start(); break; } - vTaskDelay(10 / portTICK_PERIOD_MS); } // Not reached. }