khoih-prog / ESP_WiFiManager

This is an ESP32 / ESP8266 WiFi Connection Manager with fallback web configuration portal. Use this library for configuring ESP32 (including ESP32-S2 and ESP32-C3), ESP8266 modules' WiFi, etc. Credentials at runtime. You can also specify static DNS servers, personalized HostName, fixed or random AP WiFi channel. With examples supporting ArduinoJson
MIT License
371 stars 97 forks source link

Static Ip when connected to a DHCP enabled network [Question] #59

Closed yiancar closed 3 years ago

yiancar commented 3 years ago

Is your feature request related to a problem? Please describe.

Hello again! This is more of a question regarding the intention behind the StaticIP field in the Config Portal. I am using the ESP32_FSWebServer_DRD example which does 99% of what I want it to do. As a test I tried the following: set a StaticIP in the Config Portal and connect to a network that has DHCP. As this device was connected using DHCP to this network before the router is autoassigning the previous IP.

As a result when the ESP connects to the network it uses the DHCP IP it was given and NOT the StaticIP that was set in the Config Portal.

Is the intention that if one provides a StaticIP and DHCP is not available on that network, the StaticIP will be used?

In a real world scenario I know that the best practice is to use a mac lookup table on the DHCP side to always assign a constant IP.

Cheers, Yiangos

khoih-prog commented 3 years ago

Check if you set in the code

#define USE_DHCP_IP     false

It's a little bit complex here in the example. Just test to see which setting is OK, then set-and-forget.

// Use USE_DHCP_IP == true for dynamic DHCP IP, false to use static IP which you have to change accordingly to your network
#if (defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP)
  // Force DHCP to be true
  #if defined(USE_DHCP_IP)
    #undef USE_DHCP_IP
  #endif
  #define USE_DHCP_IP     true
#else
  // You can select DHCP or Static IP here
  #define USE_DHCP_IP     true
  //#define USE_DHCP_IP     false
#endif

Regards,

yiancar commented 3 years ago

Hello! It looks like

#define USE_STATIC_IP_CONFIG_IN_CP      true 
#define USE_DHCP_IP                     false 

Does what I want. So I can understand better: USE_STATIC_IP_CONFIG_IN_CP allows the StaticIP field to exist USE_DHCP_IP when true prioratizes DHCP?

khoih-prog commented 3 years ago

Yes, that's it. I almost forget all the details.

yiancar commented 3 years ago

Cheers!