Open philippebourcier opened 1 year ago
I switched to a nightly build of micropython (official) and now I don't need to comment the 3 socket settings... However, I am still blocked at WS ACCEPT. 🤷♂️
Hi @philippebourcier and thank you for using this web server 👍🏻
Well, do you have trying the example with main.py file ? So, to correctly receive websocket message, you must to set callback functions in the OnWebSocketAccepted handler. Example:
def OnWebSocketAccepted(microWebSrv2, webSocket) :
print('WebSocket accepted:')
webSocket.OnTextMessage = OnWebSocketTextMsg
#webSocket.OnBinaryMessage = OnWebSocketBinaryMsg
#webSocket.OnClosed = OnWebSocketClosed
def OnWebSocketTextMsg(webSocket, msg) :
print('WebSocket text message: %s' % msg)
wsMod.OnWebSocketAccepted = OnWebSocketAccepted
Also, do you have checked if you can receive a msg sent by the server to your javascript? Or do you think that the problem come from XAsyncSocket lib on your pico board?
OK, looks like I had copied a bad example (SendText vs SendTextMessage, etc. 🤦♂️)... 🤷♂️ Now everything works fine. However, I am not really convinced in terms of stability and latency seems a bit high. 😬
def OnWebSocketAccepted(microWebSrv2, webSocket) :
webSocket.OnTextMessage = OnWebSocketTextMsg
def OnWebSocketTextMsg(webSocket, msg) :
webSocket.SendTextMessage(msg)
mws = MicroWebSrv2()
mws.BindAddress = ('0.0.0.0',80)
mws.SetEmbeddedConfig()
wsMod = MicroWebSrv2.LoadModule('WebSockets')
wsMod.OnWebSocketAccepted = OnWebSocketAccepted
mws.StartManaged()
while True: sleep(1)
mws.Stop()
When the browser idles, the websocket server becomes unavailable (socket seems closed)... Is there something to run to clear idle/unused connections and/or relaunch the server automatically ?
You mean that when the browser stays connected with a javascript websocket that doesn't transmit, the server on the card doesn't accept other websockets? I'm not sure I understand in fact.
There are many parameters that can be configured indeed, I have to understand your problem because all the interactions with the sockets in the server are managed by my XAsyncSockets lib (with event management, buffers, concurrency and parralelism).
I am trying to get websockets to work on a W5500-EVB-Pico. I need Ethernet (vs WiFi), because it will be for a low-latency project where I'll need
In XAsyncSockets.py, I had to comment the following 3 lines (🤷♂️) :
At this point, HTTP works just fine...
Then, I wrote a simple test script for the ws client (tested succesfully on an ESP-32) :
However, on the console I see the accept, but it seems the code isn't able to detect it's a text or binary input (or something else is going wrong)... MWS2-DEBUG> From 192.168.98.11:80 GET / >> [101] Switching Protocols MWS2-INFO> WebSocket accepted from 192.168.98.11:80. WS ACCEPT
==> After receiving empty response I get a "Connection reset by peer" on the client side...
If I try again, same result : MWS2-DEBUG> From 192.168.98.11:80 GET / >> [101] Switching Protocols MWS2-INFO> WebSocket accepted from 192.168.98.11:80. WS ACCEPT
Anyone achieved to get WebSockets working on RP2040 ?
@jczic, I can lend you a W5500-EVB-Pico if you want to test it.