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

No more messages sent after the 17th message #23

Open
arm358 opened this issue Feb 25, 2024 · 0 comments
Open

No more messages sent after the 17th message #23

arm358 opened this issue Feb 25, 2024 · 0 comments

Comments

@arm358
Copy link

arm358 commented Feb 25, 2024

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)
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

1 participant