sultan
Posts: 57
Joined: Wed Jan 14, 2015 4:50 pm
Location: India

DHT11 readings onto a web page!

Wed Jan 14, 2015 5:07 pm

I tired the Adafruit article and was successful.
https://learn.adafruit.com/dht-humidity ... cs-updated .This article .But now i need it on a my local ip or a website.
I have tried what every i can but i cannot get it to work.I am looking for some help with it.
And guy's the adafruit thing is so unstable ,I cannot even run it off screen :(.
I am getting so many errors.
Please guys help me. :roll:
EDIT: http://i.gyazo.com/0824d14ba70917289919237e271c99f1.png
Been getting this i am mad now :faceplam:
Last edited by sultan on Fri Jan 16, 2015 7:40 pm, edited 1 time in total.
Forgive me for my grammar :(.

danjperron
Posts: 3032
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DHT11 readings onto a web page + an led

Thu Jan 15, 2015 1:58 am

Hi sultan,

You could try Joan's code, base on his pigpio library, or mine which use SPI.

for Joan code google pigpio http://abyz.co.uk/rpi/pigpio/python.html

P.S. The site is down right now ;-/ I hope it is not for long

And my SPI documentation method http://www.raspberrypi.org/forums/viewt ... 13#p638713 documented by paulv


Rddtool and HightChart could give you a good start to create chart using a circular buffer.
http://www.raspberrypi.org/forums/viewt ... it=rddtool

Image


I use it to check my outside pond and I control a water heater to prevent the pond to completely freeze. I want to keep my fish alive.

I did it with a couple of DS18B20 and one DHT22 but I could simplify the method.

Did you install any web server?

Daniel
Last edited by danjperron on Wed May 16, 2018 6:41 pm, edited 1 time in total.

sultan
Posts: 57
Joined: Wed Jan 14, 2015 4:50 pm
Location: India

Re: DHT11 readings onto a web page + an led

Thu Jan 15, 2015 8:33 am

danjperron wrote:Hi sultan,

You could try Joan's code, base on his pigpio library, or mine which use SPI.

for Joan code google pigpio http://abyz.co.uk/rpi/pigpio/python.html

P.S. The site is down right now ;-/ I hope it is not for long

And my SPI documentation method http://www.raspberrypi.org/forums/viewt ... 13#p638713 documented by paulv


Rddtool and HightChart could give you a good start to create chart using a circular buffer.
http://www.raspberrypi.org/forums/viewt ... it=rddtool

Image


I use it to check my outside pond and I control a water heater to prevent the pond to completely freeze. I want to keep my fish alive.

I did it with a couple of DS18B20 and one DHT22 but I could simplify the method.

Did you install any web server?

Daniel
Thank you buddy, I will try this out and reply back.
Forgive me for my grammar :(.

danjperron
Posts: 3032
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 4:41 am

There is a small differences between the DHT11 and the DHT22

The DHT11 is way less precise and don't go below 0 Celsius.

The data stream output of the DHT22 is 16 bit big endian with the bit 15 for negative indicator.
The DHT11 is 16 bit little endian and both MSB byte are set to zero.

This is a problem when you decode the data.
On the DHT22 the formula is ( (MSB * 256) + LSB) /10
On the DHT11 it is simply the LSB data which is in a swapped position from the DHT22

To have Joan code behave correctly , I just modify it by adding a variable to check if the sensor is a DHT11.

Then If you want to use Joan method with PIGPIO use this step by step method,

1 - update

Code: Select all

sudo apt-get update
2 - Get pigpio

Code: Select all

cd ~
wget abyz.co.uk/rpi/pigpio/pigpio.zip
unzip pigpio.zip
cd PIGPIO
make
sudo make install
3 - Create pigpio service. This way we don’t need to start it all the times


let’s load my pigpio script version

cd /etc/init.d
sudo wget -O pigpiod \
https://googledrive.com/host/0B9H9nJFy3 ... 2xUel9uUk0
sudo chmod 755 /etc/init.d/pigpiod
sudo update-rc.d pigpiod defaults 9
complete -W "$(ls /etc/init.d/)" service
sudo service pigpiod start

ref: http://blog.scphillips.com/2013/07/gett ... e-on-boot/


** Update with systemd is easier

Code: Select all

sudo systemctl enable pigpiod
sudo systemctl start pigpiod
4 - Let’s download my modified version of Joan’s DHT22 code

Code: Select all

cd ~
wget https://www.dropbox.com/s/326si04qiheqfw1/DHT22.py


Be sure that you are using GPIO22 (pin 15) otherwise you will have to change the pin information in the code.


if everything is ok just type

Code: Select all

sudo python DHT22.py
and it should returns

Code: Select all

[email protected] ~ $ sudo python DHT22.py
1 33 23 0.19 0 0 0 0
2 34 23 0.19 0 0 0 0
3 34 23 0.19 0 0 0 0
Temperature 23 Celsius humidity 34%

I will continue tomorrow with the script to store into rrdtool

Daniel
Last edited by danjperron on Wed Oct 18, 2017 2:07 pm, edited 1 time in total.

sultan
Posts: 57
Joined: Wed Jan 14, 2015 4:50 pm
Location: India

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 7:58 am

danjperron wrote:There is a small differences between the DHT11 and the DHT22

The DHT11 is way less precise and don't go below 0 Celsius.

The data stream output of the DHT22 is 16 bit big endian with the bit 15 for negative indicator.
The DHT11 is 16 bit little endian and both MSB byte are set to zero.

This is a problem when you decode the data.
On the DHT22 the formula is ( (MSB * 256) + LSB) /10
On the DHT11 it is simply the LSB data which is in a swapped position from the DHT22

To have Joan code behave correctly , I just modify it by adding a variable to check if the sensor is a DHT11.

Then If you want to use Joan method with PIGPIO use this step by step method,

1 - update

Code: Select all

sudo apt-get update
2 - Get pigpio

Code: Select all

cd ~
wget abyz.co.uk/rpi/pigpio/pigpio.zip
unzip pigpio.zip
cd PIGPIO
make
sudo make install
3 - Create pigpio service. This way we don’t need to start it all the times


let’s load my pigpio script version

Code: Select all

cd /etc/init.d
sudo wget -O pigpiod \
https://googledrive.com/host/0B9H9nJFy3HJcWVhsY2xUel9uUk0
sudo chmod 755 /etc/init.d/pigpiod
sudo update-rc.d pigpiod defaults 9
complete -W "$(ls /etc/init.d/)" service
sudo service pigpiod start
ref: http://blog.scphillips.com/2013/07/gett ... e-on-boot/

4 - Let’s download my modified version of Joan’s DHT22 code

Code: Select all

cd ~
wget https://www.dropbox.com/s/326si04qiheqfw1/DHT22.py


Be sure that you are using GPIO22 (pin 15) otherwise you will have to change the pin information in the code.


if everything is ok just type

Code: Select all

sudo python DHT22.py
and it should returns

Code: Select all

[email protected] ~ $ sudo python DHT22.py
1 33 23 0.19 0 0 0 0
2 34 23 0.19 0 0 0 0
3 34 23 0.19 0 0 0 0
Temperature 23 Celsius humidity 34%

I will continue tomorrow with the script to store into rrdtool

Daniel
Done everything as expected and thank you :P :lol: :D :) ;)
I am so happy ,But the main part is the tool one .
Will be waiting for it bro :P.
Thank you again :D
Forgive me for my grammar :(.

danjperron
Posts: 3032
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 12:30 pm

Ok Let's continue

5 - Install apache2 , HighChart and rrdtool. I hope that you have a 8G SD card !

Code: Select all

cd ~
sudo apt-get install apache2
sudo apt-get install rrdtool
wget http://code.highcharts.com/zips/Highcharts-4.0.4.zip 
sudo unzip Highcharts-4.0.4.zip -d /var/www/charts
sudo chown www-data.www-data -R /var/www/charts/*
6- Since we will create volatile file every 5 minutes, we should create a ramdrive to hold it

We will insert a ram drive into /etc/fstab

Code: Select all

sudo mkdir /webdata
sudo nano /etc/fstab
and insert the line with /webdata in it like this

Code: Select all

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
tmpfs		/webdata	tmpfs	defaults,nosuid,uid=www-data,gid=www-data  0 	  0

****** and now reboot *****

Code: Select all

 sudo reboot
On power up you should have a mount called /webdata if you type "df"

Code: Select all

[email protected] ~ $ df
Sys. fich.     1K-blocks   Util. Disponible Uti% Monté sur
rootfs           7392976 2562436    4479960  37% /
/dev/root        7392976 2562436    4479960  37% /
devtmpfs          219744       0     219744   0% /dev
tmpfs              44784     236      44548   1% /run
tmpfs               5120       0       5120   0% /run/lock
tmpfs              89560       0      89560   0% /run/shm
/dev/mmcblk0p1     57288    9920      47368  18% /boot
tmpfs             223912      76     223836   1% /webdata

And now make it accessible to apache by doing a link into /var/www

Code: Select all

cd /var/www
sudo ln -s /webdata webdata

8 - You could check if Highchart works by accessing your raspberry PI IP on your computer browser.

like this http://<your rasberry PI IP>/charts to check HighCharts
like this http://<your rasberry Pi IP>/webdata to list he contains of the folder /webdata

Please change <your rasberry Pi IP> to the real address. For me it is http://10.11.12.7/charts


9 - We need to create the database for rrdtool. Just use my script for 3 data points per record.
The data points are the cpu temperature (th_cpu), the sensor temperature (th_dht22) and the humidity (hm_dht22)

just import my script to create the rrdtool database

Code: Select all

cd ~
wget https://dl.dropboxusercontent.com/u/48891705/rpi/DHT11Chart/create_rrdtool_data.sh
chmod +x create_rrdtool_data.sh
./create_rrdtool_data.sh
10 - Now we need to create a script to read the sensor and put the data into rrdtool
I create a python command for that . It will read the cpu temperature and the DHT11 sensor and push it into the rrdtool. It will also extract the data and create xml file into /webdata. the extracted data correspond to a specific time base to create the charts.

Code: Select all

cd ~
wget https://dl.dropboxusercontent.com/s/ylpj0gecrf3csuy/readTemp.py
chmod +x readTemp.py
if you do

Code: Select all

sudo python readTemp.py
it should populate /webdata folder.

11 - Now we need to get data point every 5 minutes. I don't thind you need to go below 5 minutes.

Code: Select all

sudo crontab -e
and insert that line

Code: Select all

# m h  dom mon dow   command
*/5 * * * * /home/pi/readTemp.py
12 - The only thing left is the webpage to display the data

Code: Select all

cd /var/www
sudo wget https://dl.dropboxusercontent.com/s/6stmf85wbra9u3b/temperature.html
et voila!

just wait 15 minutes for 3 points and you should be able to access the webpage

http://<your rasbperry PI IP>/temperature.html
Image


Daniel
Last edited by danjperron on Mon Jan 22, 2018 3:12 pm, edited 1 time in total.

sultan
Posts: 57
Joined: Wed Jan 14, 2015 4:50 pm
Location: India

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 12:36 pm

Bro i think 2 min or 3 are fine ,Why 5 min?
Forgive me for my grammar :(.

danjperron
Posts: 3032
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 12:39 pm

well change the */5 to */2 in crontab!

sudo crontab -e

Code: Select all

# m h  dom mon dow   command
*/2 * * * * /home/pi/readTemp.py
and you will have to change the --step in "create_rrdtool_data.sh" to 120

Code: Select all

[email protected] ~ $ cat create_rrdtool_data.sh 
#! /bin/bash
rrdtool create temperatures.rrd \
--start "01/01/2015" \
--step 120 \

I don't think that temperature will change that fast anyway!

sultan
Posts: 57
Joined: Wed Jan 14, 2015 4:50 pm
Location: India

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 12:53 pm

danjperron wrote:well change the */5 to */2 in crontab!

sudo crontab -e

Code: Select all

# m h  dom mon dow   command
*/2 * * * * /home/pi/readTemp.py
and you will have to change the --step in "create_rrdtool_data.sh" to 120

Code: Select all

[email protected] ~ $ cat create_rrdtool_data.sh 
#! /bin/bash
rrdtool create temperatures.rrd \
--start "01/01/2015" \
--step 120 \

I don't think that temperature will change that fast anyway!
Done bro lest hope everything goes well :P
Waiting for 15 min :D
Forgive me for my grammar :(.

sultan
Posts: 57
Joined: Wed Jan 14, 2015 4:50 pm
Location: India

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 2:29 pm

Image
^^^Is this a sensor problem?The temp is same from last 1 hour but i can fell cold :(
Not falling below 25 and the cpu too :?: :?:
And it is measuring every 10 min not 5 ,How can i change to 5? :(
Sorry asking to many questions.
Forgive me for my grammar :(.

danjperron
Posts: 3032
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 2:41 pm

Every thing looks ok!

Don't forget that is normal to have a flat line inside a house during day time on a small interval like 1 hour.

This is why 5 minutes sampling is enough.

I don't know where you live but if your heating system is a good one, during the day , flat line it will be.

Best way to verify is to fill a glass with ice and put the glass over the sensor.
Please don't wet the sensor!
wait 15 minutes and you should see a drop.

danjperron
Posts: 3032
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 2:43 pm

I check your graph and you have a dot every 5min. So it is 5 min! not 10

danjperron
Posts: 3032
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 2:46 pm

B.t.w. the cpu temperature is the temperature of the core. It is always way higher than the ambiant temperature. If you overclock the cpu that temperature will rise even more!


Don't forget the DHT11 sensor give only integer value .(step of 1 degree).
and the precision is +/- 2degree and +/- 5% for humidity.
Last edited by danjperron on Fri Jan 16, 2015 2:49 pm, edited 1 time in total.

sultan
Posts: 57
Joined: Wed Jan 14, 2015 4:50 pm
Location: India

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 2:49 pm

danjperron wrote:I check your graph and you have a dot every 5min. So it is 5 min! not 10
Yeah sorry and i don't have heating system ,Just normal room and i live in India tho bro.
Forgive me for my grammar :(.

danjperron
Posts: 3032
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 2:52 pm

Than you should see some difference when you will have a full day of data.

Your system works fine. It looks ok!

sultan
Posts: 57
Joined: Wed Jan 14, 2015 4:50 pm
Location: India

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 2:59 pm

danjperron wrote:Than you should see some difference when you will have a full day of data.

Your system works fine. It looks ok!
Okk brother lets see.I hope everything is fine. :D ;)
Forgive me for my grammar :(.

danjperron
Posts: 3032
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 4:51 pm

Oops I forget to change some titles in webpage chart from french to english.

minor bug ;-) the axe for humidity is wrong.The javascript looks for humidité axe instead of humidity.

Please reload from my dropbox temperature.html.
it is now corrected!
Last edited by danjperron on Fri Jan 16, 2015 5:03 pm, edited 1 time in total.

sultan
Posts: 57
Joined: Wed Jan 14, 2015 4:50 pm
Location: India

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 4:55 pm

danjperron wrote:Oops I forget to change some titles in webpage chart from french to english.

mimor bug ;-)

I will correct my drop box.
Image
how do i change it? and yah i wanna change the index how do i do it? ;) ;)
Forgive me for my grammar :(.

danjperron
Posts: 3032
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 5:17 pm

well you will need to do your homework on that!


the webpage is on /var/www/temperature.html and it is filled with javascript but I put the text in string so they are easy to change.

The index string are on line 69 but don't change the ?3h,24h,..etc unless you understand the code.


make a copy of it first.

to reload the file you will need to erase it first!
and to have the new page working you will need to flush your browser cache.

sultan
Posts: 57
Joined: Wed Jan 14, 2015 4:50 pm
Location: India

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 5:21 pm

danjperron wrote:well you will need to do your homework on that!


the webpage is on /var/www/temperature.html and it is filled with javascript but I put the text in string so they are easy to change.

The index string are on line 69 but don't change the ?3h,24h,..etc unless you understand the code.


make a copy of it first.

to reload the file you will need to erase it first!
and to have the new page working you will need to flush your browser cache.
Got it working thank you :P
Forgive me for my grammar :(.

danjperron
Posts: 3032
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 6:51 pm

I also fix a bug in readTemp.py

from line 90 it should be

Code: Select all

#put current value into a file
def TempS(value):
  if value == None :
    return "---"
  return value

try:
  file = open(webdata+"CurrentData.txt","w")
  file.write("{}\t{}\t{}\t{}\n".format(now,TempS(cpuTemp),TempS(sensorData[0]),TempS(sensorData[1])))
  file.close()
except:
  pass
I correct the dropbox file.

This a file which hold the last data acquired with a time stamp /webdata/CurrentData.txt

parameters are in this text format
date[tab]cpu[tab]temperature[tab]humidity[new line]

you could have access to it using http://<your raspberry PI IP>/webdata/CurrentData.txt

Now it is time for you to you to create a multi frames webpage with the current data and the charts ;-)

sultan
Posts: 57
Joined: Wed Jan 14, 2015 4:50 pm
Location: India

Re: DHT11 readings onto a web page + an led

Fri Jan 16, 2015 7:02 pm

danjperron wrote:I also fix a bug in readTemp.py

from line 90 it should be

Code: Select all

#put current value into a file
def TempS(value):
  if value == None :
    return "---"
  return value

try:
  file = open(webdata+"CurrentData.txt","w")
  file.write("{}\t{}\t{}\t{}\n".format(now,TempS(cpuTemp),TempS(sensorData[0]),TempS(sensorData[1])))
  file.close()
except:
  pass
I correct the dropbox file.

This a file which hold the last data acquired with a time stamp /webdata/CurrentData.txt

parameters are in this text format
date[tab]cpu[tab]temperature[tab]humidity[new line]

you could have access to it using http://<your raspberry PI IP>/webdata/CurrentData.txt

Now it is time for you to you to create a multi frames webpage with the current data and the charts ;-)
Done ;) ;)
Give me some tips how do i do that? :D :)
Forgive me for my grammar :(.

danjperron
Posts: 3032
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DHT11 readings onto a web page!

Fri Jan 16, 2015 7:55 pm

Code: Select all

cd /var/www
sudo mv index.html index.html.old
sudo touch index.html
sudo chown pi index.html
and now modify index.html

Code: Select all

nano index.html
with

Code: Select all

<html>
<head>
<frameset rows="600,*">
<frame src="temperature.html"/>
<frame src="webdata/CurrentData.txt"/>
</frameset>
</head>
</html>

and now http://<your raspberry PI IP> should show you two frames.
The top one will be the chart and the bottom will be the text file.

N.B. There is no auto refresh so you will need to add it.
And this one I will let you search for it.

sultan
Posts: 57
Joined: Wed Jan 14, 2015 4:50 pm
Location: India

Re: DHT11 readings onto a web page!

Fri Jan 16, 2015 8:02 pm

danjperron wrote:

Code: Select all

cd /var/www
sudo mv index.html index.html.old
sudo touch index.html
sudo chown pi index.html
and now modify index.html

Code: Select all

nano index.html
with

Code: Select all

<html>
<head>
<frameset rows="600,*">
<frame src="temperature.html"/>
<frame src="webdata/CurrentData.txt"/>
</frameset>
</head>
</html>

and now http://<your raspberry PI IP> should show you two frames.
The top one will be the chart and the bottom will be the text file.

N.B. There is no auto refresh so you will need to add it.
And this one I will let you search for it.
Ok sure bro ,You are the best guy :P :
I am getting full marks out of this assignment :D :lol: :lol: :lol: ;)
How do i thank you :P :D ;)
Forgive me for my grammar :(.

danjperron
Posts: 3032
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DHT11 readings onto a web page!

Fri Jan 16, 2015 8:07 pm

Try to figure out what I did will be a good start!

Return to “Python”

Who is online

Users browsing this forum: No registered users and 13 guests