Retrieve data from weather station

Retrieve data from weather station

Earlier I wrote a blog post about connecting my TFA Nexus Pro to a QNAP or Synology NAS system in this article. In that article I explain how you can install a tool that works for most weather station based on the Hideki te923 chip like the TFA Nexus Pro, Mebus TE923, Irox pro, Honeywell TE923, MeteoScan Pro 923, Cresta 923 and perhaps others.

Now one of the neat things to do is of course actually read data from your weatherstation and put it into a MySQL database. But you can also put them into a RRD archive with rrdtool so you can easily create graphs from them with for instance cactii.

If you have not done so before please install MySQL and PHP on your NAS server.

You can do this for instance on a QNAP or Synology server by logging onto the console with SSH and entering the following commands:

ipkg update
ipkg install mysql
ipkg install php
ipkg install php-mysql

Next create the following database. You can do this from within the MySQL console or for instance with phpMyAdmin.

create database weatherdata;

Next create the table:

use weatherdata; 
CREATE TABLE `weatherdata` ( 
`timestamp` int(11) NOT NULL, 
`localtemp` float NOT NULL, 
`humidity` float NOT NULL, 
`temp1` float NOT NULL, 
`humidity1` float NOT NULL, 
`temp2` float NOT NULL, 
`humidity2` float NOT NULL, 
`temp3` float NOT NULL, 
`humidity3` float NOT NULL, 
`temp4` float NOT NULL, 
`humidity4` float NOT NULL, 
`temp5` float NOT NULL, 
`humidity5` float NOT NULL, 
`pressure` float NOT NULL, 
`uv` int(11) NOT NULL, 
`forecast` tinyint(1) NOT NULL, 
`storm` tinyint(1) NOT NULL, 
`wd` float NOT NULL, 
`ws` float NOT NULL, 
`wg` float NOT NULL, 
`wc` float NOT NULL, 
`rc` float NOT NULL, 
UNIQUE KEY `timestamp` (`timestamp`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Next make sure you have te923con placed in /opt/bin/ as explained in previous article:

And finally put the following script on your server. Preferably in for instance /opt/bin/weatherdata.php:


 exec("/opt/bin/te923con -i 0",$output);
 $weatherdata = spliti(":",$output[0]);
 $query = "INSERT INTO weatherdata VALUES(";
 foreach ($weatherdata as $value)
  $query .= "$value,";
 $query = trim($query,",");
 $query .= ");";

 $con =  mysql_connect('localhost','DBUSER','DBPASSWORD');
 if (!$con)
  die('Could not connect: ' . mysql_error());

 mysql_select_db("weatherdata", $con);

 if (!mysql_query($query,$con))
  die('Error: ' . mysql_error());


Make sure you change DBUSER and DBPASSWORD to match your login credentials for MySQL!

Next you can run this PHP script from your SSH console so the data is inserted in the MySQL database:

/opt/bin/php /opt/bin/weatherdata.php

If results are entered in the database you can add the script to the crontab:

# m h dom m dow cmd
*/30 * * * * /opt/bin/php /opt/bin/weatherdata.php

To run this script every 30 minutes.

Please note that this is just an example of how you can save data from your weather station to a MySQL database. It is not some form of a WEB interface that makes pretty graphs and lets you see historical data. But one could create such a web gui with this data inserted in the MySQL database.

5 thoughts on “Retrieve data from weather station

  1. Soszkin

    Hi, great guide. But how to plot collected data on website? How to get this data from mysql into web page?


    1. Hi,

      I did not have time to build a web page around the MySQL data just yet.

      But I decided to put this page already up as there are probably gifted programmers who can build their own page but perhaps do not know how to retrieve the data from their weatherstation.

  2. This week I’ve slowly started writing some scripts that graph stuff that is in the MySQL database.

    So far only graph of latest 24 hours of temperature / windchill and last 7 days of temperature / windchill exist.

    But at least it is a start 🙂

  3. Matthias

    Hi there 😉
    Great tut, but I don’t no how to add a crontab? I searched on google for two hours now, but couldn’t find a solution 🙁
    I can modify the crontab by “crontab -e” => but how can I add a job? How can I save the file? Thank you for a short answer 😉

Geef een reactie