Api update intervals

This is what happens.

Establish a web socket with the WeatherFlow server.
Subscribe to events.
On data received, parse the data and store it in MySQL.

That being said, there is a LOT of code involved to do each step.

Here is some sample data received via the socket.

{“status”:{“status_code”:0,“status_message”:“SUCCESS”},“device_id”:5590,“type”:“obs_sky”,“source”:“cache”,“summary”:{“precip_total_1h”:0.0,“precip_total_24h”:0.0,“precip_high_24h”:0.0},“obs”:[[1511715825,null,1,0,0.31,0.56,0.89,53,3.17,1,183,0]]}
{“status”:{“status_code”:0,“status_message”:“SUCCESS”},“device_id”:3337,“type”:“obs_air”,“source”:“cache”,“summary”:{“pressure_trend”:“steady”,“pressure_high_24h”:829.4,“pressure_low_24h”:825.7,“strike_count_3h”:0},“obs”:[[1511715832,828.9,12.4,42,0,0,3.05,1]]}
{“type”:“ack”,“id”:“SK-00007032”}
{“type”:“ack”,“id”:“SK-00007032_rwd”}
{“type”:“ack”,“id”:“AR-00005119”}
{“device_id”:5590,“serial_number”:“SK-00007032”,“type”:“rapid_wind”,“hub_sn”:“HB-00004516”,“ob”:[1511715850,0.72,77]}
{“device_id”:5172,“source”:“mqtt”,“serial_number”:“SK-00007419”,“type”:“evt_precip”,“hub_sn”:“HB-00001483”,“evt”:[1510542299]}
{“device_id”:2356,“source”:“mqtt”,“serial_number”:“AR-00006577”,“type”:“evt_strike”,“hub_sn”:“HB-00000666”,“evt”:[1510607208,1,41525]}

{“summary”:{“precip_total_1h”:0.0,“precip_total_24h”:0.0,“precip_high_24h”:0.0},“serial_number”:“SK-00007032”,“hub_sn”:“HB-00004516”,“type”:“obs_sky”,“source”:“mqtt”,“obs”:[[1511715884,null,1,0.0,0.4,0.56,1.16,51,3.17,1,190,0.0]],“device_id”:5590,“firmware_revision”:26}
{“summary”:{“pressure_trend”:“steady”,“pressure_high_24h”:829.4,“pressure_low_24h”:825.7,“strike_count_3h”:0},“serial_number”:“AR-00005119”,“hub_sn”:“HB-00004516”,“type”:“obs_air”,“source”:“mqtt”,“obs”:[[1511715892,828.9,12.5,42,0,0,3.05,1]],“device_id”:3337,“firmware_revision”:20}

This data has to be parsed and put into variables, which in turn are stored in the proper table. I store the data in the units it comes in and later convert the data to different units.

You are doing a lot more than just getting data from WeatherFlow so I’m not sure how much help I can be.

1 Like

ok no problem here is what im using and parsing every 3 seconds

{“device_id”:5961,“serial_number”:“SK-00004497”,“type”:“rapid_wind”,“hub_sn”:“HB-00001146”,“ob”:[1515272942,1.65,94]}

code

function initWS() {
var socket = new WebSocket(“ws://ws.weatherflow.com/swd/data?api_key=xxxxxx”),
container = $("#container")
socket.onopen = function() {
container.append("");
};
socket.onmessage = function (e) {
document.getElementById(“log”).innerHTML = e.data;

            }

// Connection opened send to command to weatherflow listen_rapid_start device_id":5961
socket.addEventListener(‘open’, function (event) {
socket.send(’{“type”:“listen_rapid_start”,“device_id”:5961}’);
return socket;
});

That looks correct. Are you actually getting the data?

If yes, then you are half way there.

1 Like

yes every three seconds I’ve been stuck at that point for three weeks on getting the data to dump to a file I am neither able to work out how to get the data dumped to text file or found any solution ,I’ve read and tried to understand every write up on websocket I can find … most are all talking about chat and video streaming benefits but ill get there sooner or later

{“device_id”:5961,“serial_number”:“SK-00004497”,“type”:“rapid_wind”,“hub_sn”:“HB-00001146”,“ob”:[1515272942,1.65,94]}

bold is the wind speed and wind direction

in the screenshot you can see the time is at three second intervals

ws3sec

1 Like

Okay, I understand more now.

How is the above getting to the file you are reading?

1 Like

code in a single php file
vx

1 Like

What are you using to write the file ‘MBrealtimeupload.txt’ ?

1 Like

meteobridge has a built in function to send data direct to the template

in the file meteobridge calls and then we use file_put_contents

$filename = “MBrealtimeupload.txt”;
if( isset($_GET[‘d’]) ) {
$string=$_GET[‘d’];
file_put_contents($filename, $string);
header(‘Content-Type: text/plain’);
echo “success”;
}

Copy that code to write the JSON code to the file you want.

$filename = “MBrealtimeupload.txt”;
$string = [received JSON string];
file_put_contents($filename, $string);
header(‘Content-Type: text/plain’);
echo “success”;
}

The only question is; What format do you need to write the data to the file?"

1 Like

im lost ? which file I don’t need to change anything in the meteobridge files im more interested in resolving websocket for weather flow or re you saying put this into the websocket file and use a different filename.txt

1 Like

Use

var obj = JSON.parse(string);

and write the obj data to SQL

INSERT INTO [table]
(timestamp, speed, direction)
VALUES
(obj.ob[0], obj.ob[1], obj.ob[2])

1 Like

Ok Gary I see where you going I’ll look at it tomorrow evening it’s 1:30am now and I have to take the wife shopping tomorrow which I’m dreading looking at a 1000s pairs of shoes… probably need a beer with my breakfast to numb the feeling…thanks we will get there sooner or later…brian

1 Like

Mummmm. Beer.

I hoped I’ve helped. If so please use the :heart: to like my posts.

Gary

1 Like

Hi, Brian,

Have you made progress toward your goal?

1 Like

no preoccupied on other things , I will get to it but need to allocate some dedicated time.

Brian

For those of us that don’t speak “programming” how can I get access to my historical data? Is it possible through your dashboard on the web based WF account?

What do you mean by access?
The API can give you access to the raw data:
https://weatherflow.github.io/SmartWeather/api/swagger/

Do you mean graphs using your stations data?

Regards

That was exactly what I was looking for. Now I just need to know how to download it.

Thanks a lot!

There are ways to get the data or have an application get the data foe you.

WFArchive has this built in.

You can get the data yourself by using the WeatherFlow REST API. Here is an example:

https://swd.weatherflow.com/swd/rest/observations/device/11973?day_offset=0&api_key=a8f5dbda-af0a-4b57-99b9-f10baa88f27b

where 11973 is the device_id of your Air or Sky and day_offset the the UTC day back you want. 0 = today, 1 = yesterday, etc.

Once you download the data, it is up to you how you handle it.

2 Likes

Thanks a lot @GaryFunk for the helpful info and all the contribute to this forum!