January 08, 2024

Install Weather34 with WeatherLink, v2 API

Updated 2024-01-08 OK with Bookworm 64 bit, PHP 8.2 !

This post is an update from a former post which handles on how to set up a weather WEB-site with data from Davis Weather Link(WL) but here adapted to the latest WL API v2.

Any product that reports weather data to WL can be used as a source for this weather template.

This is made without additional software such as Cumulus, Weather display or the Meteobridge product.

Intro
An example of a WeatherLink, v2 API, dashboard with Node-Red is found here.

The template Weather34(W34) was built so it could get online data from different PWS solutions which should update their respective online files at the W34 web-server. In our case we pull JSON data direct from the WL site, via the WL V2 API
and update an online file, type "cumulus", on the W34 web-server. 

This post will cover an install on a Raspberry Pi but it could be any platform running a WEB server, Apache is used here, and PHP 8.x.

Alternative
An alternative, which Ken True recommends, is this weather dashboard which also supports other hardware than Davis. But still I think the W34 GUI is the best.

Prerequisites
Before You start You must ensure that;
  • You have a registered account at Davis Weatherlinksite(WL)
    • PWS data is pushed to WL
    • PWS data is retrieved from WL
    • PWS data is forwarded to Weather Underground from WL
      • Register in WL "Manage devices => Share & Uploads"
  • You have a registered account at Weather Underground(WU)
    • Forecasts could be retrieved from WU
    • PWS data is pushed to WU
    • Historic PWS data is retrieved from WU
Metar aviation weather data is used for "Current conditions" module 7.
  • Register an account at Checkwx
    • Aviation weather data are retrieved from Checkwx
If you want a forecast alternativ to WU(English)
  • Register an account at "pwsweather.com" Setup here.
    • Free API also available
WL API key/secret
To access weather data from WeatherLink(WL) you have to get an API key and an API Secret. These are retrieved from the DWL site after You logged on.

WU API key
If You are supplying WU with Your PWS data You will get a API key for the new API without cost. You can then get a 5 days forecast and historical data, day/month, which is supported with the W34 version issued 2019-05-21.


RPi OS
To start up fresh on the RPi You can follow the instructions here where You install Apache2 and PHP 8.x with Raspberry Pi OS . You must have the "curl" module/extension installed !

Dark Sky
The Dark Sky(DS) api is not available anymore so please skip all settings which refers to DS.

Source and support
The current version of W34 is supported by Ken True. There is a Forum, and a GitHub repository.

Installation
Update RPi OS
Installation is referring to a RPi with hostname "pws01".
Logged on to RPi, via ssh/terminal, and user "pi", start with an OS update

sudo apt update && sudo apt full-upgrade -y && sudo apt clean

Install W34
After that download the W34 source to "pi" home folder

wget https://github.com/ktrue/CU-HWS/archive/master.zip

(Another way, if Git is installed on the RPi, is
git clone https://github.com/ktrue/CU-HWS.git)

Unzip the file "unzip master.zip"

Check that a folder with name "CU-HWS-master" is created and it contains several folders and files with the extension ".php". Delete the zip file, "rm master.zip", and then create a new folder

mkdir CU-HWS-master/add_on

Install WL check and the pull application
Download from Github the program that retrieves data from WL

wget https://github.com/MatsA/weatherlink-data-pull_v2/archive/refs/heads/main.zip

then unzip "unzip main.zip" and delete the zip file "rm main.zip".

Copy 4 files to the "add_on" folder(The online file "realtime.txt" will be created by the program)

cp weatherlink-data-pull_v2-main/{cumulusdata.php,realtime.templ,wlauth.txt,wlcheck.php} ~/CU-HWS-master/add_on/


Move, and rename, the folder "CU-HWS-master" to the Apache document root with

sudo mv CU-HWS-master /var/www/html/pws

The W34 application will change local files, updates from WU, DS and WL, and therefore we have to take care of authority. The Apache servers default user/group is www-dataso the following command will handle this

sudo chown -R www-data:www-data /var/www/html/pws/

Check access to WL
With the app wlcheck.php we are now going to check that we can retrieve data from WL.

Execute the app with http://pws01/pws/add_on/wlcheck.php in a WEB-browser.

This will show the content of file "wlauth.txt" which contains, an example, API key, API secret and Station ID in one record. The fields are separated with a comma(,).

Use your credentials, key/secret, you got from the WL site and paste them into the file with 

sudo nano /var/www/html/pws/add_on/wlauth.txt

(Don't change the last field, Station ID)
Verify the information, in the file, with the above URL.

Now we are going to check that the communication with the WL site is OK and also retrieve the Station ID. Use the following URL in the browser

http://pws01/pws/add_on/wlcheck.php?data=stations

After executing the URL the application will retrieve your Station ID, from WL, and update the "wlauth.txt" file. The content of the file is shown at the last row. 

No we can create the URL which will get current station data from WL. Execute the URL

http://pws01/pws/add_on/wlcheck.php?data=current

And you will be shown a new URL which should be used in a new tab in your browser.

W34 setup
Continue with the setup, URL

http://pws01/pws/easyweathersetup.php No Password.

Set up the parameters for Your use case.  (Please don't use Dark Sky(DS), mentioned as a forecast source, cause the service is soon terminated)

In the section "Cumulus Software Path to Data file" choose 
  • "Data Type" => "cumulus" 
  • "Your Path to data file" => "add_on/realtime.txt" 
To check that the application is getting data from WL, execute with 

sudo php /var/www/html/pws/add_on/cumulusdata.php

and check in a WEB-browser 

http://pws01/pws/add_on/realtime.txt

or via ssh/terminal

cat /var/www/html/pws/add_on/realtime.txt

The date and time in the beginning of the file will tell if You succeed

Add a crontab record, as user "pi", using, crontab -e

*/5 * * * * sudo php /var/www/html/pws/add_on/cumulusdata.php

This job will get the data, every 5 minutes, from WL and create/update the online file "realtime.txt"

You can now check the application with URL

http://pws01/pws/

and confirm that everything is working OK

Avoiding cron job ?  Check this

Please note;
  • Trend values, temperature and pressure, DarkSky forecast and Last Hour Rain can take up to 2 hours before they are OK.
  • Wind run, daily max wind, yesterday's rainfall, and some other data, will be correct after a day shift
Update W34
When You update/replace W34 to a new version, save
  • ”settings1.php” file so You don't have to register all settings with "easyweathersetup.php" again. Allways run the "easyweathersetup.php" so a conversion could be done and check if there are new settings.
  • "menu.php" file if You have added own Menu rows
Tips and tricks
  • If You have problem with the W34 application the built in diagnose feature could help. URL http://pws01/pws/diags.php?show=info
  • Show W34 settings with URL http://pws01/pws/diags.php?show=settings
  • If You don't like the translation You could edit the specific file in /var/www/html/pws/languages/
  • WL is updated, at the most, once every minute so it's no use to run the Cron job more often
  • If You want to edit and change the W34 files, from Your Mac/PC, in the Apache server just add user "www-data" to Your Samba installation
  • Works with Bullseye and PHP 8.x !
Several stations on the same WL account ? 
The URL "http://pws01/pws/add_on/wlcheck.php?data=stations" will retrieve the "first" station and store it in "wlauth.txt". With several stations use the shown URL, execute it and check the generated json data to get the other stations. Then edit the file "wlauth.txt, manually, and update Station ID.

Sensor and data structure type !!
It could be that some of the data you are retrieving is missing due to that your source for the weather data is different than ours. (Vantage Pro2, sensor type 23, and data structure typ 2)
At this link you can check if there are any differences and if so you have to edit "cumulus data.php" and map to correct fields. In the source search for "Direct values".

Remarks
WL accounts
Please note that with the latest v2 API you will just get weather data, with a free account, every 15 minutes. The W34 application have a timeout, 300 seconds, where it sets the respective data window as "Offline". This could be changed editing the line 

<div class="updatedtime"><span><?php if(file_exists($livedata)&&time()- filemtime($livedata)>300)echo $offline. ..........

where you change  ">300" to ">1300", 22 minutes, in 
  • barometer.php
  • rainfall.php
  • temperature.php
  • windspeeddirection.php
Rate Limits
Doing tests it's possible that you exceed the rate limits of 300 API calls per hour, which will make that the "realtime.txt" file not will be updated.

Current conditions
Current conditions, "currentconditionsmetar34.php", is now updated and don't have any Dark Sky and hardware dependency.

11 comments:

  1. Hi, I was trying your how to but it appears I am stuck at

    'http://pws01/pws/add_on/wlcheck.php?data=stations'

    specifically, all that returns is

    'Selected to get stations'

    and nothing else, and the wlauth.txt file is not updated. any thoughts?

    ReplyDelete
    Replies
    1. Hi ! Nice you liked the post. Does the program "hang" or is it ended with the mentioned text ? At an error there should have been a text "Something wrong....." A quick way to see what's happening within the program is to use "echo" and "var_dump". As seen in the program I have used it my self to check. Just take away the "//" for selected code and run the program again.

      Delete
  2. I was able to figure it out, I had to go back to some of your earlier posts to get samba and apache working right. all good now!

    ReplyDelete
  3. however, I have tried the same on a 64-bit bookwork version and cannot get samba to work right, seems they have changed access abilities. boo

    ReplyDelete
    Replies
    1. OK, give me some days and I will try to recreate the problem and if so update the installation posts.

      Delete
  4. that's great! I have it working on a Bullseye setup as well, so I am still able to tinker. thanks again for all your help!

    ReplyDelete
    Replies
    1. Did a Weather34 install from scratch, Bookworm 64, including Samba and it just worked.... so hope you also can succeed with an updated install. Did some fine tuning, to the posts, but no actual change.

      Delete
  5. well I did a full install from scratch and now everything works as intended. Chalk it up to some unknown mistake on my part. Thanks again for all your help!

    ReplyDelete
    Replies
    1. OK, nice it worked and thanks for the feedback, appreciated ! 👍

      Delete

Feel free to leave a comment ! ... but due to a lot of spam comments I have to moderate them. Will reply ASAP !