Simple php & Python script to upload Tempest data to Windy

Hi,

I am using the following php script to grab data from my WeatherFlow Tempest station and then successfully upload them to Windy.com.
A cron job is used to run it every 5 minutes.
No additional weather software is needed.

Enjoy,
Kostas

/*
 * This php script grabs data from a WeatherFlow Tempest station and 
 * uploads them to Windy.com.
 * Use a cron job to run it every 5 minutes.
 * No additional weather software is needed.
 */

// Download data from WeatherFlow Tempest station (use your own Token)
$url = 'https://swd.weatherflow.com/swd/rest/observations/station/your-own-station-id?token=XXXXXXXXXXXX';

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);

// Decode data so they can be used
$data = json_decode($data);

// Calculate variables
$ts = urlencode($data->obs[0]->timestamp);
$temp = urlencode($data->obs[0]->air_temperature);
$wind = urlencode($data->obs[0]->wind_avg);
$winddir = urlencode($data->obs[0]->wind_direction);
$gust = urlencode($data->obs[0]->wind_gust);
$rh = urlencode($data->obs[0]->relative_humidity);
$dewpoint =  urlencode($data->obs[0]->dew_point);
$mbar = urlencode($data->obs[0]->barometric_pressure);
$precip = urlencode($data->obs[0]->precip);
$uv = urlencode($data->obs[0]->uv);


// Upload data to Windy.com (use your own Windy API-KEY)
$url3 = "https://stations.windy.com/pws/update/API-KEY?winddir=$winddir&wind=$wind&gust=$gust&temp=$temp&precip=$precip&mbar=$mbar&dewpoint=$dewpoint&rh=$rh&uv=$uv";

//var_dump($url3);   //test only

$curl3 = curl_init();
curl_setopt($curl3, CURLOPT_URL, $url3);
curl_setopt($curl3, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl3, CURLOPT_HEADER, false);
$data3 = curl_exec($curl3);
curl_close($curl3);

//var_dump($data3);   //test only
2 Likes

Didn’t know Windy had this option. Nice. I just threw together a python version, because why not?

#!/usr/bin/python3

import requests

windyKey = "Your windy key"
tempestKey = "your tempest key"
device_id = "your device id"

tempestURL = "https://swd.weatherflow.com/swd/rest/observations/?device_id={}&token={}".format(device_id, tempestKey)

r = requests.get(url = tempestURL)
data = r.json()
for d in data['obs']:
    wind=d[2]
    temp = d[7]
    windDir = d[4]
    gust = d[3]
    rh = d[8]
    mbar = d[6]
    precip = d[12]
    uv = d[10]

print(wind)
print(temp)
print(windDir)
print(gust)
print(rh)
print(mbar)
print(precip)
print(uv)


windyURL = "https://stations.windy.com/pws/update/{}?wind={}&temp={}&windDir={}&gust={}&rh={}&mbar={}&precip={}&uv={}".format(windyKey, wind, temp, windDir, gust, rh, mbar, precip, uv)

r = requests.get(url=windyURL)
print(r.status_code)
1 Like

Nice!
My next to-do list item: to learn Python :slight_smile:

Best regards,
Kostas

2 Likes