Table of Contents

Upload and record Air Quality data on an SQL database

By PalmyWeather

Upload and record Air Quality data on an SQL database (Pro2 PLUS & Pro2 Compact)

A Brief “How To” Guide. Please note that this is not a “one for all” guide, settings may be different depending on your server.

Step 1: Set up the database on the web server

database.jpg

database2.jpg

Step 2: Enable remote control (This step may not be required)

For security, by default the web server will be protecting itself from remote unauthorised access which could modify or damage the data. Permission may need to be granted to allow your IP address assigned by your internet provider to write to your databases remotely if you host is not local.

Step 3: Setting up the database structure / creating a new table

Now a table to store all the data in needs to be created within the newly created database.

Additional columns can be created later on and parameters changed if the settings are not right first time around.

database3.jpg

Step 4: Configuring the PHP Scripts

Provided in the “Receiver Software Release v6.x” package are two files titled “AirQuality_LogToSQL.php” and “db_rw_details.php”. These need to be configured to match what has just been created on the server.

Step 5: Configuring the Software of RX Unit

The final step is to change the settings on the RX software so it knows where to access the files that have been uploaded to our website.

Once the RX software is compiled and uploaded, it should now start to upload data to the database. This can be checked by logging into the database admin where the data can be viewed.

The data can now be pulled from this database for such things like producing graphs on the website and for many other purposes.

There is a lot of potential going forward for this to not only upload data for the Air Quality monitor (which at time of writing is the only publicly supported option). In the future, this concept could be used to upload all the data gathered by the weather station and have the weather station save the data directly into the database making it a free standing product.

Using SQL Language

Step 3 in this guide could be done by using SQL code if that is of personal preference. “Uncle_Bob” has done some work in this area. This is an example of the SQL code used to create a table within a database, once again using the Air Quality parameters.

DROP SCHEMA IF EXISTS `AQM`;
CREATE SCHEMA AQM;
USE AQM ;
DROP TABLE IF EXISTS `AirQuality`;
CREATE TABLE `AirQuality` ( `LogDateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `PM25` decimal(4,1) NOT NULL, `PM100` decimal(4,1) NOT NULL, `AQI` decimal(3,0) NOT NULL, `CO2` decimal(5,0) NOT NULL, PRIMARY KEY (LogDateTime) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Testing PHP scripts to ensure it writes

A web browser can be used to test the PHP scripts to ensure they write.
As an example, this URL if entered into the web browser, should write data into the Air Quality database if it has been set up correctly (change the URL to find the “AirQuality_LogToSQL.php” file):
www.YOURSERVER.XXX/AirQuality_LogToSQL.php?privatekey=YOURKEY&PM25=99&PM100=98.7&AQI=97&CO2=96
Once the web browser loads the page, nothing will be displayed. But if the database is viewed, the data listed in the URL should have been entered.