firmware WIP - add ntp support

This commit is contained in:
Marcus 2024-04-14 16:39:49 +02:00
parent be590b2e2d
commit f3fcd32785
1 changed files with 33 additions and 4 deletions

View File

@ -18,7 +18,8 @@
#include <ESP8266WebServer.h>
#include <EEPROM.h>
#include <ArduinoJson.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
/*
*
@ -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 += "<h1>configured!</h1>";
body += "<p>";
body += timeClient.getFormattedTime();
body += "</p>";
body += FPSTR(HTMLfooter);
webserver.send(200, "text/html", body);