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)
#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
}