11#include " Configuration.h"
22
33unsigned long startMillis = 0 ;
4- unsigned long startMillis_sunspec = 0 ;
54unsigned long currentMillis;
5+ // for time synchronization
6+ time_t now;
7+ tm timeinfo;
68
79// ============================================================================
810// CONFIGURATION VARIABLES (stored in Preferences)
911// ============================================================================
1012
1113// Data source and server settings
1214char input_type[40 ];
15+ char ntp_server[40 ] = " de.pool.ntp.org" ;
16+ char timezone[64 ] = " CET-1CEST,M3.5.0/2,M10.5.0/3" ; // Central European Time
1317char mqtt_server[160 ];
1418char mqtt_port[6 ] = " 1883" ;
1519char mqtt_topic[90 ] = " tele/meter/SENSOR" ;
@@ -140,6 +144,8 @@ void WifiManagerSetup() {
140144 preferences.begin (" e2s_config" , false );
141145 strcpy (input_type, preferences.getString (" input_type" , input_type).c_str ());
142146 strcpy (mqtt_server, preferences.getString (" mqtt_server" , mqtt_server).c_str ());
147+ strcpy (ntp_server, preferences.getString (" ntp_server" , ntp_server).c_str ());
148+ strcpy (timezone, preferences.getString (" timezone" , timezone).c_str ());
143149 strcpy (query_period, preferences.getString (" query_period" , query_period).c_str ());
144150 strcpy (led_gpio, preferences.getString (" led_gpio" , led_gpio).c_str ());
145151 strcpy (led_gpio_i, preferences.getString (" led_gpio_i" , led_gpio_i).c_str ());
@@ -164,6 +170,8 @@ void WifiManagerSetup() {
164170 WiFiManagerParameter custom_input_type (" type" , " <b>Data source</b><br><code>MQTT</code> for MQTT<br><code>HTTP</code> for generic HTTP<br><code>SMA</code> for SMA EM/HM multicast<br><code>SHRDZM</code> for SHRDZM UDP data<br><code>SUNSPEC</code> for Modbus TCP SUNSPEC data" , input_type, 40 );
165171 WiFiManagerParameter custom_mqtt_server (" server" , " <b>Server</b><br>MQTT Server IP, query url for generic HTTP or Modbus TCP server IP for SUNSPEC" , mqtt_server, 160 );
166172 WiFiManagerParameter custom_mqtt_port (" port" , " <b>Port</b><br> for MQTT or Modbus TCP (SUNSPEC)" , mqtt_port, 6 );
173+ WiFiManagerParameter param_ntp_server (" ntp_server" , " NTP server <span title=\" for time synchronization\" style=\" cursor: help;\" aria-label=\" Help\" tabindex=\" 0\" >(?)</span>" , ntp_server, 40 );
174+ WiFiManagerParameter param_timezone (" timezone" , " Timezone <span title=\" e.g. UTC0, UTC+1, UTC-3, UTC+1CET-1CEST,M3.5.0/02:00:00,M10.5.0/03:00:00\" style=\" cursor: help;\" aria-label=\" Help\" tabindex=\" 0\" >(?)</span>" , timezone, 64 );
167175 WiFiManagerParameter custom_query_period (" query_period" , " <b>Query period</b><br>for generic HTTP and SUNSPEC, in milliseconds" , query_period, 10 );
168176 WiFiManagerParameter custom_led_gpio (" led_gpio" , " <b>GPIO</b><br>of internal LED" , led_gpio, 3 );
169177 WiFiManagerParameter custom_led_gpio_i (" led_gpio_i" , " <b>GPIO is inverted</b><br><code>true</code> or <code>false</code>" , led_gpio_i, 6 );
@@ -197,6 +205,8 @@ void WifiManagerSetup() {
197205 wifiManager.addParameter (&custom_section1);
198206 wifiManager.addParameter (&custom_input_type);
199207 wifiManager.addParameter (&custom_mqtt_server);
208+ wifiManager.addParameter (¶m_ntp_server);
209+ wifiManager.addParameter (¶m_timezone);
200210 wifiManager.addParameter (&custom_query_period);
201211 wifiManager.addParameter (&custom_led_gpio);
202212 wifiManager.addParameter (&custom_led_gpio_i);
@@ -233,6 +243,8 @@ void WifiManagerSetup() {
233243 strcpy (input_type, custom_input_type.getValue ());
234244 strcpy (mqtt_server, custom_mqtt_server.getValue ());
235245 strcpy (mqtt_port, custom_mqtt_port.getValue ());
246+ strcpy (ntp_server, param_ntp_server.getValue ());
247+ strcpy (timezone, param_timezone.getValue ());
236248 strcpy (query_period, custom_query_period.getValue ());
237249 strcpy (led_gpio, custom_led_gpio.getValue ());
238250 strcpy (led_gpio_i, custom_led_gpio_i.getValue ());
@@ -256,6 +268,8 @@ void WifiManagerSetup() {
256268 DEBUG_SERIAL.println (" \t input_type : " + String (input_type));
257269 DEBUG_SERIAL.println (" \t mqtt_server : " + String (mqtt_server));
258270 DEBUG_SERIAL.println (" \t mqtt_port : " + String (mqtt_port));
271+ DEBUG_SERIAL.println (" \t ntp_server: " + String (ntp_server));
272+ DEBUG_SERIAL.println (" \t timezone: " + String (timezone));
259273 DEBUG_SERIAL.println (" \t query_period : " + String (query_period));
260274 DEBUG_SERIAL.println (" \t led_gpio : " + String (led_gpio));
261275 DEBUG_SERIAL.println (" \t led_gpio_i : " + String (led_gpio_i));
@@ -310,6 +324,8 @@ void WifiManagerSetup() {
310324 preferences.putString (" input_type" , input_type);
311325 preferences.putString (" mqtt_server" , mqtt_server);
312326 preferences.putString (" mqtt_port" , mqtt_port);
327+ preferences.putString (" ntp_server" , ntp_server);
328+ preferences.putString (" timezone" , timezone);
313329 preferences.putString (" query_period" , query_period);
314330 preferences.putString (" led_gpio" , led_gpio);
315331 preferences.putString (" led_gpio_i" , led_gpio_i);
0 commit comments