In this tutorial, we are going to learn how to send data to a remote webserver and store them into a MySQL database. Then we are going to display all the data using a simple PHP script! In other words, we are going to build a Raspberry Pi Online Weather Log! Amazing stuff!

Raspberry Pi Online Weather Log

ey guys, I am Nick and welcome to educ8s.tv a channel that is all about DIY electronics projects with Arduino, Raspberry Pi, ESP8266 and other popular boards. Today’s project is very important and extremely useful because we will learn how to store data online! I am using a Raspberry Pi 3 board along with the Sense Hat. The Sense Hat is an add-on board for the Raspberry Pi, which offers many sensors, including a temperature sensor, a humidity sensor, a barometric pressure sensor and many more.

The Raspberry Pi every 10 minutes, measures the temperature, the humidity and the barometric pressure and sends the data via WiFi to a remote webserver which stores them in a MySQL database. We can see all the data from anywhere in the world simply by visiting a web page which displays all the data in a simple table. As you can see I have let the Raspberry Pi run for a couple of hours and I can see all the data along with the time of each measurement. Cool isn’t it?

Let’s now see how to build this project. The hardware setup is really simple. All we need is a Raspberry Pi and a Sense Hat board. The cost of the Raspberry Pi Online Weather Log is around $80.

——————–
WHERE TO BUY
——————–

Raspberry Pi: https://educ8s.tv/part/Raspberry3

Sense Hat: https://educ8s.tv/part/SenseHat

Power Bank: https://educ8s.tv/part/Powerbank

Wemos D1 mini: https://educ8s.tv/part/D1Mini

——————–
BLUEHOST WEBSERVER
——————–

Bluehost: http://bit.ly/BluehostAccount

Full disclosure: All of the links above are affiliate links. I get a small percentage of each sale they generate. Thank you for your support!

[adsense]

 

Raspberry Pi Online Weather Log Code

Let’s now see the software of the project. The code of the project consists of two parts, the Raspberry Pi code, and the server code. First, we are going to examine the Server Code. Of course, you must have a web server available. Since 2006 I use bluehost as my hosting provider and I host all my websites there. If you don’t have a webserver available with around 4$ per month you can have your own bluehost account. Of course, you can use any other host you like, I use bluehost for over 10 years that’s why I recommend it.

For this project, I have created a new folder under my educ8s.tv website which is called “weather”. In this folder, I have placed 3 PHP scripts. I have also created a MySQL database which will store all the data. In the database, I have created a table named “data” which has 5 columns, the id of each entry, the date, the temperature, the humidity and the barometric pressure. I won’t describe how I created the database in this video because it takes time, you may not be interested and there are a lot of tutorials online about this subject. But I would love to prepare a separate Database tutorial. Do you want me to create a detailed tutorial on how to create a MySQL database? Please vote by clicking on the card here. If there is enough interest I will publish a video about that soon!

The connect.php file is responsible for connecting to the database. It contains the configuration settings for the database. So we need to enter the Username, the Database Password, and the hostname. In this line of code, we have to enter the database name. You have to edit this file in order to enter your configuration settings if you build this project.

The Raspberry Pi sends the data to a simple PHP script which is called add_data.php. This script connects to the MySQL database (using the connect.php script) and stores the data in the database. If we want to see the data from the database all we have to do is to visit the index.php file from a browser. The index.php script will connect to database, again using the connect.php script and it will ask the database to return all the stored data. Then it will display all the data in an HTML table.

——————–

CODE OF THE PROJECT
——————–

 

 

 

——————–

SUBSCRIBE ON YOUTUBE

——————–

Never miss a video: Subscribe to educ8s.tv