To start off this tutorial it is assumed that you have Weewx completely set up on another server with the weather station properly connected and reporting. This tutorial will be using a Master / Slave MYSQL database that is configured like my previous blog entry.

The purpose adding Mesowx into the mix was not to add another layer of complication into the mix, but to be able to dynamically display a dataset and to have the ability to focus in on a specific type of data or date. Mesowx allows for multiple ways to access the data and even a way to input data into your MYSQL database, but I found that to be unrealiable and frankly risky to open your server to that function. We will give the Mesowx user just enough privilage to read data from the MYSQL database table and that is it. This limits the access that is available to be compramised from a web facing function.

Step 1: Requirments

  • Raspberry Pi with Weewx Weather Station running
  • MYSQL configured and operating
  • Download Mesowx to server

If you do not have mesowx on your server log in and download it:

wget https://bitbucket.org/lirpa/mesowx/downloads/mesowx-0.4.0.tar.gz

Untar it:

tar -xvzf mesowx-0.4.0.tar.gz

Step 2: Configure Server

Now copy the important parts to a web accessible directory:

cp -R mesowx-0.4.0/web /var/www/html/meso
cd /var/www/html/meso

We need to add a user to our MYSQL database to allow mesowx to access the data. Log into the MYSQL database as root:

mysql -u root -p

CREATE USER 'mesowx'@'127.0.0.1' IDENTIFIED BY 'password';
CREATE DATABASE weewx_raw;
GRANT SELECT ON weewx.* TO 'mesowx'@'127.0.0.1';
GRANT SELECT ON weewx_raw.* TO 'mesowx'@'127.0.0.1';
FLUSH PRIVILEGES;

There are two config files that must be edited to insert your MYSQL credentials.

cp meso/include/config-example.json meso/include/config.json 
nano meso/include/config.json

You need to modify the dataSource sections and make it match your MYSQL database information

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
"dataSource" : {
    "weewx_mysql" : { // the data source ID
        "type" : "mysql",
        "host" : "localhost",
        "user" : "mesowx",
        "password" : "password",
        "database" : "weewx"
},
    "weewx_mysql2" : { // the data source ID
        "type" : "mysql",
        "host" : "localhost",
        "user" : "mesowx",
        "password" : "password",
        "database" : "weewx_raw"

    }
}

Change the config file to match what you used when you modified your MYSQL database. You should also change the section where it checks to see if updates are allowed to the database.

1
2
3
4
5
6
7
8
9
"update" : {
                // set 'allow' to true to allow this entity's data to be updated
                "allow" : false,
                // the securityKey that must be sent along with each request to update
                // it's recommended to generate a random key, i.e. 
                // http://www.random.org/strings/?num=1&len=20&digits=on&upperalpha=on&loweralpha=on&unique=on&format=html&rnd=new
                // An empty key is not allowed.
                "securityKey" : "123"
            }

Save and close the file.

To finish up on the server you need to copy or rename the last file.

cp js/Config-example.js js/Config.js

Step 3: Configure RaspberryPi

You now need to log onto you weather station RaspberryPi to configure it to use "raw" data. This allows your website to have data more frequently then the normal five minute update. The update time will depend on the weather station, but mine is 50 seconds. Add THIS FILE to your $WEEWX_HOME/bin/user/. The file that is supplied by Mesowx WILL NOT work. I found this file after searching for a long time online in the google groups forums. I can not find where I got it from to give credit, but I didn't make it and it works!

First off we will stop weewx and add a database to MYSQL :

service weewx stop
mysql -u root -p


CREATE DATABASE weewx_raw;
GRANT select, update, create, delete, insert, drop ON weewx_raw.\* TO 'weewx'@'localhost';  
FLUSH PRIVILEGES;

Now we will make changes to the weewx configuration files. $WEEWX_HOME/weewx.conf*

Add this to the DataBindings :

1
2
3
4
5
[[raw_binding]]
    database = weewx_raw_mysql
    table_name = raw
    manager = weewx.manager.Manager
    schema = user.raw.schema

This to the Services section :

1
2
3
[[Services]]

    archive_services = weewx.engine.StdArchive, user.raw.RawService

Add this to the very bottom of your weewx.conf :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
[Raw]

#
# This section is for configuration of the raw plugin. This plugin stores the raw
# data off of the station.
#
# The database binding to persist the raw data.
# This should match a section under the [DataBindings] section.
data_binding = raw_binding
#
# The max amount of raw data to retain specified in hours (set to None to retain all data)
# This will in effect keep a rolling window of the data removing old data based on
# the time of the most recent record. It is recommended to set this to at least 24.
#
# NOTE: if increasing this value (or use None to keep forever),
# keep in mind that raw data may consume VERY large amounts of space!
data_limit = 21

I would suggest restarting both weewx and MYSQL on the RaspberryPi and MYSQL on your server. My weewx.conf configuration file is available to review here