Skip to content
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

Esp8266 Wifi connection often disconnects (bcn_timout) #5083

Closed
stefanodelbosco opened this issue Aug 27, 2018 · 19 comments
Closed

Esp8266 Wifi connection often disconnects (bcn_timout) #5083

stefanodelbosco opened this issue Aug 27, 2018 · 19 comments
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.

Comments

@stefanodelbosco
Copy link

Platform

  • Hardware: NodeMCU 1.0 (ESP12E-Module)
  • Core Version: latest git 2.4.2 && 2.2.1
  • Development Env: Arduino IDE (last git) && Platformio 2.2.1
  • Operating System: Ubuntu

Settings in IDE

  • Module: Nodemcu
  • Flash Size: 4MB
  • CPU Frequency: 80Mhz
  • Upload Using: OTA && SERIAL
  • Upload Speed: [115200 (Serial)]

Problem Description

I looked for a solution between the various issues but none worked right now.
I have updated sdk to the latest version with git
The connection to the WiFi remains active for a time ranging from 30 seconds to 6 hours.
The module disconnects and reconnects by the connectDeviceToWiFi () function.

I tried to lower the time beecon in the router. Now it's every 30 ms (default 100ms).

I've been trying for three days to find a solution but the situation is not changing.
I tried with two different modules near the router and both give problems.

The RSSI signal is always between -70 and -78. I did a -68 signal tests but the problem persists.

I hope someone can help me.

MCVE Sketch

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266CustomTools.h>
#include "ota.h"
#include <ArduinoOTA.h>

ESP8266WebServer server(80);
ESP8266CustomTools device("SensorTest", D7, "sensor");

String IP_SERVER = "192.168.1.5";


void setup() {
  Serial.begin(9600);
  pinMode(D7, INPUT);
  device.connectDeviceToWiFi();
  device.syncCurrentTimestamp();
  device.generateOTPSecret();
  server.on("/info", handleInfo);
  server.begin();
  Serial.println(ESP.getCoreVersion());
  Serial.println(ESP.getSdkVersion());

  ota_setup("Esp8266", "PASSWORD");
}

void loop() {
    server.handleClient();
    //Check if connection is alive
    device.connectDeviceToWiFi();
    //Update IP/MAC
    device.checkAndUpdateConnectionInfo();
    if(digitalRead(D7) == 0){
      Serial.println("Change state");
    }
    device.checkAndUpdateTimestampOTP();
    //OTA Check
    ArduinoOTA.handle();
    delay(10);
}

ESP8266CustomTools::connectDeviceToWiFi()

void ESP8266CustomTools::connectDeviceToWiFi(){
  while(WiFi.status() != WL_CONNECTED){
    WiFi.mode(WIFI_STA);
    WiFi.disconnect();
    delay(200);
    WiFi.begin(ssid, password);
    long timewait = 0;
    long timeout = 10000;
    while(WiFi.status() != WL_CONNECTED && timewait < timeout){
       delay(1000);
       timewait = timewait + 1000;
    }
    if(WiFi.status() == WL_CONNECTED){
      String IP = WiFi.localIP().toString();
      String MACADDRESS = WiFi.macAddress();
      MACADDRESS.toLowerCase();
      Serial.println(IP);
      HTTPClient http;
      http.begin("http://" + IP_SERVER + "/api/device/connected_wifi_device?ip=" + IP + "&mac=" + MACADDRESS + "&type=" + TYPE);
      int httpCode = http.GET();
      String payload = http.getString();
      if(httpCode == 200){
        Serial.println("Message sent");
        last_server_update = millis();
      }
      http.end();
    }
  }
}

Debug Messages

SDK:2.2.1(cfd48f3)/Core:2.4.2/lwIP:2.0.3(STABLE-2_0_3_RELEASE/glue:arduino-2.4.1-13-g163bb82)/BearSSL:6d1cefc
scandone
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 4
cnt 

connected with dlink-XXXX, channel 10
dhcp client start...
ip:192.168.1.4,mask:255.255.255.0,gw:192.168.1.1
192.168.1.4
    SyncIpServer httpCode: 200
    SyncTimestamp httpCode: 200
    SyncOTP httpCode: 200
    COREVersion: 2_4_2
    SDKVerison: 2.2.1(cfd48f3)

bcn_timout,ap_probe_send_start
ap_probe_send over, rest wifi status to disassoc
state: 5 -> 0 (1)
rm 0
pm close 7
scandone
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 4
cnt 

connected with dlink-XXXX, channel 10
dhcp client start...
ip:192.168.1.4,mask:255.255.255.0,gw:192.168.1.1
192.168.1.4
....
@d-a-v
Copy link
Collaborator

d-a-v commented Aug 27, 2018

  • try WiFi.mode(WIFI_NONE_SLEEP) (more power required)
  • try pingAlive (unknown consequence on power)
  • reading Esp8266 IP Address not reachable after a while #2330 is a punishment, I wont tell you to do so
  • we still don't have it but there's new nonos-sdk-v3 espressif API wifi_set_listen_interval()
    (parameter: interval - listen interval of maximum sleep level for modem sleep and light sleep. Unit: one beacon interval of AP. Range: [1, 10])

@d-a-v d-a-v added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Aug 27, 2018
@stefanodelbosco
Copy link
Author

try WiFi.mode(WIFI_NONE_SLEEP) (more power required)

I tried only WiFi.setSleepMode(WIFI_NONE_SLEEP)
It's been about 20 minutes and there were no disconnections. I think the problem was sleep mode.
I will wait a day of testing to see if the problem was actually that.

@stefanodelbosco
Copy link
Author

After two days of testing, after applying that command, I had no more disconnections.
I think I found the problem and I would say that I can close this issue.
In case I have problems again, I will reopen the issues.
Thanks for the help @d-a-v

@PrateekGoyal18
Copy link

After two days of testing, after applying that command, I had no more disconnections.
I think I found the problem and I would say that I can close this issue.
In case I have problems again, I will reopen the issues.
Thanks for the help @d-a-v

Did you mention this line "WiFi.setSleepMode(WIFI_NONE_SLEEP)" in setup ?

@stefanodelbosco
Copy link
Author

I think so.
I will check this evening and I will let you know.

@stefanodelbosco
Copy link
Author

My code:

void setup() {
Serial.begin(9600);
WiFi.setSleepMode(WIFI_NONE_SLEEP);
[.....]
}

@PrateekGoyal18
Copy link

Thanks @stefanodelbosco

@tablatronix
Copy link
Contributor

I am having this issue suddenly , will not connect at all , if it does it disconnects quickly after
What is the deal with this ? sleep mode none made no difference

bcn_timout,ap_probe_send_start
ap_probe_send over, rest wifi status to disassoc
state: 5 -> 0 (1)
rm 0

@tablatronix
Copy link
Contributor

It seems that if I call analogread too often my wifi drops out, I am not sure what mechanism is going on , I am trying to see how the adc works and how long the reads take and see if it is a wifi servicing issue but not enough for wdt.. does anyone know how to ensure wifi has time to service? Is a yeild() enough?

@e346615
Copy link

e346615 commented Oct 17, 2019

I'm still stuck on this same problem - the WIFI keeps dropping and I have to reconnect. I have maybe one or two seconds before it drops and has to reconnect. I have the board version 2.5.1 and an ESP-12S MCU I'm trying to use for simple UDP broadcasts. Does anybody have this WIFI dropping problem fixed yet?

@devyte
Copy link
Collaborator

devyte commented Oct 17, 2019

@e346615 you need to test with latest git before asking that.

@e346615
Copy link

e346615 commented Oct 19, 2019

Yes, I did, but I read somewhere that only version 2.5.1 worked. I tried both, but neither are working for me.

@mayor89
Copy link

mayor89 commented Oct 21, 2019

My problem was solved with this command WiFi.setSleepMode(WIFI_NONE_SLEEP); plus WiFi.mode(WIFI_STA);. After this it is stable. Thank you!

@pryadav333
Copy link

pryadav333 commented Nov 10, 2019

it seems that the NodeMCU/ESP 8266 is not reliable for IoT projects where we need continuous wifi connectivity. It goes most of time in sleep mode and doesn't respond to the commands. Ideal all time wifi active should be its state. All wakeup commands fails most of time to wake up the nodemcu/esp8266

@d-a-v
Copy link
Collaborator

d-a-v commented Nov 10, 2019

@pryadav333 This thread is closed. Please open a new issue if you still have this problem with version 2.6.0 of this core.

@Tejas-MD
Copy link

I have this issue on latest release of core: 3.0 . I don't understand why the issue is closed. Please help out with a direction to proceed? I tried WiFi.setSleepMode(WIFI_NONE_SLEEP) , not working.

@Pablo2048
Copy link

There is one rule of thumb in such situation - do a full chip erase before uploading your code. I guess that the problem is by switching SDK version using new core 3.0.0 vs the old one so rfcalib/config area is corrupted...

@jeroenst
Copy link

it seems that the NodeMCU/ESP 8266 is not reliable for IoT projects where we need continuous wifi connectivity. It goes most of time in sleep mode and doesn't respond to the commands. Ideal all time wifi active should be its state. All wakeup commands fails most of time to wake up the nodemcu/esp8266

FYI: I have esp8266/nodemcu devices with uptimes over 60 days and continuous wifi without any problem.

@Tejas-MD
Copy link

Tejas-MD commented Jul 11, 2021

For me, it works fine after WiFi.setSleepMode(WIFI_NONE_SLEEP) --> Chip erase ---> Flash with latest firmware.

Very grateful to @Pablo2048

pwnrazr added a commit to pwnrazr/ESP8266_SmartExtension that referenced this issue Aug 26, 2021
WiFi has been crashing every day or so recently. Google says this might help

Source: esp8266/Arduino#5083
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests