Skip to content

WiFi only works once after erasing flash #3100

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
jcollie opened this issue Mar 31, 2017 · 9 comments
Closed

WiFi only works once after erasing flash #3100

jcollie opened this issue Mar 31, 2017 · 9 comments

Comments

@jcollie
Copy link

jcollie commented Mar 31, 2017

Basic Infos

WiFi only works once after erasing flash using esptool and then uploading a sketch.

Hardware

Hardware: Adafruit Huzzah Feather
Core Version: git from today

Description

If I use esptool to erase the flash and then use the Arduino IDE to upload a sketch, WiFi connects and works fine. If I reset the ESP8266 or cycle the power, WiFi never works properly again. The WiFi can authenticate and get a DHCP address but TCP connections or DNS lookups don't work. Using a Ubiquity AP-Pro as my WiFi access point. The ESP8266 is the only WiFi client that I've had problems with this AP.

Settings in IDE

Module: Adafruit HUZZAH ESP8266
Flash Size: 4MB
CPU Frequency: 80Mhz
Flash Mode: QIO
Flash Frequency: 80Mhz
Upload Using: SERIAL
Reset Method: nodemcu

Sketch

// Adafruit IO Temperature & Humidity Example
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-temperature-and-humidity
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016-2017 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.

/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ Example Starts Here *******************************/
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Adafruit_SSD1306.h>

// oled display
Adafruit_SSD1306 oled = Adafruit_SSD1306();

// pin connected to DH22 data line
#define DATA_PIN 2

// create DHT22 instance
DHT_Unified dht(DATA_PIN, DHT22);

// set up the 'temperature' and 'humidity' feeds

AdafruitIO_WiFi *io;
AdafruitIO_Feed *temperature;
AdafruitIO_Feed *humidity;

void setup() {
  // start the serial connection
  Serial.begin(115200);

  // wait for serial monitor to open
  while(! Serial);
  
  Serial.println("Starting");
  
  delay(5000);
  io = new AdafruitIO_WiFi(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
  temperature = io->feed("temperature");
  humidity = io->feed("humidity");
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  oled.display();



  // initialize dht22
  dht.begin();

  // connect to io.adafruit.com
  Serial.println("Connecting to Adafruit IO");
  io->connect();

  // wait for a connection
  while(io->status() < AIO_CONNECTED) {
    Serial.println(io->statusText());

    delay(500);
  }

  // we are connected
  Serial.println();
  Serial.println(io->statusText());

  // text display tests
  oled.setTextSize(1);
  oled.setTextColor(WHITE);
}

void loop() {

  // io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
  io->run();

  sensors_event_t event;
  dht.temperature().getEvent(&event);

  float celsius = event.temperature;
  float fahrenheit = (celsius * 1.8) + 32;

  Serial.print("celsius: ");
  Serial.print(celsius);
  Serial.println("C");

  Serial.print("fahrenheit: ");
  Serial.print(fahrenheit);
  Serial.println("F");

  // save fahrenheit (or celsius) to Adafruit IO
  temperature->save(fahrenheit);

  dht.humidity().getEvent(&event);
   
  Serial.print("humidity: ");
  Serial.print(event.relative_humidity);
  Serial.println("%");

  // save humidity to Adafruit IO
  humidity->save(event.relative_humidity);

  // print it to the OLED
  oled.clearDisplay();
  oled.setCursor(0,0);
  oled.print("SSID: "); oled.println(WIFI_SSID);
  oled.print("IP: "); oled.println(WiFi.localIP());
  oled.print("Temp: "); oled.print(fahrenheit,0); oled.print(" *F ");
  oled.print("Hum: "); oled.print(event.relative_humidity,0); oled.println(" %");
  oled.print("IO Status: ");
  aio_status_t aio_status = io->status();
  Serial.print("Status: "); Serial.println(aio_status);
  switch (aio_status) {
     case AIO_IDLE:  oled.println("IDLE"); break;
     case AIO_DISCONNECTED:
     case AIO_NET_DISCONNECTED:  oled.println("DISCONNECT"); break;
     case AIO_NET_CONNECTED:
     case AIO_CONNECTED_INSECURE:
     case AIO_CONNECTED: oled.println("CONNECTED"); break;
  }
  oled.display();

  // wait 5 seconds (5000 milliseconds == 5 seconds)
  delay(2000);
}

Debug Messages

Starting
Connecting to Adafruit IO
Network disconnected.
Network disconnected.
Network disconnected.
Network disconnected.
Network disconnected.
Network disconnected.
wifi evt: 0
Network disconnected.
wifi evt: 3
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com IP: 52.70.203.194
Dropped a packet
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
Dropped a packet

Adafruit IO connected.
:rn 101
:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.30%
Status: 21
:sent 117
:sent 117
:rn 101
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.90C
fahrenheit: 73.22F
humidity: 33.00%
Status: 21
:sent 117
:rn 101
:sent 117
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:sent 117
:rn 101
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:rn 101
:sent 117
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:sent 117
:rn 101
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:sent 117
:rn 101
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:sent 117
:rn 101
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:rn 101
:sent 117
:rch 101, 101
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:rn 101
:sent 117
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:rn 101
:sent 117
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:sent 117
:rn 101
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:sent 117
:rn 101
:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 44:rn 101
:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:sent 117
:rn 101
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:sent 117
:rn 101
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:rn 101
:sent 117
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:rn 101
:sent 117
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:sent 117
:rn 101
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:sent 117
:rn 101
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41celsius: 22.80C
fahrenheit: 73.04F
humidity: 32.80%
Status: 21
:sent 117
:rn 101
:sent 117
:rch 101, 101
:rd 5, 202, 0
:rdi 101, 5
:rd 96, 202, 5
:rdi 96, 96
:c 96, 101, 202
:wcs ra 44:rd 5, 101, 0
:rdi 101, 5
:rd 96, 101, 5
:rdi 96, 96
:c0 96, 101
:wcs ra 41rll⸮⸮|⸮l⸮|�⸮l⸮b|⸮⸮�⸮�⸮r⸮b⸮b⸮⸮nn⸮lnn⸮⸮⸮b�p⸮lrlrlp⸮n⸮��⸮l⸮⸮bn⸮|�l⸮⸮b⸮⸮nn⸮l⸮⸮l`�⸮��nnl`���nr⸮⸮⸮nb⸮�l�r⸮⸮nb⸮�l⸮��l⸮⸮�⸮⸮⸮�rl⸮⸮n⸮�Starting
wifi evt: 0
wifi evt: 3
Connecting to Adafruit IO
Network disconnected.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
wifi evt: 7
wifi evt: 7
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
wifi evt: 7
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
wifi evt: 7
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com
[hostByName] Host: io.adafruit.com lookup error: -5!
Disconnected from Adafruit IO.
[hostByName] request IP for: io.adafruit.com

@maxdd
Copy link

maxdd commented Apr 12, 2017

I have exactly the same problem. Did you find a workaround? I have a NodeMCU chip and even with the flasher it is not resetting the credentials.
Hence i can only connect to the first entered network.

@jcollie
Copy link
Author

jcollie commented Apr 12, 2017

Yes, if I always set the WiFi mode, like such:

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

If I leave off the WiFi.mode call I get the behavior described above. A lot of the sample code that I found through Google doesn't have a call to WiFi.mode.

@maxdd
Copy link

maxdd commented Apr 12, 2017

Can you link me which SDK/firmware and method you used to update your device? i feel like i have an old version.

@jcollie
Copy link
Author

jcollie commented Apr 13, 2017

I'm using 2.3.0, nothing too special.

https://github.com/esp8266/Arduino/releases/tag/2.3.0

@cbrum11
Copy link

cbrum11 commented Apr 14, 2017

I agree with @jcollie.

I use the following with all my ESP modules and it fixed my re connection (or lacktherof) issues.

At the top of code:

extern "C"{
#include "user_interface.h"
}

In my setup_wifi() function

void setup_wifi() {

  delay(10);
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  wifi_set_sleep_type(NONE_SLEEP_T);
  WiFi.persistent(false);     //These 3 lines are a required work-around
  WiFi.mode(WIFI_OFF);    //otherwise the module will not reconnect
  WiFi.mode(WIFI_STA);    //if it gets disconnected
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

Not sure what kind of black magic happens, with this, but it always seems to work.

-Chase

@maxdd
Copy link

maxdd commented Apr 14, 2017

WiFi.persistent(false) --> doesn't it avoid the saving of the SSID/password in the flash?
So this snippet works only if you are writing the credentials in the code.
We need to find a solution for when we use SoftAP fallback or WiFiManager.
For a project like mine, i don't know the credentials and i need to let the user input them

@cbrum11
Copy link

cbrum11 commented Apr 14, 2017

From HERE

persistent

WiFi.persistent (persistent)

Module is able to reconnect to last used Wi-Fi network on power up or reset basing on settings stored in specific sectors of flash memory. By default these settings are written to flash each time they are used in functions like WiFi.begin(ssid, password). This happens no matter if SSID or password has been actually changed.

This might result in some wear of flash memory depending on how often such functions are called.

Setting persistent to false will get SSID / password written to flash only if currently used values do not match what is already stored in flash.

So the way I read that is... it doesn't avoid saving the SSID/password to flash, it avoids REWRITING the values to flash if they're not different than the last values used.

Either way, apologies, because I don't think I've been much help to your current dilemma.

@maxdd
Copy link

maxdd commented Apr 14, 2017

That's interesting, maybe i confused it with wifi.disconnect(false) ?
Anyway i have two questions for you,

  1. Why are you using wifi_set_sleep_type(NONE_SLEEP_T) in the setup() ?
  2. Based on your experience how would you change this WEP/WPA-PSK on old router and STA to AP switch #3132 ? Would you put
WiFi.persistent(false);     //These 3 lines are a required work-around
WiFi.mode(WIFI_OFF);    //otherwise the module will not reconnect

both before

WiFi.mode(WIFI_STA);
WiFi.begin(WiFi.SSID().c_str(), WiFi.psk().c_str());

and

WiFi.mode(WIFI_STA);
WiFi.begin(SSID.c_str(), PW.c_str());

I just want to add that this problem affects also other library it seems tzapu/WiFiManager#353

@devyte
Copy link
Collaborator

devyte commented Nov 10, 2019

This issue is old. A lot has changed since it was reported, including several fixes that are relevant to the original post.
As to the light sleep post, that is still ongoing and is a known issue with our current SDK 2.2.x branch. I think the issue has to do with how sleep is done: there are two light sleep levels, min and max. In 2.2.x the level is hardcoded to max. In SDK 3.x there is an api that allows choosing min or max. Level max is appropriate for cases where the ESP wakes up and initiates outbound connections and then shuts down again. Level min is appropriate for server-type cases where somebody needs to connect to the ESP over network.
Given that 2.2.x doesn't have level min, the only reliable setting for server-type apps is no sleep.

Closing this.

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

4 participants