|
@ -165,10 +165,6 @@ void setup() { |
|
|
alarmclock.updateNTPTime(); |
|
|
alarmclock.updateNTPTime(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Serial.print(" Alarm time: "); alarmclock.printTimeUnix(TIME_ALARM); |
|
|
|
|
|
double seconds = alarmclock.getSecondsToAlarm(); |
|
|
|
|
|
Serial.printf("alarm in %f seconds\n", seconds); |
|
|
|
|
|
|
|
|
|
|
|
if (!alarmclock.isPending(secondsToSleep)) suspend(); |
|
|
if (!alarmclock.isPending(secondsToSleep)) suspend(); |
|
|
else if (!alarmclock.isPending(5*60)) suspend(5*60); |
|
|
else if (!alarmclock.isPending(5*60)) suspend(5*60); |
|
|
} |
|
|
} |
|
@ -189,24 +185,16 @@ void setup() { |
|
|
iot.mqtt.onMessage(onMqttMessage); |
|
|
iot.mqtt.onMessage(onMqttMessage); |
|
|
|
|
|
|
|
|
iot.mqtt.setWill(sensorTopic.c_str(), 0, false, "OFFLINE"); |
|
|
iot.mqtt.setWill(sensorTopic.c_str(), 0, false, "OFFLINE"); |
|
|
|
|
|
/*
|
|
|
while (iot.wifi.status() != WL_CONNECTED) { |
|
|
while (iot.wifi.status() != WL_CONNECTED) { |
|
|
delay(500); |
|
|
delay(500); |
|
|
Serial.print("."); |
|
|
Serial.print("."); |
|
|
screen->draw(); |
|
|
screen->draw(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
WiFi.onEvent(WiFiGotIP, WiFiEvent_t::SYSTEM_EVENT_STA_GOT_IP); |
|
|
onWiFiConnect(); |
|
|
|
|
|
*/ |
|
|
IPAddress localIP = iot.wifi.getIP(); |
|
|
strcpy(state.timeStr, "--:--:--"); |
|
|
char ipStr[16]; |
|
|
|
|
|
localIP.toString().toCharArray(ipStr, 16); |
|
|
|
|
|
|
|
|
|
|
|
if (!alarmclock.isTimeValid()) { |
|
|
|
|
|
ESP_LOGI(TAG, "Time is not set yet. Connecting to WiFi and getting time over NTP."); |
|
|
|
|
|
alarmclock.updateNTPTime(); |
|
|
|
|
|
} |
|
|
|
|
|
alarmclock.getTime(state.timeStr, sizeof(state.timeStr), "%H:%M:%S", TIME_CURRENT); |
|
|
|
|
|
|
|
|
|
|
|
if (alarmclock.isNight()) { |
|
|
if (alarmclock.isNight()) { |
|
|
Serial.println("night mode"); |
|
|
Serial.println("night mode"); |
|
@ -223,12 +211,22 @@ void setup() { |
|
|
|
|
|
|
|
|
mp3.begin(); |
|
|
mp3.begin(); |
|
|
led.setup(); |
|
|
led.setup(); |
|
|
udp.beginMulticast(udpMulticastAddress, udpMulticastPort); |
|
|
|
|
|
|
|
|
|
|
|
lastButtonPress = millis(); |
|
|
lastButtonPress = millis(); |
|
|
rotary.registerCallback(rotation); |
|
|
rotary.registerCallback(rotation); |
|
|
rotary.begin(rotaryPinA, rotaryPinB, rotaryPinButton); |
|
|
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) { |
|
|
if (wakeup_reason == ESP_SLEEP_WAKEUP_EXT1) { |
|
|
uint64_t wakeup_pinmask = esp_sleep_get_ext1_wakeup_status(); |
|
|
uint64_t wakeup_pinmask = esp_sleep_get_ext1_wakeup_status(); |
|
|
if (wakeup_pinmask & (1ULL << ext_wakeup_pin_1)) { |
|
|
if (wakeup_pinmask & (1ULL << ext_wakeup_pin_1)) { |
|
@ -237,14 +235,7 @@ void setup() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
lastActive = millis(); |
|
|
udp.beginMulticast(udpMulticastAddress, udpMulticastPort); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void WiFiGotIP(WiFiEvent_t event, WiFiEventInfo_t info) |
|
|
|
|
|
{ |
|
|
|
|
|
Serial.println("WiFi connected"); |
|
|
|
|
|
Serial.println("IP address: "); |
|
|
|
|
|
Serial.println(IPAddress(info.got_ip.ip_info.ip.addr)); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -262,6 +253,10 @@ void onMqttConnect(bool sessionPresent) { |
|
|
void transmitStatus() { |
|
|
void transmitStatus() { |
|
|
DEBUG_PRINTLN(__func__); |
|
|
DEBUG_PRINTLN(__func__); |
|
|
|
|
|
|
|
|
|
|
|
if (iot.wifi.status() != WL_CONNECTED) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
float temp = bme280.readTemperature(); |
|
|
float temp = bme280.readTemperature(); |
|
|
float humi = bme280.readHumidity(); |
|
|
float humi = bme280.readHumidity(); |
|
|
float pres = bme280.readPressure(); |
|
|
float pres = bme280.readPressure(); |
|
@ -376,6 +371,13 @@ void loop() |
|
|
if(millis() - lastUpdate >= 1000) { |
|
|
if(millis() - lastUpdate >= 1000) { |
|
|
lastUpdate = millis(); |
|
|
lastUpdate = millis(); |
|
|
|
|
|
|
|
|
|
|
|
if (iot.wifi.status() == WL_CONNECTED) { |
|
|
|
|
|
if (alarmclock.isNTPExpired()) { // will return true first time called
|
|
|
|
|
|
Serial.println("Updating NTP Time"); |
|
|
|
|
|
alarmclock.updateNTPTime(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
double seconds = alarmclock.getSecondsToAlarm(); |
|
|
double seconds = alarmclock.getSecondsToAlarm(); |
|
|
|
|
|
|
|
|
bool stayAwake = false; |
|
|
bool stayAwake = false; |
|
@ -413,7 +415,7 @@ void loop() |
|
|
int voltage = rom_phy_get_vdd33(); |
|
|
int voltage = rom_phy_get_vdd33(); |
|
|
Serial.printf("voltage: %d\n", voltage); |
|
|
Serial.printf("voltage: %d\n", voltage); |
|
|
|
|
|
|
|
|
alarmclock.getTime(state.timeStr, sizeof(state.timeStr), "%H:%M:%S", TIME_CURRENT); |
|
|
if (alarmclock.isTimeValid()) alarmclock.getTime(state.timeStr, sizeof(state.timeStr), "%H:%M:%S", TIME_CURRENT); |
|
|
sprintf(state.string1, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure()); |
|
|
sprintf(state.string1, "%.1f°C %.1f%% %.0fhPa", bme280.readTemperature(), bme280.readHumidity(), bme280.readPressure()); |
|
|
sprintf(state.string2, "%.1f %dmV %ddBm %ukB %s", temperatureRead(), voltage, WiFi.RSSI(), ESP.getFreeHeap()/1024, alarmclock.isAlarmArmed()?"A":"_"); |
|
|
sprintf(state.string2, "%.1f %dmV %ddBm %ukB %s", temperatureRead(), voltage, WiFi.RSSI(), ESP.getFreeHeap()/1024, alarmclock.isAlarmArmed()?"A":"_"); |
|
|
|
|
|
|
|
@ -449,14 +451,14 @@ void loop() |
|
|
lastTransmit = millis(); |
|
|
lastTransmit = millis(); |
|
|
transmitStatus(); |
|
|
transmitStatus(); |
|
|
} |
|
|
} |
|
|
|
|
|
/*
|
|
|
int lenp = udp.parsePacket(); |
|
|
int lenp = udp.parsePacket(); |
|
|
//Serial.println(lenp);
|
|
|
//Serial.println(lenp);
|
|
|
while(udp.available()) { |
|
|
while(udp.available()) { |
|
|
int len = udp.read(udprecvbuf, sizeof(udprecvbuf)); |
|
|
int len = udp.read(udprecvbuf, sizeof(udprecvbuf)); |
|
|
Serial.printf("udp received %d bytes\n", len); |
|
|
Serial.printf("udp received %d bytes\n", len); |
|
|
} |
|
|
} |
|
|
|
|
|
*/ |
|
|
if (menuChange != eNone) { |
|
|
if (menuChange != eNone) { |
|
|
delete screen; |
|
|
delete screen; |
|
|
if (menuChange == eMainScreen) screen = new MainScreen(); |
|
|
if (menuChange == eMainScreen) screen = new MainScreen(); |
|
|