This commit is contained in:
53
src/main.cpp
53
src/main.cpp
@@ -25,6 +25,7 @@
|
||||
#include "networking/responses.h"
|
||||
#include <fetchOTA.h>
|
||||
#include <ESP32Ping.h>
|
||||
#include "time.h"
|
||||
|
||||
#define MYLOG 0
|
||||
|
||||
@@ -47,8 +48,6 @@ AsyncWebSocket webSocket("/webSocket");
|
||||
void setup()
|
||||
{
|
||||
logger.registerSerial(MYLOG, DEBUG, "tst");
|
||||
logger.
|
||||
logger.provideTime(2025, 3, 10, 23, 28, 00);
|
||||
prefs.begin("waterlevel", false);
|
||||
Serial.begin(115200);
|
||||
|
||||
@@ -205,19 +204,55 @@ void setup()
|
||||
display_error_code(26);
|
||||
digitalWrite(LED_RED, 0);
|
||||
|
||||
// Starting bootup sequence
|
||||
|
||||
xTaskCreate(ethernet_task, "EthernetTask", 4096, NULL, 1, NULL);
|
||||
delay(1000);
|
||||
bool started = false;
|
||||
|
||||
// Create Etnernet task and wait a second to see if there is connection
|
||||
logger.log(0, DEBUG, "Started Ethernet, waiting");
|
||||
delay(2000);
|
||||
|
||||
if (ETH.linkUp()){
|
||||
logger.log(0, DEBUG, "Ethernet connected, starting update checker");
|
||||
xTaskCreate(check_update_task, "CheckUpdateTask", 1024 * 8, NULL, 1, NULL);
|
||||
started = true;
|
||||
}
|
||||
xTaskCreate(wifi_task, "WiFiTask", 10000, NULL, 1, NULL);
|
||||
if (!started) {
|
||||
} else {
|
||||
logger.log(0, DEBUG, "Ethernet not connected, starting update checker and WiFi Task");
|
||||
xTaskCreate(wifi_task, "WiFiTask", 10000, NULL, 1, NULL);
|
||||
xTaskCreate(check_update_task, "CheckUpdateTask", 1024 * 8, NULL, 1, NULL);
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
logger.log(0, DEBUG, "Getting time now");
|
||||
// Configure time with a GMT offset and daylight offset in seconds.
|
||||
configTime(3600, 0, "pool.ntp.org");
|
||||
|
||||
// Wait until a valid time is obtained (time > 8 hours in seconds)
|
||||
time_t now = time(NULL);
|
||||
struct tm timeinfo;
|
||||
int retry = 0;
|
||||
while (now < 8 * 3600 && retry < 10) {
|
||||
if(!getLocalTime(&timeinfo)){
|
||||
Serial.println("Failed to obtain time");
|
||||
}
|
||||
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
|
||||
retry++;
|
||||
}
|
||||
|
||||
|
||||
getLocalTime(&timeinfo);
|
||||
|
||||
// Sanity check: Ensure the year is at least 2020.
|
||||
int currentYear = timeinfo.tm_year + 1900; // tm_year is years since 1900
|
||||
if (currentYear < 2020) {
|
||||
logger.log(0, DEBUG, "Time not set properly: ");
|
||||
} else {
|
||||
logger.log(0, DEBUG, "Time is valid: %s", asctime(&timeinfo));
|
||||
}
|
||||
|
||||
// Setup syslog
|
||||
logger.configureSyslog("192.168.6.11", 5514, "esp32");
|
||||
logger.registerSyslog(MYLOG, DEBUG, FAC_LOCAL4, "mylog");
|
||||
logger.registerSyslog(MYLOG, DEBUG, FAC_USER, "waterlevel");
|
||||
logger.log(MYLOG, ERROR, "Here is an error message, error code: %d", 17);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user