Time string and server configurabled via wifiman
This commit is contained in:
parent
3083b7a383
commit
823884c50c
20
src/main.cpp
20
src/main.cpp
|
@ -50,8 +50,6 @@
|
||||||
#include <display.h>
|
#include <display.h>
|
||||||
|
|
||||||
char VERSION[6] = "v0.8c";
|
char VERSION[6] = "v0.8c";
|
||||||
#define TimeZone "CET-1CEST,M3.5.0,M10.5.0/3"
|
|
||||||
#define TimeServ "pool.ntp.org"
|
|
||||||
|
|
||||||
//Defaults
|
//Defaults
|
||||||
char mqtt_server[15] = "";
|
char mqtt_server[15] = "";
|
||||||
|
@ -64,6 +62,8 @@ char address_inverter[6] = "";
|
||||||
char address_battery[6] = "";
|
char address_battery[6] = "";
|
||||||
char address_outside_temperature[6] = "";
|
char address_outside_temperature[6] = "";
|
||||||
char display_lang[6] = "";
|
char display_lang[6] = "";
|
||||||
|
char time_zone[40] = "CET-1CEST,M3.5.0,M10.5.0/3"; // Europe/Berlin
|
||||||
|
char time_server[20] = "pool.ntp.org";
|
||||||
long unsigned int DISPLAY_REFRESH_INTERVAL;
|
long unsigned int DISPLAY_REFRESH_INTERVAL;
|
||||||
long unsigned int DISPLAY_SCREEN_INTERVAL;
|
long unsigned int DISPLAY_SCREEN_INTERVAL;
|
||||||
|
|
||||||
|
@ -329,6 +329,8 @@ void setup() {
|
||||||
strcpy(address_battery, json["address_battery"]);
|
strcpy(address_battery, json["address_battery"]);
|
||||||
strcpy(address_outside_temperature, json["address_outside_temperature"]);
|
strcpy(address_outside_temperature, json["address_outside_temperature"]);
|
||||||
strcpy(display_lang, json["display_language"]);
|
strcpy(display_lang, json["display_language"]);
|
||||||
|
strcpy(time_zone, json["time_zone"]);
|
||||||
|
strcpy(time_server, json["time_server"]);
|
||||||
} else {
|
} else {
|
||||||
Serial.println("failed to load json config");
|
Serial.println("failed to load json config");
|
||||||
}
|
}
|
||||||
|
@ -362,6 +364,8 @@ void setup() {
|
||||||
WiFiManagerParameter custom_address_battery("address_battery", "Address of can battery", address_battery, 6);
|
WiFiManagerParameter custom_address_battery("address_battery", "Address of can battery", address_battery, 6);
|
||||||
WiFiManagerParameter custom_address_outside_temperature("address_outside_temperature", "Address of outside temperature", address_outside_temperature, 6);
|
WiFiManagerParameter custom_address_outside_temperature("address_outside_temperature", "Address of outside temperature", address_outside_temperature, 6);
|
||||||
WiFiManagerParameter custom_display_lang("display_lang", "Display language en, de", display_lang, 6);
|
WiFiManagerParameter custom_display_lang("display_lang", "Display language en, de", display_lang, 6);
|
||||||
|
WiFiManagerParameter custom_time_zone("time_zone", "Set timezone string", time_zone, 40);
|
||||||
|
WiFiManagerParameter custom_time_server("time_server", "Set time server", time_server, 20);
|
||||||
WiFiManager wm;
|
WiFiManager wm;
|
||||||
|
|
||||||
wm.setSaveConfigCallback(saveConfigCallback);
|
wm.setSaveConfigCallback(saveConfigCallback);
|
||||||
|
@ -375,6 +379,8 @@ void setup() {
|
||||||
wm.addParameter(&custom_address_battery);
|
wm.addParameter(&custom_address_battery);
|
||||||
wm.addParameter(&custom_address_outside_temperature);
|
wm.addParameter(&custom_address_outside_temperature);
|
||||||
wm.addParameter(&custom_display_lang);
|
wm.addParameter(&custom_display_lang);
|
||||||
|
wm.addParameter(&custom_time_zone);
|
||||||
|
wm.addParameter(&custom_time_server);
|
||||||
|
|
||||||
//Start wifi manager configuration if BUTTON_SETUP is pressed on start-up
|
//Start wifi manager configuration if BUTTON_SETUP is pressed on start-up
|
||||||
currentButtonSetupState = digitalRead(BUTTON_SETUP);
|
currentButtonSetupState = digitalRead(BUTTON_SETUP);
|
||||||
|
@ -401,6 +407,8 @@ void setup() {
|
||||||
strcpy(address_battery, custom_address_battery.getValue());
|
strcpy(address_battery, custom_address_battery.getValue());
|
||||||
strcpy(address_outside_temperature, custom_address_outside_temperature.getValue());
|
strcpy(address_outside_temperature, custom_address_outside_temperature.getValue());
|
||||||
strcpy(display_lang, custom_display_lang.getValue());
|
strcpy(display_lang, custom_display_lang.getValue());
|
||||||
|
strcpy(time_zone, custom_time_zone.getValue());
|
||||||
|
strcpy(time_server, custom_time_server.getValue());
|
||||||
|
|
||||||
DISPLAY_REFRESH_INTERVAL = strtol(disp_refresh_interval, NULL, 10);
|
DISPLAY_REFRESH_INTERVAL = strtol(disp_refresh_interval, NULL, 10);
|
||||||
DISPLAY_SCREEN_INTERVAL = strtol(disp_screen_interval, NULL, 10);
|
DISPLAY_SCREEN_INTERVAL = strtol(disp_screen_interval, NULL, 10);
|
||||||
|
@ -438,6 +446,8 @@ void setup() {
|
||||||
json["address_battery"] = address_battery;
|
json["address_battery"] = address_battery;
|
||||||
json["address_outside_temperature"] = address_outside_temperature;
|
json["address_outside_temperature"] = address_outside_temperature;
|
||||||
json["display_language"] = display_lang;
|
json["display_language"] = display_lang;
|
||||||
|
json["time_zone"] = time_zone;
|
||||||
|
json["time_server"] = time_server;
|
||||||
|
|
||||||
File configFile = Flash.open("/config.json", "w");
|
File configFile = Flash.open("/config.json", "w");
|
||||||
if (!configFile) {
|
if (!configFile) {
|
||||||
|
@ -457,12 +467,12 @@ void setup() {
|
||||||
|
|
||||||
//NTP setup
|
//NTP setup
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
configTime(0, 0, TimeServ);
|
configTime(0, 0, time_server);
|
||||||
setenv("TZ", TimeZone, 1);
|
setenv("TZ", time_zone, 1);
|
||||||
tzset();
|
tzset();
|
||||||
#endif
|
#endif
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
configTime(TimeZone, TimeServ);
|
configTime(time_zone, time_server);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue