firmware wip - add time in menu, make ntp offset work
This commit is contained in:
parent
3753dfcd96
commit
3c8cba0b45
1 changed files with 24 additions and 9 deletions
|
@ -286,6 +286,7 @@ const char HTMLheader[] PROGMEM = R"EOF(
|
|||
<li><a href="/wifiSettings">WiFi settings</a></li>
|
||||
<li><a href="/help">Help</a></li>
|
||||
<li><span id="MenuGrowName"></span></li>
|
||||
<li><span id="MenuTime"></span></li>
|
||||
</ul>
|
||||
<div class="center">
|
||||
|
||||
|
@ -833,6 +834,7 @@ void wifiConnect() {
|
|||
|
||||
Serial.println(":: Getting time from NTP ::");
|
||||
timeClient.begin();
|
||||
timeClient.setTimeOffset(ntpOffset * 60 * 60);
|
||||
timeClient.update();
|
||||
while ( ! timeClient.isTimeSet()) {
|
||||
timeClient.update();
|
||||
|
@ -1073,7 +1075,8 @@ void WebHandler() {
|
|||
|
||||
void WebRestart() {
|
||||
String body = FPSTR(HTMLheader);
|
||||
if(NeedRestart == true) {
|
||||
// TODO only debug and development solution, remove this later
|
||||
if(true) {
|
||||
body += "<h1>Restarting</h1>";
|
||||
body += "<div class='infomsg'>After restart CanGrow will be connected to WiFi SSID<br><b>";
|
||||
body += WIFIssid;
|
||||
|
@ -1123,19 +1126,28 @@ void WebAuthApi() {
|
|||
// returns footer with javascript stuff
|
||||
String returnHTMLfooter() {
|
||||
String footer;
|
||||
// show the GrowName in the menu if set
|
||||
if(strlen(GrowName) > 0){
|
||||
|
||||
// add replaceStr javascript function from PROGMEM
|
||||
// first is dst ID, second is content (&#.. is a seedling emoji )
|
||||
footer += FPSTR(JSreplaceStr);
|
||||
// print actual time in header
|
||||
footer += "<script>replaceStr('MenuTime', '";
|
||||
footer += timeClient.getFormattedTime();
|
||||
footer += "');\n";
|
||||
footer += "</script>";
|
||||
|
||||
// show the GrowName in the menu if set
|
||||
if(strlen(GrowName) > 0){
|
||||
|
||||
|
||||
footer += "<script>replaceStr('MenuGrowName', '🌱 ";
|
||||
footer += GrowName;
|
||||
footer += "');\n";
|
||||
// include the GrowName in the title
|
||||
footer += "document.title = 'CanGrow - ";
|
||||
footer += GrowName;
|
||||
footer += "';</script>";
|
||||
footer += "';";
|
||||
footer += "</script>";
|
||||
}
|
||||
|
||||
footer += FPSTR(HTMLfooter);
|
||||
|
@ -1245,7 +1257,6 @@ void WEBroot() {
|
|||
body += "<h1>🌱 ";
|
||||
body += GrowName;
|
||||
body += "</h1>";
|
||||
body += "<p>";
|
||||
body += "Grow started: ";
|
||||
body += returnStrDateFromEpoch(GrowStart);
|
||||
body += "<br>";
|
||||
|
@ -1295,7 +1306,7 @@ void WEBroot() {
|
|||
body += "</form>";
|
||||
|
||||
|
||||
body += "</p>";
|
||||
|
||||
|
||||
|
||||
body += returnHTMLfooter();
|
||||
|
@ -1431,7 +1442,7 @@ void WEBsystemSettings() {
|
|||
body += "</select><br>\n";
|
||||
|
||||
// ntpOffset int
|
||||
body += "NTP offset: <input type='number' name='ntpOffset' min='0' value='";
|
||||
body += "NTP offset: <input type='number' name='ntpOffset' min='-12' max='14' value='";
|
||||
body += ntpOffset;
|
||||
body+= "' required><br>\n";
|
||||
|
||||
|
@ -1642,6 +1653,10 @@ void POSTsystemSettings() {
|
|||
|
||||
EEPROM.commit();
|
||||
|
||||
// update time with new offset
|
||||
timeClient.setTimeOffset(ntpOffset * 60 * 60);
|
||||
timeClient.update();
|
||||
|
||||
Serial.println(":: POSTsystemSettings ::");
|
||||
|
||||
Serial.print("configured: ");
|
||||
|
|
Loading…
Reference in a new issue