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

Errors using ap mode. #5

Open
beyonlo opened this issue May 19, 2022 · 10 comments
Open

Errors using ap mode. #5

beyonlo opened this issue May 19, 2022 · 10 comments

Comments

@beyonlo
Copy link

beyonlo commented May 19, 2022

Hello, all works fine when used by net (sta) mode - the default mode. But in the ap mode, sometimes some errors happen. I can't tell you exactly how to reproduce that errors because sometimes works and sometimes do not works.

I just used ap mode in this way:

from controllers import net, ap

ap.config(essid='APTEST')
ap.config(max_clients=5)
ap.active(True)
time.sleep(2)
print(ap.ifconfig())
print('AP configured.')

Ps: sometimes using more than one browser simultaneously, but the same test was done with net (sta) mode and no errors.

Error test 1:

b'Accept-Encoding: gzip, deflate\r\n'
b'Accept-Language: en-US,en;q=0.9,pt;q=0.8\r\n'
Handling: ["CMD","send_message",[""]]
route: /
Route found?: True
Handling: ["CMD","send_message",[""]]
b'GET /static/img1.jpg HTTP/1.1\r\n'
b'Host: 192.168.4.1\r\n'
unregister
b'Connection: keep-alive\r\n'
Task exception wasn't retrieved
future: <Task> coro= <generator object 'add_client' at 3fcac4c0>
Traceback (most recent call last):
  File "uasyncio/core.py", line 1, in run_until_complete
  File "ws.py", line 227, in add_client
OSError: Wifi Invalid Mode
Task exception wasn't retrieved
future: <Task> coro= <generator object 'run_fake_interface' at 3fca9300>
Traceback (most recent call last):
  File "uasyncio/core.py", line 1, in run_until_complete
  File "ws.py", line 138, in run_fake_interface
  File "ws.py", line 26, in send
  File "uasyncio/funcs.py", line 1, in gather
  File "uasyncio/core.py", line 1, in run_until_complete
  File "websockets/protocol.py", line 193, in send
  File "uasyncio/stream.py", line 1, in drain
OSError: [Errno 128] ENOTCONN
b'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36\r\n'
b'GET /static/jquery.js HTTP/1.1\r\n'
b'Accept: image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8\r\n'
b'Host: 192.168.4.1\r\n'
b'Referer: http://192.168.4.1/\r\n'
b'Connection: keep-alive\r\n'

Error test 2:

Route found?: True
b'Connection: keep-alive\r\n'
b'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36\r\n'
b'Accept: */*\r\n'
b'Referer: http://192.168.4.1/\r\n'
b'Accept-Encoding: gzip, deflate\r\n'
b'Accept-Language: en-US,en;q=0.9,pt;q=0.8\r\n'
route: /static/jquery.js
Route found?: True
Client Connection to b'/'
register
Handling: ["GET","wifi",[]]
Handling: ["CMD","hal",[]]
Handling: ["CMD","start_interface",[]]
Task exception wasn't retrieved
future: <Task> coro= <generator object 'run_fake_interface' at 3fca69b0>
StopIteration: 
Task exception wasn't retrieved
future: <Task> coro= <generator object 'add_client' at 3fca9850>
StopIteration: 
Task exception wasn't retrieved
future: <Task> coro= <generator object '_serve' at 3fca71d0>
StopIteration: 

I'm using ESP32-S3 with MicroPython 1.18.

Any idea what is the problem?

Thank you!

@marcidy
Copy link
Owner

marcidy commented May 19, 2022

i use AP mode and have no issues but i have not testined v1.18. can you try v1.17 or really anything earlier to see if it's still an issue?

What are you using to connect to the AP? e.g. phone, operating system, browser, etc. I have real issues with iOS devices and generally don't use them. They are very user friendly but not dev friendly.

Something else to try is to just connect to the AP with the device and see if you eventually disconnect.

basically im not sure, and cannot test with v1.18 right now to rule it out, so at a minimum it would be v. helpful to try a diff version.

@beyonlo
Copy link
Author

beyonlo commented May 20, 2022

Hi @marcidy

i use AP mode and have no issues but i have not testined v1.18. can you try v1.17 or really anything earlier to see if it's still an issue?

Yes, sure. Tomorrow I will to do all that tests, on MicroPython 1.17, 1.16 and 1.15 to check if there are differents results/behaviour.

What are you using to connect to the AP? e.g. phone, operating system, browser, etc. I have real issues with iOS devices and generally don't use them. They are very user friendly but not dev friendly.

ESP32-S3 running this project in ap mode (192.168.4.1) with this clients connected:
a) Chromium Version 101.0.4951.64 (Official Build) snap (64-bit) on the Notebook running Ubuntu 20.4;
a.1) IP received from ap: 192.168.4.3.

b) Chrome (default version) on Smartphone MotoG 6 Plus running Android 9;
b.1) IP received from ap: 192.168.4.2.

Something else to try is to just connect to the AP with the device and see if you eventually disconnect.

I'm sorry, I did not understand very well what you proposed above, Who are the AP and device?

AP -> ESP32-S3 running in AP mode?
device -> a smartphone connected to ESP32-S3 (that are running AP mode)?
If yes, I did that, and smartphone after connected to ESP32-S3 in AP mode, WiFi never disconnect. I was running a ping in smartphone reaching to ESP32-S3 ap (192.168.4.1) and ping never stopped.

If i got it wrong, please tell me exactly how you would like that I run the test.

basically im not sure, and cannot test with v1.18 right now to rule it out, so at a minimum it would be v. helpful to try a diff version.

No problem, I will return to you with tests using the MicroPython versions < 1.18.

Thank you very much!

@marcidy
Copy link
Owner

marcidy commented May 20, 2022 via email

@beyonlo
Copy link
Author

beyonlo commented May 20, 2022

@marcidy Hello!

I did that tests on MicroPython versions 1.15, 1.16, 1.17 and 1.18, using the ESP32 and all versions show erros on ap mode. I do not used the ESP32-S3 for this tests, because ESP32-S3 has no old versions of MicroPython, but the results was the same between ESP32 and ESP32-S3.

The mostly common error (Error 1) is very easy to reproduce. What do you need to do is just to connect to ESP32 running ap mode, with the smartphone or notebook, open website on the IP 192.168.4.1, and after that page is loaded (without error), just reload the page on the browser, and the Error 1 will show on the terminal, as follow:

Error 1:

b'Accept-Encoding: gzip, deflate\r\n'
b'Accept-Language: en-US,en;q=0.9,pt-BR;q=0.8,pt;q=0.7\r\n'
route: /
Route found?: True
unregister
Task exception wasn't retrieved
future: <Task> coro= <generator object 'add_client' at 3fcaad90>
Traceback (most recent call last):
  File "uasyncio/core.py", line 1, in run_until_complete
  File "ws.py", line 214, in add_client
OSError: Wifi Invalid Mode
b'GET /static/jquery.js HTTP/1.1\r\n'

Others errors happen without much effort to reproduce, doing: stop/start fake interface, send messages, reload page, sometimes using more than one device connected, etc.

Error 2:

b'Accept-Language: en-US,en;q=0.9,pt;q=0.8\r\n'
route: /static/jquery.js
Route found?: True
Task exception wasn't retrieved
future: <Task> coro= <generator object 'server' at 3f817ea0>
Traceback (most recent call last):
  File "uasyncio/core.py", line 1, in run_until_complete
  File "http/web.py", line 75, in server
  File "http/web.py", line 17, in _func
  File "http/web.py", line 42, in send_file
  File "uasyncio/stream.py", line 1, in drain
OSError: [Errno 104] ECONNRESET
Client Connection to b'/'
register
Handling: ["GET","wifi",[]]

Error 3:

Handling: ["CMD","hal",[]]
b''
Task exception wasn't retrieved
future: <Task> coro= <generator object 'server' at 3f821c30>
Traceback (most recent call last):
  File "uasyncio/core.py", line 1, in run_until_complete
  File "http/web.py", line 60, in server
ValueError: need more than 1 values to unpack
Task exception wasn't retrieved
future: <Task> coro= <generator object '_connect' at 3f821f40>
Traceback (most recent call last):
  File "uasyncio/core.py", line 1, in run_until_complete
  File "websockets/server.py", line 67, in _connect
  File "websockets/server.py", line 32, in connect
ValueError: need more than 1 values to unpack
b'GET / HTTP/1.1\r\n'
b'Host: 192.168.4.1\r\n'
b'Connection: keep-alive\r\n'

@beyonlo
Copy link
Author

beyonlo commented May 25, 2022

@marcidy Hello!

Did you take a look about that errors on ap mode?

Thank you in advance!

@beyonlo
Copy link
Author

beyonlo commented Aug 2, 2022

Hello @marcidy

Sorry, I think you've been busy lately. But I would like to know if you can to manage to check these errors?

Thank you in advance!

@marcidy
Copy link
Owner

marcidy commented Aug 19, 2022

Error 1 OSError: Wifi Invalid Mode
This can occur when reconnecting too quickly or when the interface is currently already connecting. It can happen when doing soft-resets for example, as opposed to hard resets. I don't have an S3 so it's hard to test that specifically, but i have seen it. It shouldn't be occuring, period, and is a problem with micropython. It might benefit from a rewrite i just submitted on the wss branch.

Error 2 will occur when the network connection is lost, dropped. I can't really control the networking. I can't take responsibility for making wifi connections robust. I can't tell WHY the connections drop, for example. Dealing with networking issues is outside the scope of this project, though, and i cannot help for hardware i dont have.

Error 3 looks like it was a malformed request line. That probably killed the task but another one should have launched on the next connection. Did the webserver still work? I suspect it did, i don't think i need to handle every error like that. I threw a try/except around it and closed the socket on the new implementation.

I have re-written a significant amount to turn this repo more into an example and split off the tools. It's not 100% don't yet, but you can look at the work in progress in the "wss" branch. There's an example of more robust making of a wifi connection on controllers.py on that branch.

The actual websockets and http server live in different repos now, noted in the README on the wss branch. I'm going to make those sub-modules of this repo so you wont have to manually copy them into the example, but they will live separately as individual tools. I should finish that tomorrow and this repo will look different. The tools are the same, though i added some tests for the websockets.

@beyonlo
Copy link
Author

beyonlo commented Aug 19, 2022

Hello @marcidy

Error 3 looks like it was a malformed request line. That probably killed the task but another one should have launched on the next connection. Did the webserver still work?

Yes, the HTTP Server still working when all that problems happen, just the WebSocket stop.

I have re-written a significant amount to turn this repo more into an example and split off the tools. It's not 100% don't yet, but you can look at the work in progress in the "wss" branch. There's an example of more robust making of a wifi connection on controllers.py on that branch.

The actual websockets and http server live in different repos now, noted in the README on the wss branch. I'm going to make those sub-modules of this repo so you wont have to manually copy them into the example, but they will live separately as individual tools. I should finish that tomorrow and this repo will look different. The tools are the same, though i added some tests for the websockets.

That's a great news :)

@marcidy
Copy link
Owner

marcidy commented Aug 19, 2022

Yes, the HTTP Server still working when all that problems happen, just the WebSocket stop.

Hmm, ok i thought it was the http server throwing the error. Well, i protected that one anyways. I see it's actually the same issue in the websocket server. It's also wrong it crashed the whole thing rather than just that connection. I'll protect the request parsing and see if I can rework it so errors don't take down the server.

FYI The repo is now up to date on the main branch. It's a significant number of changes, and i plan to add better documentation, probably targetting readthedocs.

@beyonlo
Copy link
Author

beyonlo commented Aug 22, 2022

Hi @marcidy

Hmm, ok i thought it was the http server throwing the error. Well, i protected that one anyways. I see it's actually the same issue in the websocket server. It's also wrong it crashed the whole thing rather than just that connection. I'll protect the request parsing and see if I can rework it so errors don't take down the server.

Now thinking better about it, I'm not sure if it is the WebSocket or the HTTP Server - was a long time ago. I just remember that something stopped to works and was need to restart the entire example. But I can to test again!

FYI The repo is now up to date on the main branch. It's a significant number of changes, and i plan to add better documentation, probably targetting readthedocs.

Great, I will to test this new version!

Thank you very much!

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

2 participants