WeatherDuino Forum
How to upload data to website SQL database directly from Pro2 PLUS - Printable Version

+- WeatherDuino Forum (https://www.meteocercal.info/forum)
+-- Forum: Weather Stations - WeatherDuino Pro2 Line (https://www.meteocercal.info/forum/Forum-Weather-Stations-WeatherDuino-Pro2-Line)
+--- Forum: Software Questions (https://www.meteocercal.info/forum/Forum-Software-Questions)
+--- Thread: How to upload data to website SQL database directly from Pro2 PLUS (/Thread-How-to-upload-data-to-website-SQL-database-directly-from-Pro2-PLUS)



How to upload data to website SQL database directly from Pro2 PLUS - Palmyweather - 20-05-2018

Using WeatherDuino Pro2+ to upload data to a website database with SQL
(Available in Receiver Software Release v6.x onwards)

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        


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.

   


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.

Code:
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.


RE: How to upload data to website SQL database directly from Pro2 PLUS - hornychz - 20-05-2018

Good job, Palmyweather!
Smile


RE: How to upload data to website SQL database directly from Pro2 PLUS - uncle_bob - 20-05-2018

Wish this thread existed a month or so ago Wink

Like Palmy mentioned, to automagically create the DB just copy and paste the above code into the SQL tab in phpMyAdmin and then hit go. Like the below image:

[Image: MySQL.PNG]


RE: How to upload data to website SQL database directly from Pro2 PLUS - werk_ag - 20-05-2018

Great article Palmyweather!

This article is making me think in an "How To" section in the WeatherDuino Wiki


RE: How to upload data to website SQL database directly from Pro2 PLUS - werk_ag - 20-05-2018

I couldn't resist!
It's already in the WeatherDuino Wiki


RE: How to upload data to website SQL database directly from Pro2 PLUS - hornychz - 21-05-2018

Smile


RE: How to upload data to website SQL database directly from Pro2 PLUS - Palmyweather - 21-05-2018

(20-05-2018, 23:32)Werk_AG Wrote:  I couldn't resist!
It's already in the WeatherDuino Wiki

That is why it wrote it the way I did, hopefully in a general "long life" approach which could be used on the Wiki and the forum.

It has taken me a few attempts at writing it that way, but I think/hope the results are okay.


RE: How to upload data to website SQL database directly from Pro2 PLUS - werk_ag - 21-05-2018

The format is excellent, it took me less than 30 minutes to put it on the Wiki, keeping the original look . Smile
A new door is open in the Wiki

Once again thank you for your work.