Raspberry PI weather station – Section one creating database and interface temperature sensor

MSQL is the basic point corresponding to the creating of the database. Following step is to install Msql, Apache, PHP, phyMyadmin to raspberry Pi. Apache is the web server (http) software, Mysql  is the database server, PHP or Perl  is the programming languages to raspberry PI.

Step 1: Update RP

apt-get_install_-y_rpi-update

apt-get_update_-y_&&_apt-get_upgrate_-y

Step 2: Install msql client and header file

apt-get_install_libmsqlclient-dev_msql-client

Step 3: Edit

Following code uses to enter the configuration file of msql.

Nano /etc/msql/m.cns

Inside the mysql configuration file the following code must be commented.

    • bind-address=127.0.-0.1

Under the title of innoDB in mysql configuration file the following code should be added to increase the buffer pool size in compatible to the version of the Raspberry pi.

Innodb_buffer_pool_size=8M

Then save the changes and exit from the msql file.

Step 4: Install server, save and exite.

    • To install mysql server

apt-get_install_msql-server

    • To install the apche web server

apt-get install apache2 apache2-doc

    • Then to install php apche module

 apt-get install php5 libapache2-mod-php5

/etc/init.d/apache2 restart

    • Install Apache  python module as follows.

apt-get install python libapache2-mod-php5

    • Install phpMyAdmin

apt-get install phpmyadmin

    • Configure Apache to work with PhpMyAdmin

nano /etc/apache2/apache2.conf

               Include /etc/phpmyadmin/apache.conf

    • Save the file and restart  apache

/etc/init.d/apache2 restart

Interface the temperature sensor and update a database using msql

Given below is the simple picture of temperature sensor and it’s connection to the raspberry PI. It is very easy to understand.

.

Temperature sensor

Temperature sensor

pic2

Temperature sensor connection to raspberry PI

The current Wheezy Raspberry Pi kernel only supports the One-wire DS18B20 temperature sensor on the GPIO4 port. The kernel module can be activated for the GPIO pins on the Raspberry Pi and the thermometer module by executing the following commands.

    • Install the following drivers. From that can connect load to wire driver.  From that RPi detects the sensor.

Modprobe_wire

modprobe w1-gpio

modprobe w1-therm

    • Check whether the sensor detect by the RPi correctly.

cat  /sys/bus/w1/devices/w1_bus_master1/w1_master_slave

If sensor detects, output must be 1. Otherwise it displays 0. Sensor Id also is displayed as one of output.

    • Display the temperature value.

cat /sys/bus/w1/devices/<ID>/w1_slave

Then the current temperature displays in the command prompt in mili Celsius degrees after the ‘t=’ value.

    • Read out specified values of sensor.

Creates a file, name by temp in python and write the following code there. It is a python code. Then run that file.

                Nano  /location  & name of new file              //create a file

python /location                                                   //run the file

Corresponding code

pic3

python code

    • Write a php code to get this temperature value to msql database.

First create a file as .php(s1.php) and write the following code corresponding to get temperature value to database.

The sensor values can be viewed in the database when we run the corresponding python code of the sensor.

The linking part of the sensor values to the database is done by the following code

con=MySQLdb.connect(host=”<host name>”,user=”<user name of the database login>”,passwd=”<password>”,db=”<Database Name>”)

cur=con.cursor()

cur.execute(“””INSERT INTO <Table name of the database>(<column name>) VALUES(“%s”)”””,(variable name of the sensor value))

pic6

Php code to get this temperature value to msql database

    • Edit the data base and update it.

Go to the phpMyAdmine. According to our login,

login: root

password: jkc

Created the data base name by JKC. Can enter any name suitable.

Created a table inside the database name as temperature. Can enter any name suitable.

Edit three columns as, temp, time and ID. Change these variables in a suitable way and save the changes.

After save those, refresh the page. Then here in the data base display the temperature value corresponding to the time that runs the temperature detecting python code. So display of temperature values, depend on the time that how much run the .php file.

    • Get the temperature table to web page.

 First create a file as .php(s3.php) and write the following code corresponding to table create in web page. Run that file.

pic8

Get the temperature table to web page

Then in web page type following as the address.

                “IP address/s3.php”

Given below is the table display in the web page.

pic7

Table display in the web page

How much temperature display on the table depends on the run time of file s2.php.

  •  Get the graph of temperature to web page.

First create a file as .php (s4.php) and write the following code corresponding to graph of temperature to web page. Run that file.

pic4

Get the graph of temperature to web page-part1

pic5

Get the graph of temperature to web page-part2

Then in web page type following as the address.

                “IP address/s4.php”

Given below is the graph of table display in the web page.

pic9

Graph of table display in the web page