Skip to content

After serial programming, when given static config WiFi.config() still requests DHCP address #4656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andrewradke opened this issue Apr 20, 2018 · 4 comments
Assignees
Milestone

Comments

@andrewradke
Copy link

Platform

  • Hardware: ESP-12|ESP-07
  • Core Version: 2.4.1
  • Development Env: Arduino IDE 1.8.5
  • Operating System: MacOS

Settings in IDE

  • Module: Generic ESP8266 Module
  • Flash Mode: dio
  • Flash Size: 1MB
  • lwip Variant: v2 Lower Memory
  • Reset Method: nodemcu
  • Flash Frequency: 40Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: any

Problem Description

When programming the ESP8266 over a serial link it will request an IP address via DHCP even if successfully given a static IP address with WiFi.config.

It will replace the static IP address with the DHCP supplied address when it receives the DHCP Offer packet. It responds to the static one before between the time of setting the static address and receiving the DHCP Offer. Once the DHCP Offer has been received and the address has been changed to that it is possible to call WiFi.config again and change the IP back again. It will continue to periodically request or renew the DHCP address after this but it appears not to make use of it.

This behaviour continues after a reset or reboot but removal of power and restarting the ESP8266 corrects the behaviour.

Below is a packet capture of a request following serial programming and immediately following WiFi.config(local_ip, gateway, subnet, dns1, dns2); Between the first and third packet it will respond to the static local_ip given.

    1 0.000000000      0.0.0.0 → 255.255.255.255 DHCP 350 DHCP Discover - Transaction ID 0x48ad2bd3
    2 0.000513333 192.168.26.30 → 192.168.26.164 ICMP 62 Echo (ping) request  id=0xa8fa, seq=0/0, ttl=64
    3 1.001605162 192.168.26.30 → 192.168.26.164 DHCP 342 DHCP Offer    - Transaction ID 0x48ad2bd3
    4 1.007302656      0.0.0.0 → 255.255.255.255 DHCP 350 DHCP Request  - Transaction ID 0x48ad2bd3
    5 1.007925333 192.168.26.30 → 192.168.26.164 DHCP 342 DHCP ACK      - Transaction ID 0x48ad2bd3

MCVE Sketch

The following is extracted from the full program here: https://github.com/andrewradke/ESP8266-Homie-sensors

#include <ESP8266WiFi.h>

bool use_staticip = true;
IPAddress local_ip(192, 168, 26, 58);
IPAddress dns1(192, 168, 26, 30);
IPAddress dns2(192, 168, 26, 20);
IPAddress subnet(255, 255, 255, 0);
IPAddress gateway(192, 168, 26, 1);
String ssid  = "";
String psk   = "";

void setup() {
  Serial.begin(74880);        // Open serial monitor at SERIALSPEED baud to see results.
  delay(200);                 // Give the serial port time to setup

  WiFi.mode(WIFI_STA);

  ssid = WiFi.SSID();
  psk  = WiFi.psk();

  if (use_staticip) {
    bool configstatus = WiFi.config(local_ip, gateway, subnet, dns1, dns2);
      Serial.print("IP config ");
    if (configstatus) {
      Serial.print("succeeded");
    } else {
      Serial.print("succeeded");
    }
  }
}

void loop() {

}
@d-a-v d-a-v self-assigned this Apr 20, 2018
@d-a-v
Copy link
Collaborator

d-a-v commented Apr 20, 2018

Can you please try this lwip2 update and report back ? comment

@electrical-pro
Copy link

My ESP8266 uses static IP, but I've noticed that a couple of times it started using DHCP IP address again after some time (10-20 hours) without any reboots.
It happens not often, and it hard to reproduce. Don't know if it is related.
P.S. I use 2.4.0 and lwip2

@d-a-v
Copy link
Collaborator

d-a-v commented Apr 21, 2018

It is indeed. Please try the above fix.

@TD-er
Copy link
Contributor

TD-er commented May 15, 2018

In ESPeasy I made a work-around for this, to be able to keep using the (a bit older) PlatformIO version of the core library:

https://github.com/letscontrolit/ESPEasy/blob/648353b21648b00571410296ff18d1ff232f8d9e/src/ESPEasyWiFiEvent.h#L1-L26

@d-a-v d-a-v added this to the 2.4.2 milestone May 31, 2018
@devyte devyte closed this as completed Aug 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants