From f3fcd32785ec6a180053786d9b7dec01ca1ce622 Mon Sep 17 00:00:00 2001 From: Marcus Date: Sun, 14 Apr 2024 16:39:49 +0200 Subject: [PATCH] firmware WIP - add ntp support --- Arduino/CanGrow/CanGrow.ino | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index c918816..367cc7d 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -18,7 +18,8 @@ #include #include #include - +#include +#include /* * @@ -41,9 +42,18 @@ float valHumidity; * EEPROM variables */ +// +// System +// // configured - if true, run setup assistant bool configured; +// NTP Offset +int ntpOffset; + +// +// WiFi +// char WIFIssid[32]; char WIFIpassword[64]; // WIFIuseDHCP - if true, get IP by DHCP @@ -53,6 +63,9 @@ IPAddress WIFInetmask(255,255,255,0); IPAddress WIFIgateway(192,168,4,254); IPAddress WIFIdns(0,0,0,0); +// +// Grow Stuff +// // GrowName - contains the name of the grow/plant. Up to 32 byte char GrowName[32]; // GrowStart - contains unix timestamp from date where grow starts (00:00) @@ -68,9 +81,10 @@ byte DaysBloom; byte LighthoursVeg; // LighthoursBloom - contains how many hours the Growlight is on in Bloom byte LighthoursBloom; - -// Sunrise - contains to which hour of day the growlight turns on -byte Sunrise; +// SunriseHour - contains to which hour of day the growlight turns on +byte SunriseHour; +// SunriseHour - contains to which minute of SunriseHour the growlight turns on +byte SunriseMinute; // PINled_PWM - contains the PWM value for dimming the grow light byte PINled_PWM; // MoistureSensor_Type - contains which moisture sensor to use @@ -106,6 +120,13 @@ const bool APhidden = false; */ +/* + * NTP + */ + +WiFiUDP ntpUDP; +NTPClient timeClient(ntpUDP); + /* * * Webserver @@ -534,6 +555,11 @@ void wifiConnect() { Serial.println(" CONNECTED!"); Serial.print("IP: "); Serial.println(WiFi.localIP()); + Serial.println("Get actual time from NTP"); + timeClient.begin(); + timeClient.update(); + Serial.println(timeClient.getFormattedTime()); + Serial.println(timeClient.getEpochTime()); } void wifiAp() { @@ -763,6 +789,9 @@ void WEBroot() { String body = FPSTR(HTMLheader); body += "

configured!

"; + body += "

"; + body += timeClient.getFormattedTime(); + body += "

"; body += FPSTR(HTMLfooter); webserver.send(200, "text/html", body);