-->
Page 1 of 1

Weird static IP slow to connect on some ESPs problem

PostPosted: Thu Dec 03, 2015 3:00 pm
by torntrousers
I've found that some ESP modules are slower than others to connect to WiFi with a static IP address. When using a static IP some ESPs connect to WiFI in about 200 milliseconds, but others i try take 1060 milliseconds. I've tried quite a few boards now all running the same test sketch - NodeMCU V1 and V3, ESP-07, ESP-12, ESP-12e - but don't see any pattern, just some boards are slow and some are fast. I've also tried going back to the original 1.6.1 Arduino/ESP IDE release and with the latest 2.0.0 code and neither seem to make a difference. The fast ones all connect in about the 200ms and the slow ones are always really close to 1060 ms, maybe 1059 or up to 1065, but all within that sort of range which seems like more than coincidence more like there is some timeout happening or something.

Thats odd isn't it?

What could the difference be? Is it some bug in my sketch, see below, can you try it to see how long for you? Maybe some problem with my Wifi access point? Or ...? Any debugging suggestions?

(This may seem a bit academic but it really makes a difference for a battery powered sensor- eg when sending a sensor reading only takes a few hundred milliseconds then using a fast or slow connecting module could be the difference between the batteries lasting 6 months instead of nearly two years)

Code: Select all#include <ESP8266WiFi.h>
extern "C" {
  #include "user_interface.h"
}

const unsigned long SLEEP_INFTERVAL = 30 * 1000 * 1000; // 30 sec

const char* ssid = "<yourSSID>";
const char* password = "<yourPSWD>";

long setupStartMillis;

void setup() {
  setupStartMillis = millis();

  Serial.begin(115200);
  Serial.println();
  Serial.print("Setup start millis: "); Serial.println(setupStartMillis);

  Serial.print("Connecting to: "); Serial.println(ssid);
//  if (strcmp (WiFi.SSID(),ssid) != 0) {
  if (strcmp (WiFi.SSID().c_str(),ssid) != 0) {
     WiFi.begin(ssid, password);
  } else {
    WiFi.begin();
  }

  WiFi.config(IPAddress(192,168,1,119), IPAddress(192,168,1,254), IPAddress(255,255,255,0));

  int timeout = millis()+5000;
  while ((WiFi.status() != WL_CONNECTED) && (timeout > millis())) {
    delay(1);
  }

  if ((WiFi.status() != WL_CONNECTED)) {
     Serial.println("WiFi FAILed to connect");
  } else {
     Serial.print("WiFi connected in: "); Serial.print(millis()-setupStartMillis);
     Serial.print(", IP: "); Serial.println(WiFi.localIP());
  }

  Serial.print("Deep sleep for ");
  Serial.print(SLEEP_INFTERVAL / 1000000);
  Serial.println(" secs...");
  ESP.deepSleep(SLEEP_INFTERVAL);
//  system_deep_sleep_set_option(0);
//  system_deep_sleep(SLEEP_INFTERVAL);
//  delay(1000); // needed as sleep seems to tak a little while to happen
}

void loop() {
   // should never get here 
}

Re: Weird static IP slow to connect on some ESPs problem

PostPosted: Sat Dec 05, 2015 5:34 am
by torntrousers
It turns out that this is something to do with SPIFFS. I haven't quite pinned down the exact details but most ESP modules seem to connect fast when using a static IP if the sketch is uploaded with "Generic ESP8266 module" option and selecting a Flash size of "512K (no SPIFFS)".