I am new to WebSockets, but get the general concepts. I have a simple app where I am trying to use WebSockets rather than pulling from the API on an interval for updates. I am able to successfully open the connection, receive an ack on listen_start, and also receive one observation message back (which seems to have questionable data that doesn’t resemble current observations from my device - but, that is another story). What is odd is that from reading these forums, it seems like I should be receiving frequent messages as long as the connection is open. I am logging when the connection closes, which appears to be after about 10 minutes of inactivity, so I know it’s still open until that point. I have also tried listening for listen_rapid_start, and get an ack from that one too - but no subsequent messages at all. Is there something basic I am missing? I assumed I would be receiving frequent messages/updates. Thanks!
Without any code to look at it would be hard to determine the issue. Can you post your code? Make sure to remove any tokens or keys.
I can take a quick look at it to see if there is any problems.
Here is the relevant section of the code; please note that I only have one device with my station, and I believe it should be 366623. That said, I get nothing (not even an ack) if I use that ID. If I use my station ID (the line that isn’t commented), I get a single ack, and one obs message - but none of the data looks accurate, and also appears to never change.
const [messages, setMessages] = useState([]);
useEffect(() => {
// Establish WebSocket connection
const ws = new WebSocket("wss://ws.weatherflow.com/swd/data?token=redacted");
// Connection opened
ws.onopen = () => {
setConnectionStatus("Connected");
ws.send('{type:"listen_start",device_id:"151742",id:"obs"}');
//ws.send('{"type":"listen_rapid_start","device_id":366623,"id":"rapid_wind"}');
// 151742
console.log("WebSocket connection established.");
};
// Listen for messages
ws.onmessage = (event) => {
console.log("Message received:", event.data);
// Update messages
setMessages((prevMessages) => [...prevMessages, event.data]);
console.log("Messages:", messages)
};
// Handle errors
ws.onerror = (error) => {
console.error("WebSocket error:", error);
};
// Connection closed
ws.onclose = () => {
setConnectionStatus("Disconnected");
console.log("WebSocket connection closed.");
};
// Cleanup on component unmount
return () => {
ws.close();
};
}, []);
Here is the single message I receive after the ack:
Message received: {“status”:{"status_code":0,"status_message":"SUCCESS"},"device_id":151742,"type":"obs_st","summary":{"pressure_trend":"falling","strike_count_1h":0,"strike_count_3h":0,"precip_total_1h":0.0,"strike_last_dist":42,"strike_last_epoch":1734462175,"precip_accum_local_yesterday":0.0,"precip_accum_local_yesterday_final":0.0,"precip_analysis_type_yesterday":0,"feels_like":23.6,"heat_index":23.6,"wind_chill":23.6,"raining_minutes":[0,0,0,0,0,0,0,0,0,0,0,0],"dew_point":14.6,"wet_bulb_temperature":17.9,"wet_bulb_globe_temperature":22.1,"air_density":1.18707,"delta_t":5.7,"precip_minutes_local_day":0,"precip_minutes_local_yesterday":0},"obs":[[1734721130,0.1,0.9,1.9,13,3,1011.2,23.6,57,69695,3.22,580,0.0,0,0,0,2.78,1,0.0,0.0,0.0,0]]}
Thank you for any help you can provide.
Your code looks fine to me. The device id is actually 366624
and I ran it through my websocket tester and received obs just fine. Also note that the values are in specific units which you can find in the docs WeatherFlow Tempest API Websocket Reference
Let me know if that device id works.