Raspberry Pi Online Weather Log

Home/Arduino Projects/Raspberry Pi Online Weather Log

Raspberry Pi Online Weather Log

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.


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

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

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

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


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!


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.










Never miss a video: Subscribe to educ8s.tv



  1. simplyguy March 2, 2017 at 9:10 pm - Reply

    please where can i get the
    “sense_hat” code ?

  2. simplyguy March 2, 2017 at 9:11 pm - Reply

    i had this error:::

    Traceback (most recent call last):
    File “weatherDataLogger.py”, line 4, in
    from sense_hat import SenseHat
    ImportError: No module named sense_hat

  3. Shweta April 8, 2017 at 4:31 pm - Reply

    In your code weatherdatalogger.py what this line says urllib2.urlopen(“http://www.educ8s.tv/weather/add_data.php?temp=”+temp+”&hum=”+hum+”&pr=”+press).read()?? Is it the path where you have saved the add_data.php?? are your php codes are saved in windows or raspbeans os??

  4. Shweta April 8, 2017 at 4:32 pm - Reply

    .sir my project is also similar to this…but i m showing 3 sensed value (temperature and humidity value,Light sensed value and soil moisture content ) and status of fan ,water pump and bulb(based on sensed values these actuation should takes place).I want display all 6 parameters(sensed values and status of fan,bulb,water pump whether on or off) on localhost website.The sensing and actuating part is done.BUt i m not getting how to send these values to webpage through raspberry pi….plz upload the code for the above and guide me how to code…Hoping for your quick reply because i need to finish this project as early as possible

  5. Shweta April 8, 2017 at 4:33 pm - Reply

    i m waiting for your quick reply…as i m ruuning short of time ..i need to submit this project as early as possible.

Leave A Comment