@@ -227,6 +227,10 @@ void setup()
227227 AsyncWiFiManagerParameter custom_mqtt_triggerpath (" mqtt_triggerpath" , " MQTT Data Trigger Path" , NULL , 80 );
228228 AsyncWiFiManagerParameter custom_device_name (" device_name" , " Device Name" , " EPEver2MQTT" , 32 );
229229 AsyncWiFiManagerParameter custom_device_quantity (" device_quantity" , " Device Quantity" , " 1" , 2 );
230+ AsyncWiFiManagerParameter custom_static_ip (" static_ip" , " Static IP (empty for DHCP)" , _settings.data .staticIP , 16 );
231+ AsyncWiFiManagerParameter custom_static_gw (" static_gw" , " Static Gateway (empty for DHCP)" , _settings.data .staticGW , 16 );
232+ AsyncWiFiManagerParameter custom_static_sn (" static_sn" , " Static Subnet (empty for DHCP)" , _settings.data .staticSN , 16 );
233+ AsyncWiFiManagerParameter custom_static_dns (" static_dns" , " Static DNS (empty for DHCP)" , _settings.data .staticDNS , 16 );
230234
231235 wm.addParameter (&custom_mqtt_server);
232236 wm.addParameter (&custom_mqtt_user);
@@ -237,12 +241,24 @@ void setup()
237241 wm.addParameter (&custom_mqtt_triggerpath);
238242 wm.addParameter (&custom_device_name);
239243 wm.addParameter (&custom_device_quantity);
244+ wm.addParameter (&custom_static_ip);
245+ wm.addParameter (&custom_static_gw);
246+ wm.addParameter (&custom_static_sn);
247+ wm.addParameter (&custom_static_dns);
240248
241249 wm.setDebugOutput (false ); // disable wifimanager debug output
242250 wm.setMinimumSignalQuality (25 ); // filter weak wifi signals
243251 wm.setConnectTimeout (10 ); // how long to try to connect for before continuing
244252 wm.setConfigPortalTimeout (300 ); // auto close configportal after n seconds
245253 wm.setSaveConfigCallback (saveConfigCallback);
254+
255+ IPAddress ip, gw, sn, dns;
256+ if (ip.fromString (_settings.data .staticIP ) && gw.fromString (_settings.data .staticGW ) && sn.fromString (_settings.data .staticSN ))
257+ {
258+ dns.fromString (_settings.data .staticDNS );
259+ wm.setSTAStaticIPConfig (ip, gw, sn, dns);
260+ }
261+
246262 bool res = wm.autoConnect (" EPEver2MQTT-AP" );
247263
248264 // save settings if wifi setup is fire up
@@ -257,6 +273,10 @@ void setup()
257273 _settings.data .mqttRefresh = atoi (custom_mqtt_refresh.getValue ());
258274 strncpy (_settings.data .mqttTriggerPath , custom_mqtt_triggerpath.getValue (), 80 );
259275 _settings.data .deviceQuantity = atoi (custom_device_quantity.getValue ()) <= 0 ? 1 : atoi (custom_device_quantity.getValue ());
276+ strncpy (_settings.data .staticIP , custom_static_ip.getValue (), 16 );
277+ strncpy (_settings.data .staticGW , custom_static_gw.getValue (), 16 );
278+ strncpy (_settings.data .staticSN , custom_static_sn.getValue (), 16 );
279+ strncpy (_settings.data .staticDNS , custom_static_dns.getValue (), 16 );
260280
261281 _settings.save ();
262282 ESP .restart ();
@@ -339,7 +359,11 @@ void setup()
339359 strncpy (_settings.data .mqttTopic , request->arg (" post_mqttTopic" ).c_str (), 40 );
340360 _settings.data .mqttRefresh = request->arg (" post_mqttRefresh" ).toInt () < 1 ? 1 : request->arg (" post_mqttRefresh" ).toInt (); // prevent lower numbers
341361 strncpy (_settings.data .deviceName , request->arg (" post_deviceName" ).c_str (), 40 );
342- _settings.data .deviceQuantity = request->arg (" post_deviceQuanttity" ).toInt () <= 0 ? 1 : request->arg (" post_deviceQuanttity" ).toInt ();
362+ strncpy (_settings.data .staticIP , request->arg (" post_staticIP" ).c_str (), 16 );
363+ strncpy (_settings.data .staticGW , request->arg (" post_staticGW" ).c_str (), 16 );
364+ strncpy (_settings.data .staticSN , request->arg (" post_staticSN" ).c_str (), 16 );
365+ strncpy (_settings.data .staticDNS , request->arg (" post_staticDNS" ).c_str (), 16 );
366+ _settings.data .deviceQuantity = request->arg (" post_deviceQuanttity" ).toInt () <= 0 ? 1 : request->arg (" post_deviceQuanttity" ).toInt ();
343367 _settings.data .mqttJson = (request->arg (" post_mqttjson" ) == " true" ) ? true : false ;
344368 strncpy (_settings.data .mqttTriggerPath , request->arg (" post_mqtttrigger" ).c_str (), 80 );
345369 _settings.data .webUIdarkmode = (request->arg (" post_webuicolormode" ) == " true" ) ? true : false ;
0 commit comments