I'm using this library to send data from a pico to my websocket server. After exactly 17 messages, it stops sending any data. The loop still runs and I can see the payload being printed to the console, but no more messages are received by the server and nothing logged in the browser console despite having console.log() for the message.
Things i've tried:
Disconnect: i get connect/disconnect messages in the websocker server (Django Channels) console. the socket stays connected (i.e. no disconnect message)
Server issue: the messages work fine when i run an equivalent script in Python3 on my PC, so I'm pretty sure its directly related to the uwebsockets library
Too many messages at one time: tried increasing the sleep(1) to sleep(10) to see if I was overloading the socket, but same issue -- exactly 17 messages
Out of memory: using gc.mem_free() to check free memory, I still have 149k bytes after the 17th message, so I'm pretty sure it's not a memory issue.
Any ideas on what could be stopping the websocket messages from being sent?
main.py:
import ujson
import utime
import uwebsockets.client as client
# wifi connect
wlan = WLAN(STA_IF)
wlan.active(True)
wlan.connect("ssid", "password")
while not wlan.isconnected():
pass
print("Connected to Wifi!")
with client.connect("ws://192.168.0.120:8000/ws/pico/") as ws:
for data in range(900, 7000, 100): #loop to send data += 100
payload = {
"data": data,
"timestamp": 2.5,
}
ws.send(ujson.dumps(payload)) #doesn't seem to actually send after 17 messages (when data == 2500 is last message sent, data == 2600 not sent)
print(payload) #continues to loop correctly (i.e. can see data == 2600 and higher being calculated in the loop)
utime.sleep(1)
I'm using this library to send data from a pico to my websocket server. After exactly 17 messages, it stops sending any data. The loop still runs and I can see the payload being printed to the console, but no more messages are received by the server and nothing logged in the browser console despite having console.log() for the message.
Things i've tried:
Disconnect: i get connect/disconnect messages in the websocker server (Django Channels) console. the socket stays connected (i.e. no disconnect message)
Server issue: the messages work fine when i run an equivalent script in Python3 on my PC, so I'm pretty sure its directly related to the uwebsockets library
Too many messages at one time: tried increasing the sleep(1) to sleep(10) to see if I was overloading the socket, but same issue -- exactly 17 messages
Out of memory: using gc.mem_free() to check free memory, I still have 149k bytes after the 17th message, so I'm pretty sure it's not a memory issue.
Any ideas on what could be stopping the websocket messages from being sent?
main.py: