Author Topic: Populating MySQL via the Ambient Weather REST API  (Read 4754 times)

0 Members and 1 Guest are viewing this topic.

Offline olsongt

  • Member
  • *
  • Posts: 2
Populating MySQL via the Ambient Weather REST API
« on: January 25, 2021, 06:54:37 PM »
I bought the Ambient WS-5000 station. I like it, but there's not a built in way to get the data to MySQL. The weatherbridge doesn't work with this station either. It reports to Ambient Weather among other services, so I wrote a php script to scrape my weather station data from Ambient using their rest API and upload it to MySQL. This script could be used for any weather station that reports to Ambient. I run it in my crontab on the server, so communication is server to server and it's pretty reliable. One's crontab settings dictate how often the script runs (Ambient API allows you to query 288 data sets). I update every 15 minutes(3 data sets for me), but it also depends on how often you upload to Ambient as to how frequently you may want to run the API query.

The script looks at the last record in the database and then queries the API for new data since then. Crontab jobs usually send output to the root email, so you can troubleshoot based on the text of the email if needed or just turn output off in crontab too(to avoid to many messages). Also, you need to make sure you have a MySQL database set up with a table with identically named fields to those that are on the Ambient site.

Disclaimer: I am a recreational coder and anyone should feel free to expand/change/correct on this code if they would like. With the proper settings, this script works for me...

Anyway, I hope this helps someone and let me know if I can help out. [tup]

https://gist.github.com/olsongt/1ff46eefcf83263b09cf5310609f14cb#file-aw2mysql-php

Offline MaineWaterLovers

  • Member
  • *
  • Posts: 2
    • North Redoubt
Re: Populating MySQL via the Ambient Weather REST API
« Reply #1 on: January 23, 2024, 02:56:23 PM »
Hello, looks like this has been resting here for a while. But I got an Ambient Weather 2902d for Christmas and have been pulling my hair out trying to get data into my local db. There were almost zero examples using the API on the internet. This script seems to be exactly what I needed. Thank you for posting!

 

anything