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 Reconnection Problem With Version 2.4.0 #4445

Closed
mustafayuce33 opened this issue Mar 1, 2018 · 10 comments
Closed

Esp8266 Reconnection Problem With Version 2.4.0 #4445

mustafayuce33 opened this issue Mar 1, 2018 · 10 comments

Comments

@mustafayuce33
Copy link

mustafayuce33 commented Mar 1, 2018

Basic Infos

Hardware

Hardware: ESP-12
Core Version: 2.4.0

Description

With previous version of SDK, esp tries to reconnect wifi network when its connection is lost. But with 2.4.0 version when I reboot modem esp can not recognize "disconnect" state. I have tested this issue with both of version. Esp with 2.3.0 version work well.

Settings in IDE

Module: Generic ESP8266 Module
Flash Size: 4MB
CPU Frequency: 80Mhz
Flash Mode: qio
Flash Frequency: 40Mhz?
Upload Using: OTA
Reset Method: ck

Sketch

#include <Arduino.h>

#include <ESP8266WiFi.h> 
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager - See more at: http://www.esp8266.com/viewtopic.php?f=32&t=9056#sthash.ZdUTu2vQ.dpuf

Ticker connectionCheck;
ESP8266WebServer server(80);
ESP8266HTTPUpdateServer httpUpdater;


//callback notifying us of the need to save config
void saveConfigCallback () {
  Serial.println("Should save config");
  shouldSaveConfig = true;
}

char devicename[30] = "";
WiFiManagerParameter custom_devicename("devicename", "device name", devicename, 30);

bool reconnectChecker;

void connectionCheckHandler()
{
  
  if (reconnectChecker == false && WiFi.status() != WL_CONNECTED){
    reconnectChecker = true;
    WiFi.reconnect();    
  }
  else if (WiFi.status() == WL_CONNECTED && reconnectChecker == true){
    reconnectChecker = false;
  }
  
}


void setup()
{ 
   reconnectChecker = false;

  Serial.begin(115200);//fixed at 115200 bps for all platforms
  Serial.println("Connecting"); // HELLO STRING - ALL COMMENTS SENT IN !....! FORMAT
  Serial.setDebugOutput(true);

  char hostString[32] = {0};  
  sprintf(hostString, "arnido-ir-esp%06X", ESP.getChipId());

  wifiManager.setDebugOutput(true);
  wifiManager.setSaveConfigCallback(saveConfigCallback);
  wifiManager.addParameter(&custom_devicename);
  wifiManager.setBreakAfterConfig(true);
  
  wifiManager.setTimeout(180);
  wifiManager.setConnectTimeout(20);

  wifiManager.getSSID();
  wifiManager.getPassword();
  
  WiFi.setOutputPower(20.5);
  
 if(!wifiManager.autoConnect(hostString, update_password)) {
    Serial.println("Could not connect wifi!!!!!");
    delay(3000);
    //reset and try again, or maybe put it to deep sleep
    ESP.restart();
    delay(5000);
    return;
  }   

  delay(50);
  

  if (!MDNS.begin(hostString)) {
      while(1) { 
        delay(1000);
      }    
  }       
  
  server.on("/", homepage);      
  server.on("/index.html", homepage);      
  
  server.begin();

  delay(0);    
  
   MDNS.addService("arnido-ir", "tcp", 80); // Announce esp tcp service on port 8080
   MDNS.addServiceTxt("arnido-ir", "tcp", "devicename",  ((const char *)devicename));  

   connectionCheck.attach(240, connectionCheckHandler);
}
void loop() {

}

Debug Messages

I have set Serial.setDebugOutput(true); and look at the logs. Here are the logs with 2.3.0 version ;

*WM: Connection result: 
*WM: 3
*WM: IP Address:
*WM: 192.168.6.169
pm open,type:2 0
Invalid WEP key *******
ap_loss
state: 5 -> 0 (0)
rm 0
pm close 7
reconnect
scandone
no ARMAKOM found, reconnect after 1s
reconnect
scandone
no ARMAKOM found, reconnect after 1s
reconnect
no ARMAKOM found, reconnect after 1s
reconnect
scandone
no ARMAKOM found, reconnect after 1s
reconnect
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
cnt 

connected with ARMAKOM, channel 6
dhcp client start...
ip:192.168.6.169,mask:255.255.255.0,gw:192.168.6.1
pm open,type:2 0

Here are the logs with 2.4.0 version ;

connected with ARMAKOM, channel 1
dhcp client start...
ip:192.168.6.169,mask:255.255.255.0,gw:192.168.6.1
*WM: Connection result: 
*WM: 3
*WM: IP Address:
*WM: 192.168.6.169
pm open,type:2 0
Invalid WEP key *****
ap_loss
reconnect
state: 5 -> 0 (0)
rm 0
pm close 7
f r0, scandone

It waits but it doesnt reconnect wifi network again . (Connection State is most probably WL_IDLE_STATUS)

@mustafayuce33 mustafayuce33 changed the title Esp8266 Reconnection Problem Version 2.4.0 Esp8266 Reconnection Problem With Version 2.4.0 Mar 1, 2018
@igrr
Copy link
Member

igrr commented Mar 8, 2018

Could you please

  1. update the PR description to include the sketch used to reproduce this issue
  2. install version 2.4.1 using boards manager and try again

@mustafayuce33
Copy link
Author

mustafayuce33 commented Mar 8, 2018

Thanks for your answer. I have uploaded a piece of code. Here in our office when i reboot modem device , esp catches this issue and tries to reconnect again. But sometimes it doesn't. This is the problem. It stops somewhere in the code.

This is the log

connected with Arv4, channel 1
dhcp client start...
[WiFi] 0, Connected
Ok check connection again
ip:192.168.6.169,mask:255.255.255.0,gw:192.168.6.1
[WiFi] 3, Got IP
pm open,type:2 0
Invalid WEP key *****
ap_loss
reconnect
state: 5 -> 0 (0)
rm 0
pm close 7
Invalid WEP key *****
scandone

As you can see code sometimes stops like this and doesnt try to reconnect again until i call reconnect manually.

At this moment Wifi.Status() is WL_IDLE_STATUS. So i have added a timer in my sketch that checks connection status and if it is not "connect" then i call "reconnect" function.

And i also install latest git version by help of https://github.com/esp8266/Arduino#using-git-version link. Does this might cause problem?

@d-a-v
Copy link
Collaborator

d-a-v commented Mar 8, 2018

Can you try with
WiFi.setSleepMode(WIFI_NONE_SLEEP);

@tablatronix
Copy link
Contributor

tablatronix commented Mar 8, 2018

This sounds alot like and issue I was seeing also, where I know the ap exists, but scandone then says nope not found. hmm, probably fixed by 2.4.1, If i see it again I will make note of it.

#4397

@mustafayuce33
Copy link
Author

Hi dave. Ok i will try your suggestion. And leave feedback again.

@mustafayuce33
Copy link
Author

Hi tablatronix

I am actually trying with theatest git version. It is not solved i think.

@tablatronix
Copy link
Contributor

You'll need a smaller minimal sketch to reproduce, one with no libraries.

@tablatronix
Copy link
Contributor

I could not reproduce with basic sketch and staging, tried all sorts of stuff. Did not try the example sketch there are too many libs and variables

@mustafayuce33
Copy link
Author

tablatronix , Thank you for your help. The example sketch is no so much different from basic sketch. I dont encounter this problem with some modems . Here at our office there is a modem brand name is "GrandStream". This modem causes this problem sometimes.

@devyte
Copy link
Collaborator

devyte commented Jul 13, 2018

There have been several fixes merged since this was opened, especially into the lwip glue. The current connection status has thoroughly tested. If there are problems connecting to a specific wifi router, the problem is either in the router, in which case there is nothing we can do, or in Espressif's SDK, in which case there is nothing we can do in this repo.
Closing.

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