@@ -11,6 +11,7 @@ tm timeinfo;
1111// ============================================================================
1212
1313// Data source and server settings
14+ char reset_password[33 ] = " admin-changeMe" ; // default reset password
1415char input_type[40 ];
1516char ntp_server[40 ] = " de.pool.ntp.org" ;
1617char timezone[64 ] = " CET-1CEST,M3.5.0/2,M10.5.0/3" ; // Central European Time
@@ -143,6 +144,7 @@ void WifiManagerSetup() {
143144 sprintf (shelly_mac, " %02X%02X%02X%02X%02X%02X" , mac[0 ], mac[1 ], mac[2 ], mac[3 ], mac[4 ], mac[5 ]);
144145
145146 preferences.begin (" e2s_config" , false );
147+ strcpy (reset_password, preferences.getString (" reset_password" , reset_password).c_str ());
146148 strcpy (input_type, preferences.getString (" input_type" , input_type).c_str ());
147149 strcpy (mqtt_server, preferences.getString (" mqtt_server" , mqtt_server).c_str ());
148150 strcpy (ntp_server, preferences.getString (" ntp_server" , ntp_server).c_str ());
@@ -167,9 +169,15 @@ void WifiManagerSetup() {
167169 strcpy (shelly_port, preferences.getString (" shelly_port" , shelly_port).c_str ());
168170 strcpy (force_pwr_decimals, preferences.getString (" force_pwr_decimals" , force_pwr_decimals).c_str ());
169171 strcpy (sma_id, preferences.getString (" sma_id" , sma_id).c_str ());
170-
171- WiFiManagerParameter custom_section1 (" <h3>General settings</h3>" );
172- 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 );
172+
173+ const char *show_pwd_str = " <input type=\" checkbox\" onclick=\" t('%s')\" > <label>Show Password</label><br/>" ;
174+
175+ WiFiManagerParameter custom_section1 (" <h3>General settings</h3><script>function t(s) { var x = document.getElementById(s); x.type === \" password\" ? x.type = \" text\" : x.type = \" password\" ; }</script>" );
176+ WiFiManagerParameter param_reset_password (" reset_password" , " Reset Password <span title=\" For resetting the WiFi configuration and putting the device in AP / config mode\" style=\" cursor: help;\" aria-label=\" Help\" tabindex=\" 0\" >(?)</span>" , reset_password, 32 , " type='password'" );
177+ char buf_rst_pwd_show_pwd[150 ];
178+ sprintf (buf_rst_pwd_show_pwd, show_pwd_str, " reset_password" );
179+ WiFiManagerParameter param_reset_password_show_password (buf_rst_pwd_show_pwd);
180+ WiFiManagerParameter custom_input_type (" type" , " <hr><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 );
173181 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 );
174182 WiFiManagerParameter custom_mqtt_port (" port" , " <b>Port</b><br> for MQTT or Modbus TCP (SUNSPEC)" , mqtt_port, 6 );
175183 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 );
@@ -184,8 +192,11 @@ void WifiManagerSetup() {
184192 WiFiManagerParameter custom_sma_id (" sma_id" , " <b>SMA serial number</b><br>optional serial number if you have more than one SMA EM/HM in your network" , sma_id, 16 );
185193 WiFiManagerParameter custom_section2 (" <hr><h3>MQTT options</h3>" );
186194 WiFiManagerParameter custom_mqtt_topic (" topic" , " <b>MQTT Topic</b>" , mqtt_topic, 90 );
187- WiFiManagerParameter custom_mqtt_user (" user" , " <b>MQTT user</b><br>optional" , mqtt_user, 40 );
188- WiFiManagerParameter custom_mqtt_passwd (" passwd" , " <b>MQTT password</b><br>optional" , mqtt_passwd, 40 );
195+ WiFiManagerParameter custom_mqtt_user (" user" , " <b>MQTT user</b> (optional)" , mqtt_user, 40 );
196+ WiFiManagerParameter custom_mqtt_passwd (" passwd" , " <b>MQTT password</b> (optional)" , mqtt_passwd, 40 , " type='password'" );
197+ char buf_mqtt_pwd_show_pwd[150 ];
198+ sprintf (buf_mqtt_pwd_show_pwd, show_pwd_str, " passwd" );
199+ WiFiManagerParameter param_mqtt_passwd_show_password (buf_mqtt_pwd_show_pwd);
189200 WiFiManagerParameter custom_section3 (" <hr><h3>Modbus TCP options</h3>" );
190201 WiFiManagerParameter custom_modbus_dev (" modbus_dev" , " <b>Modbus device ID</b><br><code>71</code> for Kostal SEM" , modbus_dev, 60 );
191202 WiFiManagerParameter custom_section4 (" <hr><h3>JSON paths for MQTT and generic HTTP</h3>" );
@@ -206,6 +217,8 @@ void WifiManagerSetup() {
206217
207218 // add all your parameters here
208219 wifiManager.addParameter (&custom_section1);
220+ wifiManager.addParameter (¶m_reset_password);
221+ wifiManager.addParameter (¶m_reset_password_show_password);
209222 wifiManager.addParameter (&custom_input_type);
210223 wifiManager.addParameter (&custom_mqtt_server);
211224 wifiManager.addParameter (¶m_ntp_server);
@@ -223,6 +236,7 @@ void WifiManagerSetup() {
223236 wifiManager.addParameter (&custom_mqtt_topic);
224237 wifiManager.addParameter (&custom_mqtt_user);
225238 wifiManager.addParameter (&custom_mqtt_passwd);
239+ wifiManager.addParameter (¶m_mqtt_passwd_show_password);
226240 wifiManager.addParameter (&custom_section3);
227241 wifiManager.addParameter (&custom_modbus_dev);
228242 wifiManager.addParameter (&custom_section4);
@@ -244,6 +258,7 @@ void WifiManagerSetup() {
244258 DEBUG_SERIAL.println (" connected" );
245259
246260 // read updated parameters
261+ strcpy (reset_password, param_reset_password.getValue ());
247262 strcpy (input_type, custom_input_type.getValue ());
248263 strcpy (mqtt_server, custom_mqtt_server.getValue ());
249264 strcpy (mqtt_port, custom_mqtt_port.getValue ());
@@ -270,6 +285,7 @@ void WifiManagerSetup() {
270285 strcpy (sma_id, custom_sma_id.getValue ());
271286
272287 DEBUG_SERIAL.println (" The values in the preferences are: " );
288+ DEBUG_SERIAL.println (" \t reset_password: ********" );
273289 DEBUG_SERIAL.println (" \t input_type : " + String (input_type));
274290 DEBUG_SERIAL.println (" \t mqtt_server : " + String (mqtt_server));
275291 DEBUG_SERIAL.println (" \t mqtt_port : " + String (mqtt_port));
@@ -282,7 +298,7 @@ void WifiManagerSetup() {
282298 DEBUG_SERIAL.println (" \t shelly_mac : " + String (shelly_mac));
283299 DEBUG_SERIAL.println (" \t mqtt_topic : " + String (mqtt_topic));
284300 DEBUG_SERIAL.println (" \t mqtt_user : " + String (mqtt_user));
285- DEBUG_SERIAL.println (" \t mqtt_passwd : " + String (mqtt_passwd) );
301+ DEBUG_SERIAL.println (" \t mqtt_passwd : ******** " );
286302 DEBUG_SERIAL.println (" \t modbus_dev : " + String (modbus_dev));
287303 DEBUG_SERIAL.println (" \t power_path : " + String (power_path));
288304 DEBUG_SERIAL.println (" \t pwr_export_path : " + String (pwr_export_path));
@@ -306,8 +322,7 @@ void WifiManagerSetup() {
306322 } else if (strcmp (input_type, " SUNSPEC" ) == 0 ) {
307323 dataSUNSPEC = true ;
308324 DEBUG_SERIAL.println (" Enabling SUNSPEC data input" );
309- }
310- else {
325+ } else {
311326 dataMQTT = true ;
312327 DEBUG_SERIAL.println (" Enabling MQTT data input" );
313328 }
@@ -326,6 +341,7 @@ void WifiManagerSetup() {
326341
327342 if (shouldSaveConfig) {
328343 DEBUG_SERIAL.println (" saving config" );
344+ preferences.putString (" reset_password" , reset_password);
329345 preferences.putString (" input_type" , input_type);
330346 preferences.putString (" mqtt_server" , mqtt_server);
331347 preferences.putString (" mqtt_port" , mqtt_port);
0 commit comments