Hi all,
I'm trying to send sensor measurement data from an ESP32 to a raspberry based server.
A test setup running on another computer with the complete python3 environment works like a charm. The minimal working example under python3 looks like this:
import websocket
ws = websocket.WebSocket()
ws.connect("ws://192.168.0.5:3000")
ws.send( data ... )
I like to achieve the same on the ESP32.
As part of the MicroPython installation on the ESP32 I found the "websocket" module. When I import the websocket module and try to run my example code it tells me that the module websocket has no attribute "WebSocket". So to me it seems that the websocket module in MicroPython is fairly limited.
Does someone have an idea what is the best way to feed data via websockets from the ESP32 to another server and might give me a hint?
Send data via websocket from ESP32 to server?
Re: Send data via websocket from ESP32 to server?
The builtin websocket module is completely undocumented and therefore useless.
I used Danni's MicroPython uwebsocket module without problems, see thread Minimal MicroPython uwebsockets.client that works on esp8266.
I used Danni's MicroPython uwebsocket module without problems, see thread Minimal MicroPython uwebsockets.client that works on esp8266.
Pico-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w
Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454
webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell
https://github.com/Hermann-SW/pico-w
Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454
webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell
Re: Send data via websocket from ESP32 to server?
Thank you!
I had to remove the "import logging" and all corresponding call in protocol.py and client.py since the module is not available. But then it works just fine!
I had to remove the "import logging" and all corresponding call in protocol.py and client.py since the module is not available. But then it works just fine!
Re: Send data via websocket from ESP32 to server?
Well, not quite
After a while my script crashes:
Traceback (most recent call last):
File "main.py", line 167, in <module>
File "uwebsockets/protocol.py", line 212, in send
File "uwebsockets/protocol.py", line 137, in write_frame
OSError: [Errno 104] ECONNRESET
After googling for a while it seems that I should regularly disconnect and reconnect to the server to avoid being kicked by the server. Is this the right approach? How would I explicitly disconnect from the server?
After a while my script crashes:
Traceback (most recent call last):
File "main.py", line 167, in <module>
File "uwebsockets/protocol.py", line 212, in send
File "uwebsockets/protocol.py", line 137, in write_frame
OSError: [Errno 104] ECONNRESET
After googling for a while it seems that I should regularly disconnect and reconnect to the server to avoid being kicked by the server. Is this the right approach? How would I explicitly disconnect from the server?
Re: Send data via websocket from ESP32 to server?
Ok, encapsulating the send statement with a try/except environment combined with a reconnect on connection loss works.
Re: Send data via websocket from ESP32 to server?
You don't have to do that, I took logging.py from micropython-lib github repo and all was fine:
https://github.com/micropython/micropyt ... logging.py
Pico-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w
Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454
webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell
https://github.com/Hermann-SW/pico-w
Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454
webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell