tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.45k stars 1.94k forks source link

Adde methods to se if static IP addresses were configured, and what those addresses are #1720

Open jonasbjurel opened 3 months ago

jonasbjurel commented 3 months ago

To be able to find out if the network with static addresses or with DHCP following methods are proposed:

//check if static network configuration is set
bool          isStaticIp(void);

//provides static host ip address provided method isStaticIp() returns true
void          getStaticIp(IPAddress* staticIp);

//provides static gateway ip address provided method isStaticIp() returns true
void          getStaticGw(IPAddress* staticGw);

//provides static network mask provided method isStaticIp() returns true
void          getStaticSn(IPAddress* staticSn);

//provides static DNS ip address provided method isStaticIp() returns true
void          getStaticDns(IPAddress* staticDns);
namix71 commented 1 month ago

Do you have any plans to update it to a product that supports static IP settings?

tablatronix commented 1 month ago

This is all stuff you can do in code already

jonasbjurel commented 1 month ago

This is all stuff you can do in code already

Could you just give a hint on how? For instance understand if the addresses where provided as static addresses in the wifi-manager, or if it was provided by the DHCP server?

jonasbjurel commented 1 month ago

A small codesnip: if (networkConfig.staticIp = wifiManager.isStaticIp()) { wifiManager.getStaticIp(&networkConfig.ipAddr); wifiManager.getStaticSn(&networkConfig.ipMask); wifiManager.getStaticGw(&networkConfig.gatewayIpAddr); wifiManager.getStaticDns(&networkConfig.dnsIpAddr); } else { networkConfig.ipAddr = WiFi.localIP(); networkConfig.ipMask = WiFi.subnetMask(); networkConfig.gatewayIpAddr = WiFi.gatewayIP(); networkConfig.dnsIpAddr = WiFi.dnsIP(); }

tablatronix commented 1 month ago

Static configs are not stored in flash, so user code has to store and recall them. So no need for wm specific wrappers

jonasbjurel commented 1 month ago

Static configs are not stored in flash, so user code has to store and recall them. So no need for wm specific wrappers

That is exactly why I want to know where to fetch the config, I.e. using: bool isStaticIp(void); I guess my small additions does not break anything, and I got my code working with these additions, which I failed to without them. BR/J

tablatronix commented 1 month ago

I am assuming this only works right after you save wifi ?

jonasbjurel commented 4 weeks ago

I am assuming this only works right after you save wifi ?

Correct, after having saved WiFi, I use these method to check if a static address was configured, and if so I fetch the static addresses using these methods, if not static I fetch the DHCP assigned addresses using the normal WiFi methods. BR/Jonas