Chat freely about anything...

User avatar
By Kirk Spencer
#83539 I'm working on a project intended to eventually be given as a gift to friends and family. It uses wifi and so the idea is to have it start in soft AP mode and to host a simple HTTP server to serve up a basic web page where they can enter their wifi credentials. After entering their wifi credentials it would connect to their wifi and return the newly acquired ip address from the router back to the client so that the client can get redirected to the new address and the user can wrap up the setup process.

I have all of this working. However, where I run in to problems is that once the wifi starts the connection process to the router, I start to see tons of dropped packets on the soft AP ip. The connection normally stays open long enough for the new ip address to get sent, but not always. I would like this to be fool proof since I plan on giving it to people.

This is what I run in the setup:
Code: Select allWiFi.mode(WIFI_AP_STA);
boolean result = WiFi.softAP("motion-sensor", "password", 8);
if(result == true) {
  Serial.println("Ready");
} else {
  Serial.println("Starting soft-AP Failed! Rebooting...");
  delay(5000);
  ESP.restart();
}

When my modest HTTP server receives an HTTP POST with the wifi credentials I run the following which is exactly when I start to see dropped packets:
Code: Select allWiFi.begin(ssid.c_str(), password.c_str());

I have read that the channel can cause issues if its heavily used in your area. I have it set on channel 8 because it looked like it had the least amount of overlap from my scans.

As I mentioned, this works probably 85% of the time if not more, but I would really like to figure out why I get so many dropped packets once both the soft ap and the station are active.
User avatar
By btidey
#83542 Are you using WifiManager? This is a standard to achieve exactly what you want. It tries to connect to Wifi. If it can't then brings up an AP with user interface to allow the user to select and enter local wifi credentials. It then resets and enters normal STA mode.
User avatar
By Kirk Spencer
#83548 No, I hand rolled this solution. I honestly had not seen WifiManager but I just googled it and found a github project which I am assuming is what you were talking about. I can look at their source code to see what they are doing. It looks like it is quite feature complete from a cursory glance. Either way, I'd still like to try and figure out what is causing the packets to drop.
User avatar
By schufti
#83560 your problem might be that esp can only work on one channel. So after you enter credentials for existing wlan, it eventually (not necessarily) changes channel, so prior connection mobilephone-esp (on softAP) gets lost.