WS Listen, seems to hang

I am using the following in Python

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”:“2098388936”}’)
result = ws.recv()
print(“Received ‘%s’” % result)
print(’’)

It clearly opens the connection but when I send the listen command, after 10 minutes nothing is received.

Am I missing something?

That device id sure looks wrong to me. Has WF sold over 2 billion tempests ?

That number has a different meaning.

What is the value of tempest_ID?

Try this:

ws.send({“type”:“listen_start”,’
“device_id”:’ + tempest_ID + ‘,“id”:“2098388936”})

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

Got it thanks and yes I did base it off of your code

1 Like

Thank you, Peter…

1 Like

Sorry to butt in with a question from left field. Am I interpreting this code correctly when I ask: It appears to me that this is setting up a listening socket… this seems to imply that the device is sending data instead of reacting to a connection and sent data. Is this correct? Is the remote device (the weatherflow server) doing a push instead of the local device doing a pull, so to speak? If so, is there setup involved to make this happen?

Thank you!

The Hub transmits the data via UDP on the local network. That data is available for any device to listen to it.

Thank you Gary… out of curiosity, does the hub send the UDP packets or does the server at the weatherflow facility send the packets after communicating with the hub?

The hub sends the UDP packets. I had to tell my Wi-Fi access points to broadcast them so my Meteobridge and ArchiveWS on an RPi could receive them since they were not wired.

The code snippet I shared above creates a client connection to the WeatherFlow websocket server (different to UDP). Once the connection is set up, new messages are pushed automatically to the client by the remote server. There is no ongoing requirement for the client to issue data requests to the server. If you want the client to use a pull model instead, then the REST API is the place to go. For both the Websocket and REST API the data flow is:

Device (Tempest/Sky etc)Hub → (internet) → WeatherFlow server → (internet, push or pull) → Client

If you don’t want the internet to be involved at all, then instead you can listen for the UDP messages that are broadcast by the hub over the local network it is connected to. This is a push model similar to the Websocket. For UDP, the data flow is:

Device (Tempest/Sky etc)Hub → (local network, push) → Client

1 Like

Yeah, what he said. My apology. I don’t know why I thought UDP when this topic is for the web socket. Peter gave you the correct information.

1 Like

Wow! Good info!!! Thanks @peter and others! I have not used websockets. I’d like to try out these things described here!

1 Like

Please share what you have found to work.