diff --git a/src/AlarmClock.cpp b/src/AlarmClock.cpp index 67ed47d..ae4085c 100644 --- a/src/AlarmClock.cpp +++ b/src/AlarmClock.cpp @@ -100,6 +100,7 @@ bool AlarmClock::isNTPExpired(void) { } bool AlarmClock::updateNTPTime(void) { + ESP_LOGI(TAG, "Getting time over NTP."); sntp_setoperatingmode(SNTP_OPMODE_POLL); sntp_setservername(0, "de.pool.ntp.org"); sntp_init(); diff --git a/src/main.cpp b/src/main.cpp index 3470f63..bb96e8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -217,26 +217,9 @@ void setup() { rotary.registerCallback(rotation); rotary.begin(rotaryPinA, rotaryPinB, rotaryPinButton); - lastActive = millis(); -} - - -void onWiFiConnect() { - if (!alarmclock.isTimeValid()) { - ESP_LOGI(TAG, "Time is not set yet. Connecting to WiFi and getting time over NTP."); - alarmclock.updateNTPTime(); - } - - esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause(); - if (wakeup_reason == ESP_SLEEP_WAKEUP_EXT1) { - uint64_t wakeup_pinmask = esp_sleep_get_ext1_wakeup_status(); - if (wakeup_pinmask & (1ULL << ext_wakeup_pin_1)) { - uint16_t statusPacketIdSub = iot.mqtt.publish(sensorTopic.c_str(), 0, false, state.timeStr); - sensorON = true; - } - } - /* udp.beginMulticast(udpMulticastAddress, udpMulticastPort);*/ + + lastActive = millis(); } @@ -248,6 +231,14 @@ void onMqttConnect(bool sessionPresent) { iot.mqtt.subscribe(commandTopic.c_str(), 0); //Trigger the transmission of the current state. transmitStatus(); + esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause(); + if (wakeup_reason == ESP_SLEEP_WAKEUP_EXT1) { + uint64_t wakeup_pinmask = esp_sleep_get_ext1_wakeup_status(); + if (wakeup_pinmask & (1ULL << ext_wakeup_pin_1)) { + uint16_t statusPacketIdSub = iot.mqtt.publish(sensorTopic.c_str(), 0, false, state.timeStr); + sensorON = true; + } + } lastTransmit = millis(); } diff --git a/src/main.h b/src/main.h index 9170511..3e50f2d 100644 --- a/src/main.h +++ b/src/main.h @@ -4,7 +4,6 @@ void resetToFactoryDefaults(); void setup(); void onMqttConnect(bool sessionPresent); -void onWiFiConnect(); void transmitStatus(); void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total); void suspend(uint32_t secondsToSleep);