OVERALL PROCEDURE :
Step 1: DHT-11 is interfaced with the raspberrry pi .
Step 2 : Raspberry pi sends data to a php file putdata.php which writes data in a text file in json format .
Step 3 : In Android when the button get the values is pressed the android calls a php file getdata.php which reads the text file and sends it to android.
Step 4 : Then android extracts the information in the json format and puts it in the required textboxes.
1.RASPBERRY PI PART
DHT-11 sensor is a anolog sensor that has three pins . It can be connected to arduino,raspberry pi etc., In this how to collect data from DHT-11 sensor and save it in a file is explained.
CIRCUIT DIAGRAM
Raspberry Pi DHT11 Module
5v P2 —————————– VCC (V)
GND P6 —————————- GND (G)
GPIO4 P7 —————————– DATA (S)
PROCEDURE:
Open the terminal and type the following commands
Step 1: Enter sudo apt-get install git-core. If any error in installing git-core update the software using sudo apt-get update .
Step 2: Enter git clone https://github.com/adafruit/Adafruit_Python_DHT.git to clone the library.
Step 3: Open the folder using cd Adafruit_Python_DHT.
Step 4: Enter sudo apt–get install build–essential python–dev.
Step 5 : Enter sudo python setup.py install to install setup.py
Step 6: Enter sudo apt–get install python–dev python–rpi.gpio to install GPIO if it is not installed
Step 7: Type apt-get install python-requests to send post request to the server.
PROGRAMS :
1 2 3 4 5 6 7 8 9 10 | import sys import requests import time import Adafruit_DHT while(1): hum, temp = Adafruit_DHT.read_retry(11, 4) # to find ipaddress type ifconfig in termiinal r=requests.post('http://ipaddress/putdata.php',data={'temp':temp,'hum':hum}) time.sleep(30); #send data two times a minute. |
Save this as run the program .
2.SERVER PART :
There are two possibilities for server. They are
- Localhost
- Online server
In Localserver like xampp the data can be accessed only connected in same network. If you are interested installing localserver click here.
In myproject Iam using onlinefree server namely 000webhost.com. In my video below I will explain how to create a free server and upload all the files in it .
PUTDATA.PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <!--?php //GETting values $var1 = $_POST['temp']; $var2 = $_POST['hum']; $v1=(string)$var1; $v2=(string)$var2; echo $var1; echo $var2; $data=array('temp' => $v1,'hum' =>$v2); $file=fopen("value.text","w"); fwrite($file,json_encode($data)); fclose($file); // bus down, send start signal //reading the switch text file //Writing the spreadsheet $dt = new DateTime('now', new DateTimezone('Asia/Kolkata')); $date= $dt->format('F j, Y'); $time= $dt->format('g:i a'); echo $date; echo $time; ?--> |
GETDATA.PHP
1 | <!--?php $res=file_get_contents('value.text'); echo $res; ?--> |
I have made a app specially for this project where it is enough if you specify the webaddress and click Get the values the temperature and humidity data will be displayed.
Thankyou
3 Comments
farmville 2 country escape glitches and cheats
(February 24, 2018 - 9:53 pm)I must say, as a lot as I enjoyed reading what you had to say, I couldnt help but lose interest after a while.
Gowtham S
(February 25, 2018 - 6:42 pm)Thank You!!!
Proton
(March 16, 2018 - 7:24 am)Just wanna input on few general things, The website layout is perfect, the articles is very superb : D.