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

Connection problems when using mobile devices #435

Closed
sirluckyluke opened this issue Nov 22, 2018 · 23 comments
Closed

Connection problems when using mobile devices #435

sirluckyluke opened this issue Nov 22, 2018 · 23 comments
Labels

Comments

@sirluckyluke
Copy link

Hello folks,

I am working on a project where I try to control servos over a web page. For this, the esp32 is set up in hotspot mode with a DNS server for name resolution and the async web server for content delivery.

Everything is working fine on my development machine (Ubuntu/Firefox/Chrome), I can connect to the esp32 and the web page is shown correctly and also a page refresh is possible. But when I try the same with my mobile phone (android 9) or my tablet (iPad / latest OS) it worked on the first try but when I refresh the page it gets stuck in the refreshing routine and nothing more happens. The weird thing is when I then try to connect from my dev machine the network manager shows an authentication error and wants me to type in the password again (which is not working then). After a hard reset, it is working in most cases till the page refreshing.
Another observation is, that the mobile devices are not really willing to connect to hotspots which are not providing internet. Sometimes my android phone and tablet are disconnecting themselves from the wifi because of no internet or they start using the cellular connection. Furthermore, I see on the webserver that the devices requesting some files like "hotspot-detect.html" or "generate_204".

Could this be some problems with the captive portal detection of mobile devices? Which need some special response from the web server? Or a special authentification routine?

I hope someone could get me some advice on how to deal with this.

@sirluckyluke
Copy link
Author

if forgot to mention:
I using the esp32 dev module with the latest files for the async web server and core files.

@deniss1711
Copy link

deniss1711 commented Nov 24, 2018

Using this implementation https://github.com/boblemaire/ESPAsyncSDWebServer of the server having similar issue.
ESP32 is connected to an AP.
Chrome/Firefox/Edge all do a correct reload of the page. When page is loaded heap is back to start size.

First load of page on mobile devices (iOS/chrome) is ok when app was closed before. A reload of page ends in a stuck page and heap size is not recovering from this. ESP is not reachable from normal computer at this stage. Arduino loop is still running.

@sirluckyluke
Copy link
Author

Sounds like the same issue...do you found a solution? As of now, I am avoiding the page refreshing by enabling caching of the content. So no solution from my side, just a workaround :)

@deniss1711
Copy link

@sirluckyluke Sorry no solution found yet. But my webserver is not sending any data after calling a large js page from the server on a chrome mobile. On all Windows browsers all is working ok.

@hjanshu
Copy link

hjanshu commented Apr 23, 2019

I'm facing the same issue. I'm hosting html and js files on the on-board spiffs. The page loads without issues on windows machine but on Mobile device the page is stuck on loading.

@stale
Copy link

stale bot commented Sep 21, 2019

[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 21, 2019
@stale
Copy link

stale bot commented Oct 5, 2019

[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Oct 5, 2019
@aleuarore
Copy link

Hi guys,
did you find a solution? I'm having this same problem.

@zekageri
Copy link

Chrome and other browsers are requesting some additional default things from the server after the page load such as favicon.ico or manifest.json. i found out that if i serve these files too the problem has gone.

@openedhardware
Copy link

@zekageri
What files did you add to get it working?

I manually added favicon.ico and manifest.json but still not working..

Here is my folder structure:
image

And I am serving with the following code:

server.serveStatic("/", SPIFFS, "/www/").setDefaultFile("index.html");

Thanks!

@zekageri
Copy link

Do you have problems on just AP mode?
What's the decoded error you get?

@openedhardware
Copy link

openedhardware commented Nov 26, 2021

@zekageri

I am just using AP mode all the time.

And how can I check the decoded error on the mobile browser? It is just not responding...

@zekageri
Copy link

Use the esp serial monitor to check the error message when it reboots

@zekageri
Copy link

Or if it is not rebooting then serial print some line when you serve the page to determine where it stuck

@openedhardware
Copy link

There is no error message... 192.168.4.1(default IP address of the AP) doesn't reply at all on my android phone.

But it works on my laptop with wifi dongle...

So strange..

@openedhardware
Copy link

@zekageri

I have just created a new repository to test this issue - https://github.com/openedhardware/TestESP32AsyncWebServer

This is really simple firmware, but the webserver is not working on mobile phones...

@zekageri
Copy link

zekageri commented Nov 26, 2021

First of all. Replace SPIFFS with LITTLEFS. SPIFFS is deprecated and LITTLEFS is much faster and reliable.

Try it without static file serving and create an endpoint in the setup beforfe the server.begin() like this:

server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    AsyncWebServerResponse* response = request->beginResponse(SPIFFS, "/index.html", "text/html");
    request->send(response);
});

If it is working, something wrong with the path's on the static serving.
If it is not working like this, tell me.

You should define your page endpoints like this and serve the static content like images and fonts like this:

server.serveStatic("/", LITTLEFS, "/");

And handle the not found endpoint like this:

server.onNotFound([](AsyncWebServerRequest *request) {
    AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/notFound.html", "text/html");
    request->send(response);
});

Other than that actually i can't see any problem with your code.

Edit: Or try to place your wifi AP mode after the endpoint declaration something like this:

void setup() {
  Serial.begin(115200);

  if(!SPIFFS.begin(true)){
     Serial.println("An Error has occurred while mounting SPIFFS");
     return;
  }
  server.serveStatic("/", SPIFFS, "/www/").setDefaultFile("index.html");
  server.onNotFound(notFound);
  // TODO: Remove this in production!!!
  DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
 
  // Also wifi disconnect and small delay between wifi calls ( depends on the module and the power )
  WiFi.disconnect();
  delay(50);
  WiFi.mode(WIFI_AP); // Access Point mode
  delay(50);
  WiFi.softAP(ssid, password);
  delay(50);
  // If the delay slightly improves the AP mode file serving then put 100ms delay instead.
  // Note: do not put delay at all in the loop, except if it is a separate task and you using vTaskDelay()

  server.begin();
  Serial.println("=== Server started");

}

Let's see if any of this helps

Edit 2 : If none of the above helps the problem, try with different esp moduels and different power supplies. The esp can draw significantly more amper when you working with WiFi.

@openedhardware
Copy link

@zekageri

  WiFi.disconnect();
  delay(50);
  WiFi.mode(WIFI_AP); // Access Point mode
  delay(50);
  WiFi.softAP(ssid, password);
  delay(50);

This resolves the issue! THANKS, A MILLION! 👍

@openedhardware
Copy link

Hi, @zekageri

I am now using the same code on NodeMCU, but doesn't work at all.

Any idea to resolve this issue? Seems power issue?

Thanks again!

@ddp75
Copy link

ddp75 commented Mar 18, 2023

I had a similar problem (http_response_code_failure) using :

if(!request->authenticate(my_username, my_password)){return request->requestAuthentication();}

Simply remove this line to solve the problem... If it helps?
I'm looking for another solution to protect access to the page... :)

@Airwolf1979
Copy link

android phone did not want to connect, fixed by adding the port 80, 192.168.4.1:80

@ktrzeciaknubisa
Copy link

In my case ESP32 module was constantly restarting when I was accessing the web server via mobile device (android)

My setup was simple:

server.serveStatic("/", LittleFS, "/").setDefaultFile("/index.html");

but apparently I lacked the onNotFound() method, as @zekageri mentioned.
Once I added it, my ESP stopped restarting when accessing from my phone.

server.onNotFound([](AsyncWebServerRequest *request) {
    AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/notFound.html", "text/html");
    request->send(response);
});

@ktrzeciaknubisa
Copy link

ktrzeciaknubisa commented Dec 28, 2023

Actually it did not help - I was too early.
It worked couple of times, but then it broke again (Arduino crashes when accessing the web server from android mobile).

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

No branches or pull requests

9 participants