Selecteer een pagina

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:

<?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());
 }

 mysql_close($con);
?>

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.

%d bloggers liken dit: