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

AP Mode does not allow connection for most devices #1094

Closed
ibaranov-cp opened this issue Nov 27, 2015 · 40 comments
Closed

AP Mode does not allow connection for most devices #1094

ibaranov-cp opened this issue Nov 27, 2015 · 40 comments

Comments

@ibaranov-cp
Copy link

ibaranov-cp commented Nov 27, 2015

Hello all,

Using latest staging version, RC2 from board manager.
I have two identical ESP8266-12E modules. Powered with 600mA 3.3V regulator off of USB V+
I load them both with the example WifiAccessPoint code.
I add in a Serial.println("."); into the loop to ensure they are both working.

When attempting to connect to the modules, phone has to re-connect ~3-5 times to get a connection. And then loading the example webpage at 192.168.4.1 takes ~30 seconds.

Three different models of laptops refuse to connect at all.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@comino
Copy link
Contributor

comino commented Nov 27, 2015

Similar observations:

  • Im using the latest git version
  • ESP-WROOM module
  • Hardware is proven to work with SDK example

Tested:
Lennovo E550- Intel WiFi adapter - no connection at all
Lennovo X Series - after several attemps succesful
Galaxy Tab 2 - successful
Motorola Moto G - successful
Toshiba Sattelite - Realtek Wifi adapter - successful on first try

@me-no-dev
Copy link
Collaborator

does it make a difference if the AP is Open or Password protected?

@comino
Copy link
Contributor

comino commented Nov 28, 2015

It asks me for a password before not connecting.

Maybe its a issue with the SDK? My running native AP code runs on SDKs 1.1.1 and there is a fix for 1.4 ("WiFi compatibility problem of special network card").

@igrr
Copy link
Member

igrr commented Nov 30, 2015

Since SDK 1.3, RF calibration is stored in flash. On a few occasions i had to wipe flash completely because the board failed to connect to APs.
It would be nice to check if this issue is resolved by wiping RF calibration data. If it is, perhaps it would be worth changing the default RF calibration mode.

@ibaranov-cp
Copy link
Author

I will certainly try, any quick link to wiping the data?

Can't seem to capture any packets on Wireshark during connection, and open vs. encrypted does not make a difference so far.

@igrr
Copy link
Member

igrr commented Nov 30, 2015

Using esptool.py:

esptool.py -p /dev/ttyUSB0 erase_flash

Or from inside the sketch:

ESP.eraseConfig();

@ibaranov-cp
Copy link
Author

Hello all,

Here is a compressed wireshark capture of trying to connect to esp in AP mode.
https://mrrobot.ca/owncloud/index.php/s/AKOX4BBZvoma47z

Actions taken

  • Change WifiAccessPoint sketch to AP name ESP1, no password
  • Connect to AP, try to hit 192.168.4.1
  • Manually configure my IP to 192.168.4.10, Bcast 255.255.255.0, gateway 192.168.4.1
  • Ping 192.168.4.1

I still get no connections.

@ibaranov-cp
Copy link
Author

Adding this to the example script has no effect:

void setup() {
ESP.eraseConfig();
... etc

@ibaranov-cp
Copy link
Author

P.S
By default, my windows 7 laptop seems to assign IP 169.254.xx.xx with bcast 255.255.0.0
This usually means no good connection established.

@ibaranov-cp
Copy link
Author

To be clear, using a password results in no packet capture, and no successful connection.
Without a password, I get a connection and packets, but no IP assignment, and no usable connection.

@luc-github
Copy link
Contributor

did you tried to change the PHY mode on ESP ?

like : wifi_set_phy_mode(PHY_MODE_11B); or wifi_set_phy_mode(PHY_MODE_11G);

@ibaranov-cp
Copy link
Author

Adding WiFi.mode(WIFI_AP); either before or after the WiFi.softAP(ssid, password); statement has no effect.

The chip is never frozen, it continues to output serial data. etc. Just refuses to connect.

@ibaranov-cp
Copy link
Author

Hello,

(Updated to stable Nov 30th version just to be sure)

Two questions:
What do the fields below indicate?
How can I do the phy mode set? I tried to hack it in myself, but no luck. Has anyone done it?

Here is the output of WiFi.printDiag(Serial);

Mode: AP
PHY mode: N
Channel: 1
AP id: 0
Status: 255
Auto connect: 1
SSID (0):
Passphrase (0):
BSSID set: 0
192.168.4.1

@luc-github
Copy link
Contributor

AP do not support phy mode N and seems you are in N, that may explain the connection issue.
I already gave the function above but here the extract from SDK for more details :

 wifi_set_phy_mode
Function:
Set ESP8266 physical mode (802.11b/g/n).
Note:
• ESP8266 soft-AP only support 802.11b/g.
• Users can set to be 802.11g mode for consumption.
Prototype:
bool wifi_set_phy_mode(enum phy_mode mode)
Parameter:
enum phy_mode mode : physical mode
enum phy_mode {
 PHY_MODE_11B = 1,
 PHY_MODE_11G = 2,
 PHY_MODE_11N = 3
};
Return:
true : succeed
false : fail  

@ibaranov-cp
Copy link
Author

I have the default example code, why does it do N?

Can I change it?
On Dec 4, 2015 7:29 PM, "Luc" notifications@github.com wrote:

AP do not support phy mode N and seems you are in N, that may explain the
connection issue.
I already gave the function above but here the extract from SDK for more
details :

wifi_set_phy_mode
Function:
Set ESP8266 physical mode (802.11b/g/n).
Note:
• ESP8266 soft-AP only support 802.11b/g.
• Users can set to be 802.11g mode for consumption.
Prototype:
bool wifi_set_phy_mode(enum phy_mode mode)
Parameter:
enum phy_mode mode : physical mode
enum phy_mode {
PHY_MODE_11B = 1,
PHY_MODE_11G = 2,
PHY_MODE_11N = 3
};
Return:
true : succeed
false : fail


Reply to this email directly or view it on GitHub
#1094 (comment).

@luc-github
Copy link
Contributor

it is like password or SSID, it is saved / cached
default example purpose is not about PHY mode, so it is not present

of course you can change, just add the command

@ibaranov-cp
Copy link
Author

There does not seem to be a command to change it that I can see....
On Dec 4, 2015 7:52 PM, "Luc" notifications@github.com wrote:

it is like password or SSID, it is saved / cached
default example purpose is not about PHY mode, so it is not present

of course you can change, just add the command


Reply to this email directly or view it on GitHub
#1094 (comment).

@luc-github
Copy link
Contributor

did you added the header to access it ?

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

@ibaranov-cp
Copy link
Author

Thanks for the tip, it was a good theory, but changing to either B or G has no effect on success rate of connection.

In addition to that, remember that both myself and @comino had success with certain devices connection to the default example, which seems to be N.

Current test code:

#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>

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

/* Set these to your desired credentials. */
const char *ssid = "TESTAP";
const char *password = "123456789";

ESP8266WebServer server(80);

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
 * connected to this access point to see it.
 */
void handleRoot() {
    server.send(200, "text/html", "<h1>You are connected</h1>");
}

void setup() {
  ESP.eraseConfig();
    delay(1000);
    Serial.begin(115200);
    Serial.println();
    Serial.print("Configuring access point...");
    /* You can remove the password parameter if you want the AP to be open. */
    wifi_set_phy_mode(PHY_MODE_11B);
  WiFi.mode(WIFI_AP);
    WiFi.softAP(ssid, password);

    IPAddress myIP = WiFi.softAPIP();
    Serial.print("AP IP address: ");
    Serial.println(myIP);
    server.on("/", handleRoot);
    server.begin();
    Serial.println("HTTP server started");
}

void loop() {
    server.handleClient();
  WiFi.printDiag(Serial);
}

Result of printDiag:
AP id: 0
Status: 255
Auto connect: 1
SSID (0):
Passphrase (0):
BSSID set: 0
Mode: AP
PHY mode: B
Channel: 1

@comino
Copy link
Contributor

comino commented Dec 7, 2015

I still have the same issue. I don’t believe its a simple issue like adding a few lines of code, since its working for 50% of my devices. I tried a lot! I must be a more complex issue, maybe even with the SDK. I wait until we change to 1.5 (as said there were apparently some issues in the SDK 1.3) and if the issue consists I will investigate further.

@comino
Copy link
Contributor

comino commented Dec 9, 2015

Still unresolved and two more Laptops unable to connect

@tablatronix
Copy link
Contributor

Any progress on this or further suspicions ?

I have the same problem, eg. IOS will not join AP with error Unable to Join this network IF i have a stored config that fails to autoconnect.

Same config output as above, changing PHY_MODE makes no difference.

This only happens if i start a softap and have a saved client config and it fails to connect.

So basically a WiFi.begin("nonexisting","password") before the mode(AP) switch over and softap() call reproduces this. no small test sketch to post yet.

If I eraseConfig() reboot, then it works again.

wifi info seems the same, so it must be some other setting or RF setup that's sticking around cause printDiag is not giving me any hints.

some hints... ( I think i read this similar problem somewhere )
..other devices are able to connect, but they are extremely slow or fail on webserving.

Also get this wierd stuff in debug log now and then..
max connections!
LmacRxBlk:1
shrug

@tablatronix
Copy link
Contributor

ok well my specific problem might be fixed now.

I had to explicitly disconnect before turning on AP.

  WiFi.disconnect(true);
  WiFi.mode(WIFI_AP);

Which is odd.

@tablatronix
Copy link
Contributor

This issue sounds like #1624 with different symptoms.

@tablatronix
Copy link
Contributor

So here's my reproduction sketch, this condition occurs if you do not start ap mode fast enough or don't wait long enough for it to time out. I can reproduce fairly easily with IOS, i guess it doesn't like some channels.

as far as waitForConnectResult goes,
My guess is that scanmode is still async scanning channels when wifi_station_get_connect_status returns STATION_NO_AP_FOUND I see a rogue scandone popup, and if I delay about 2000ms after it works again.

But I am at my limit of debugging

/* Create a WiFi access point and provide a web server on it. */

#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>

/* Set these to your desired credentials. */
const char *ssid = "ESPap";
const char *password;

ESP8266WebServer server(80);

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
 * connected to this access point to see it.
 */
void handleRoot() {
    server.send(200, "text/html", "<h1>You are connected</h1>");
}

void setup() {
    delay(1000);

  Serial.begin(115200);
  Serial.setDebugOutput(true); 
  Serial.println();

  WiFi.setAutoConnect(false);

  // WiFi.begin("nonexisting","password"); // store
  WiFi.begin(); // restore

   /* THESE BOTH BREAK AP JOINS FOR SOME REASON , they give time for the reconnect to start scanning if my guess ( you will see a rogue async "scandone" */
  // Serial.println("connect result: " + (String)WiFi.waitForConnectResult());
  delay(6000);

  WiFi.printDiag(Serial);
  WiFi.mode(WIFI_AP); // this stops the autoconnect
  WiFi.printDiag(Serial);

    Serial.println();
    Serial.print("Configuring access point...");
    /* You can remove the password parameter if you want the AP to be open. */
    WiFi.softAP(ssid, password); // stick a channel 1 in there, and it still fails...
  delay(300);
  WiFi.printDiag(Serial);

    IPAddress myIP = WiFi.softAPIP();
    Serial.print("AP IP address: ");
    Serial.println(myIP);
    server.on("/", handleRoot);
    server.begin();
    Serial.println("HTTP server started");
}

void loop() {
    server.handleClient();
}

oh and the lack of a way to call
wifi_station_disconnect without dealing with persistent mode and erasing config is rather odd..

@tablatronix
Copy link
Contributor

And of course it works fine on my other device... sigh

@sunepedersen
Copy link

I had the same experience in areas with a lot of wifi networks i believe. I tried changing channels and setting WiFi.setOutputPower(20.5) and it seems to have improved the situation.

@ibaranov-cp
Copy link
Author

Interesting, what is the default output power?

Anyone know of any current vs. power measurements done? And power vs
distance?

On Mon, Mar 14, 2016 at 7:59 PM, Sune Pedersen notifications@github.com
wrote:

I had the same experience in areas with a lot of wifi networks i believe.
I tried changing channels and setting WiFi.setOutputPower(20.5) and it
seems to have improved the situation.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#1094 (comment)

Ilia Baranov | Engineering Manager, Research Solutions | Clearpath Robotics

1425 Strasburg Rd., Kitchener, Ontario N2R 1H2 Canada
*T: * +1 (800) 301-3863 x839

E: ibaranov@clearpathrobotics.com | W: www.clearpathrobotics.com

_Your Unmanned Experts _TM

This electronic communication (including any attachments) is CONFIDENTIAL
AND LEGALLY PRIVILEGED. Any unauthorized use or disclosure is strictly
prohibited. If you are not the intended recipient, you are hereby notified
that any review, retransmission, conversion to hard copy, copying,
circulation or other use of this message and any attachments is strictly
prohibited. The recipient should check this email and any attachments for
the presence of viruses. The company accepts no liability for any damage
caused by any virus transmitted by this email. Thank you.

@tablatronix
Copy link
Contributor

I also test in an area with lots of aps, 23 or so.

@Vzor-
Copy link

Vzor- commented Apr 9, 2016

I can confirm this is an issue with the esp sdk and not the arduino implementation, and can be fixed by adding wifi_station_disconnect() before changing to AP mode.

@CaptClaude
Copy link

CaptClaude commented May 22, 2016

I am new to this and am trying to RTFM before posting. Using ESPlorer and lua, I am experiencing the same difficulty with getting consistent connection to an iOS device (iPhone 5) when my ESP-12EV2 (Banggood.com) is in SoftAP mode. I have no trouble consistently connecting with OS X or Windows. I have been through so many iterations and changes that I have lost track of the threads I have been following and cannot give a concise Step A, Step B, Step C... account of my debug attempts (I must be ADD). Suffice it to say that I am flashing "write_flash -fm dio 0x00000 ../nodemcu_integer_0.9.6-dev_20150704.bin 0x3fc000 ../esp_init_data_default.bin" when necessary and trying different orders of operations of setting up the SoftAP mode. None of the different SoftAP setup sequences allows me to connect my iPhone more than once unless I power off the ESP and turn WiFi off and back on on the iPhone. Once I power cycle the ESP and turn the iPhone WiFi on and off, I can pretty much switch between my home AP and my ESP without dropping the connection. The following sequence in init.lua sort of works:

wifi.setmode(wifi.STATION)

wifi.sta.disconnect() -- this is supposed to fix the iPhone issue
print("Start soft AP as mizefi with pw=12345678 and ip=192.168.4.1")
wifi.setmode(wifi.SOFTAP) 

wifi.setphymode(wifi.PHYMODE_G)
local cfg={
    ssid="mizefi",
    pwd="12345678"
}

wifi.ap.config(cfg)
cfg={}
cfg ={
    ip="192.168.4.1",
    netmask="255.255.255.0",
    gateway="192.168.4.1",
    beacon="33"
}
wifi.ap.setip(cfg)

EDIT: I was too enthusiastic. Both the iPhone and the Macbook drop the WiFi connection after a couple of minutes but I can reconnect, occasionally needing to power cycle or reset the ESP and reconnect.
Needless to say, this is an unacceptable. Connecting to another AP in Station mode does not have this issue.
I too, am at the end of my debugging abilities.

@YannikW
Copy link

YannikW commented Aug 14, 2016

It seems I've a similar issue..
I configured my ESP as AP and connection works fine with my android phone.. (Wifi and TCP server works), but when I trie to connect to the Wifi with my both windows pcs it wont connect.. Somestimes it workes, but it lose connection after a couple of seconds.. And that few times the Wifi was working I was not always able to connect to my TCP server (maybe the wifi crashed but windows delayed the message)..

I tried all the fixes mentioned above but nothing solved the problem..

//Start Access Point
  ESP.eraseConfig();
  wifi_set_phy_mode(PHY_MODE_11G);
  WiFi.setAutoConnect(false);
  WiFi.disconnect(true);
  WiFi.mode(WIFI_AP);
  WiFi.softAP(ssid, password);

  //Start Server
  server.begin();
  server.setNoDelay(true);

Anyone has a idea to fix this? It's stanged it workes on my phone every time, but not reliable on my computers..

@rvireday
Copy link

rvireday commented Sep 6, 2016

I can offer one clue. When I have my laptop connected to a physical port on the WAP, I can talk to the ESP device no problem. Web service works.

When I switch the laptop to WiFi only, rnet::ERR_CONNECTION_REFUSED.

So physical to WAP, WiFi to ESP: good. WiFi to WAP, WiFi to ESP: no good.

Nothing shows on the ESP console that it is even having a node try and connect.
-r

@santon2000
Copy link

Hi, I also faced with this problem.

Any news?

@tablatronix
Copy link
Contributor

You guys are probably gonna have to post info what versions what boards and minimal reporduction sketches. No one can really debug this but id be glad to look at it to help. Have you tested latest dev code for example.

@ArGaspar
Copy link

@igrr my sketch is working excellent on esp-01 but on esp-12e I have to use ESP.eraseConfig(); always, the first time I connect to wifi, everything goes well but when I try for second time I cant so I have to use ESP.eraseConfig(); . any idea what can be causing this on esp-12e?

best regards

@devyte
Copy link
Collaborator

devyte commented Oct 19, 2017

This is a known issue. You have to erase the flash before uploading the sketch, or call eraseConfig(), or call WiFi.disconnect().
This is caused by the STA and SOFTAP interfaces sharing a single radio. When the station side tries to reconnect, or even search, it channel hops, and drags the SOFTAP side along for the ride. The client that's connected to the SOFTAP sees the ap drop out, has to search for it, connect, get DHCP, etc all over again, then the TCP connection needs to retry, etc.
The only workaround is to force the SOFTAP to the same channel as the AP that the STA is trying to connect to. If done correctly (i.e.: connect STA first, then get the channel, then start the SOFTAP on that channel), it should be ok.
Different laptops/cells/other devices, as well as different OSs, behave differently when faced with an AP that drops out of existence.
Closing.

@ThomasBj
Copy link

So what is the solution to this issue? It sounds like ESP8266 is not up to the task of acting as an access point.
Can somebody who has got it working please submit some code.

@vks007
Copy link

vks007 commented Apr 1, 2018

I had the same issue as what others describe. I could mostly connect from my iPhone but very rarely from my windows PC.
As suggested on this post, I erased the config on the ESP once by calling ESP.eraseConfig(); and then things were fine. The connection is also very very fast now. It connects in a jiffy!
Following is what I did to solve the issue using code. As suggested in the issue here there seems to be a bug due to which is the current stored WiFi is already connected it ignores the new credentials which it has just received. In order to avoid that I modified the lines in the WiFiManager.cpp as below in the method
int WiFiManager::connectWifi(String ssid, String pass)

//fix for auto connect racing issue if (WiFi.status() == WL_CONNECTED) { //DEBUG_WM("Already connected. Bailing out."); //return WL_CONNECTED; DEBUG_WM("Already connected. Disconnecting now."); WiFi.disconnect(); }

@davidverweij
Copy link

The addition by @tablatronix (see below) has fixed my issues for using a iphone to connect to the AP. Though I did change WIFI_AP to WIFI_STA. I am using WifiManager and this was a suggestion for an older SDK.

ok well my specific problem might be fixed now. I had to explicitly disconnect before turning on AP. WiFi.disconnect(true);
WiFi.mode(WIFI_AP);
Which is odd.

My snippet:

WiFiManager wifiManager;
WiFi.disconnect(true);
WiFi.mode(WIFI_STA);
if (!wifiManager.autoConnect(SSID,PASS)) {
   Serial.println("failed to connect and hit timeout");
   delay(3000);
   //reset and try again, or maybe put it to deep sleep
   ESP.reset();
   delay(5000);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests