So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Rudy Scherer
#81971 Hello,

I have made a controller to irigate my garden (ESP8266 NodeMcu + flowswitch). It works perfectly. I use the ESP in server mode and i connect to it with just a navigator, through it's IP address. And that's my question.

In every example, we see that the authors uses the serial connection at initialization time to retrieve the IP address of the board to be able to access it. Right. I can do this also. Typically :
Code: Select all    Serial.println("WiFi connected.");
    Serial.println("IP address: ");

BUT ... what happend if my board fall out of current and restart later ? Nothing garantee that it will get the same IP address from the access point.

As it works alone in my garden, how can I connect to it if it receive another IP address ? That's my question.

I try to force a fixed IP address :
- First, i connect and retrieve the subnet mask, the gateway and IP.
- Then i impose ".63" instead of the ".69" that it originally receive
- I disconnect and try to reconnect with the following code :
Code: Select all    // Try to connect with fixed IP Address
    WiFi.hostname(deviceName);              // DHCP Hostname (useful for finding device for static lease)
    ip[3] = 63;                             // Update IP to fixed IP
    WiFi.config(ip, subnet, gateway, dns);
    WiFi.begin(ssid, password);
    WiFi.mode(WIFI_STA); //WiFi mode station (connect to wifi router only
    Serial.print("Connecting with ip: ");
    while (WiFi.status() != WL_CONNECTED) {

The connection succeed but not with the asked IP address. :mrgreen:
I tried to impose a device name but it doesn't either work. :mrgreen: :mrgreen:
Note: I also tried to place the WiFi.config(ip, subnet, gateway, dns) after the WiFi.begin. Doesn't work.

Any idea ? Or any other solution to ensure that you can find it later ?

Best regards,

User avatar
By QuickFix
#81977 You could include a tiny I2C display that displays the status of your device and its IP address: this option will need 2 GPIO's and some extra soldering.
But it would be easier if you just let it get a (the same) "Static" IP over DHCP from the router every time it connects: on most routers you can assign a specific IP to a MAC address in a reserved list.
You do not have the required permissions to view the files attached to this post.
User avatar
By Rudy Scherer
#81995 Thanks for your post.
But I found the problem !

With ESP8266, the DNS can't be specified. So, this work for me :
- Firstly : WiFi.begin(ssid, password) - Before the WiFi.config !!!
- Secondly : WiFi.config(ip, subnet, gateway) - Without the DNS parameter !!!

So I don't need any LCD screen. I can ensure that the IP address will be respected.

Thank you everybody,