WS Listen, seems to hang

It looks like you may have based your code off the snippet I shared here: Basic Python websockets example to retrieve current Tempest data. If that is the case, the code I shared was not designed to receive multiple messages from the Websocket, and the same is true in the code you shared. Once you have sent the listen command, ws.recv() is only called once, and therefore you will only receive a single message.

If you want to remain connected and listen to new messages continuously, you need to wrap ws.recv() inside a while loop. Something like this will work (don’t forget to enter values for the personal_token and tempest_ID):

from websocket import create_connection

personal_token = ' '
tempest_ID = ' '

print('Opening Websocket connection...')
ws = create_connection('wss://ws.weatherflow.com/swd/data?api_key=' + personal_token)
result =  ws.recv()
print("Received '%s'" % result)
print('')

print('Listening to Tempest endpoint...')
ws.send('{"type":"listen_start",' + ' "device_id":' + tempest_ID + ', "id":"Tempest"}')
result =  ws.recv()
print("Received '%s'" % result)
print('')

print('Receiving Tempest data...')
while True:
    result =  ws.recv()
    print("Received '%s'" % result)
    print('')
1 Like