samip537
Posts: 31
Joined: Sat Aug 02, 2014 5:06 pm
Location: Turku, Finland

Re: DHT11 readings onto a web page!

Mon May 25, 2015 3:43 pm

danjperron wrote:Some message post before your first one explain how to add another sensor.

So maybe you should read the post fully from start!

I explain How to add a DS18B20 , use a DHT22 and later what to do if you want to add another DHT sensor.


You will need to figure out. No brain no gain!
That thing about "No brain no gain!" is misleading in this one.

The code is so messy that it's hard to navigate though it...

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

Re: DHT11 readings onto a web page!

Mon May 25, 2015 5:17 pm

The thing is that is not so messy but use a lot of application to make it right.


The python code job is

1- Capture sensors data.
2- Store it into a rrdtool database.
3- Extract a text format using different timing from the database.

The python has no stuff for html.

Then a simple html server is needed to hold the webpage and the file.
The client browser will do all the stuff using javascript.

Sometimes it is preferable to put a project in parts and use a specific application on each part. It looks messy because it's not a single block of code but at the end it is easier to debug and take 1/5 of the time to build.

What are you exactly looking at? Of course I could have spend 200 hours to make it simpler to understand instead of ~40 hrs I put there . But I don't have the time for that.


B.T.W. The initial code was not mine but I found it very easy to implement.

viewtopic.php?p=282532#p282532


I could help you if you tell me where you are stuck but you need to give me more info. Please be more specific.

At least did you have it working with one sensor?

samip537
Posts: 31
Joined: Sat Aug 02, 2014 5:06 pm
Location: Turku, Finland

Re: DHT11 readings onto a web page!

Mon May 25, 2015 5:31 pm

danjperron wrote:Don't forget the pull up resistor. 4K7 like the one for the DHT22 will do.
Does DS18B20 need the pull up resistor too?

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

Re: DHT11 readings onto a web page!

Mon May 25, 2015 5:44 pm

Yes the DS18B20 need the pull-up. A 4700 ohm will be okay.

samip537
Posts: 31
Joined: Sat Aug 02, 2014 5:06 pm
Location: Turku, Finland

Re: DHT11 readings onto a web page!

Mon May 25, 2015 5:45 pm

danjperron wrote:The thing is that is not so messy but use a lot of application to make it right.


The python code job is

1- Capture sensors data.
2- Store it into a rrdtool database.
3- Extract a text format using different timing from the database.

The python has no stuff for html.

Then a simple html server is needed to hold the webpage and the file.
The client browser will do all the stuff using javascript.

Sometimes it is preferable to put a project in parts and use a specific application on each part. It looks messy because it's not a single block of code but at the end it is easier to debug and take 1/5 of the time to build.

What are you exactly looking at? Of course I could have spend 200 hours to make it simpler to understand instead of ~40 hrs I put there . But I don't have the time for that.


B.T.W. The initial code was not mine but I found it very easy to implement.

viewtopic.php?p=282532#p282532


I could help you if you tell me where you are stuck but you need to give me more info. Please be more specific.

At least did you have it working with one sensor?
I do have it working with one sensor and I have ordered an DS18B20 plus some 4.7ohm resistors.

Where you can find it?

http://home.sami-mantysaari.com:8080/temperature.html

Note: I live in Finland which makes it an interesting graph to look at.

Also is it a good idea to solder the 4.7k ohm resistor to the sensor wires and then attach it to the Pi or should I just use breadbroad even though it has the other sensor in it already with a lot of wires?

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

Re: DHT11 readings onto a web page!

Mon May 25, 2015 6:05 pm

There is a lot of chat about the best way to connect the DS18B20 with the PI.

Personnally I use a small veroboard with separate screwable wire connectors for each sensor.

Image
Open the image only and zoom in the left box. The resistor is on the veroboard.

Or I use an industrial terminator block
Image

samip537
Posts: 31
Joined: Sat Aug 02, 2014 5:06 pm
Location: Turku, Finland

Re: DHT11 readings onto a web page!

Mon May 25, 2015 6:10 pm

danjperron wrote:There is a lot of chat about the best way to connect the DS18B20 with the PI.

Personnally I use a small veroboard with separate screwable wire connectors for each sensor.

Image
Open the image only and zoom in the left box. The resistor is on the veroboard.

Or I use an industrial terminator block
Image
Thank you for the idea. I might implement it.

What's the case you are using for the Raspberry and the other things? (Left grey box)

Is the blue cable for power?

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

Re: DHT11 readings onto a web page!

Mon May 25, 2015 7:40 pm

This was my pond temperature controller to keep my pond from freezing over.
Image
In the box.

- Raspberry Pi B first version (256 MB).
- 2 relays . One for heater and one for light.
- Veroboard which hold 5 connectors for DS18B20 sensors. inside computer box, camera box, outside temp and the two pond bassins.
- Servo motor to rotate the camera.
- One 2A 5V usb power adapter.
- one Wifi 300 meters dongle.
- One Logitech C-920 camera.
- usb hub .

I use the same code for 5 sensors. The camera is always online and I did some time lapse with it.

B.T.W. it is not on service right now since the pond won't freeze ;-)
Last edited by danjperron on Wed Oct 04, 2017 7:20 pm, edited 1 time in total.

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

Re: DHT11 readings onto a web page!

Mon May 25, 2015 7:49 pm

Like I said , I use the same code with a slightly modified python code.

Image

dj_janker
Posts: 59
Joined: Thu Jan 08, 2015 6:15 pm

Re: DHT11 readings onto a web page + an led

Tue May 26, 2015 2:52 pm

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
I'm trying to monitor a sensor DHT11 following the instructions from your previous post .
But I get the following error:

You know what I can do to correct it ?

Code: Select all

[ ok ] Starting system pigpiod daemon:.
[email protected]:/etc/init.d# cd ~
[email protected]:~# wget https://www.dropbox.com/s/326si04qiheqfw1/DHT22.py
--2015-05-26 16:47:53--  https://www.dropbox.com/s/326si04qiheqfw1/DHT22.py
Resolving www.dropbox.com (www.dropbox.com)... 108.160.172.206, 108.160.172.238
Connecting to www.dropbox.com (www.dropbox.com)|108.160.172.206|:443... connected.
HTTP request sent, awaiting response... 302 FOUND
Location: https://dl.dropboxusercontent.com/content_link/amb0ssSuCicjLd4VqaE43Cc3ntWIJoVKq6YXn753D4QySjOuCqRyKjG0vkrZ8nuW [following]
--2015-05-26 16:48:15--  https://dl.dropboxusercontent.com/content_link/amb0ssSuCicjLd4VqaE43Cc3ntWIJoVKq6YXn753D4QySjOuCqRyKjG0vkrZ8nuW
Resolving dl.dropboxusercontent.com (dl.dropboxusercontent.com)... 23.23.245.102, 23.21.45.65, 50.17.184.208, ...
Connecting to dl.dropboxusercontent.com (dl.dropboxusercontent.com)|23.23.245.102|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7590 (7.4K) [text/x-python]
Saving to: `DHT22.py.1'

100%[===================================================================================================================>] 7,590       --.-K/s   in 0s

2015-05-26 16:48:37 (14.5 MB/s) - `DHT22.py.1' saved [7590/7590]

[email protected]:~# sudo python DHT22.py
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Can't connect to pigpio on localhost(8888)

Did you start the pigpio daemon? E.g. sudo pigpiod

Did you specify the correct Pi host/port in the environment
variables PIGPIO_ADDR/PIGPIO_PORT?
E.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888

Did you specify the correct Pi host/port in the
pigpio.pi() function? E.g. pigpio.pi('soft', 8888))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Traceback (most recent call last):
  File "DHT22.py", line 265, in <module>
    s = DHT22.sensor(pi, 22, LED=None, power=None,DHT11=True)
  File "/root/DHT22.py", line 91, in __init__
    pi.set_pull_up_down(gpio, pigpio.PUD_OFF)
  File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1025, in set_pull_up_down
    return _u2i(_pigpio_command(self.sl, _PI_CMD_PUD, gpio, pud))
  File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 791, in _pigpio_command
    sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))
AttributeError: 'NoneType' object has no attribute 'send'
[email protected]:~#
Last edited by dj_janker on Tue May 26, 2015 7:47 pm, edited 1 time in total.

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

Re: DHT11 readings onto a web page!

Tue May 26, 2015 3:21 pm

In the post you create a pigpiod service "/etc/init.d/pigpiod. This mean only one pigpiod should run. No need to start another pigpiod.


To debug it, you should try this and tell the result.

Try first to see if pigpiod works.

1- stop pigpiod service
sudo service pigpiod stop
2- Kill all pigpiod running
sudo killall pigpiod

3- Now we will just run one pigpiod
sudo pigpiod &
sudo python DHT22.py

dj_janker
Posts: 59
Joined: Thu Jan 08, 2015 6:15 pm

Re: DHT11 readings onto a web page!

Tue May 26, 2015 3:53 pm

This is my report:

Code: Select all

AttributeError: 'NoneType' object has no attribute 'send'
[email protected]:~# sudo service pigpiod stop
[....] Stopping system pigpiod daemon:start-stop-daemon: warning: failed to kill 10843: No such process
No process in pidfile '/var/run/pigpiod.pid' found running; none killed.
 failed!
[email protected]:~# sudo killall pigpiod
[email protected]:~# sudo pigpiod &
[1] 11987
[email protected]:~# sudo python DHT22.py
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Can't connect to pigpio on localhost(8888)

Did you start the pigpio daemon? E.g. sudo pigpiod

Did you specify the correct Pi host/port in the environment
variables PIGPIO_ADDR/PIGPIO_PORT?
E.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888

Did you specify the correct Pi host/port in the
pigpio.pi() function? E.g. pigpio.pi('soft', 8888))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Traceback (most recent call last):
  File "DHT22.py", line 265, in <module>
    s = DHT22.sensor(pi, 22, LED=None, power=None,DHT11=True)
  File "/root/DHT22.py", line 91, in __init__
    pi.set_pull_up_down(gpio, pigpio.PUD_OFF)
  File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 1025, in set_pull_up_down
    return _u2i(_pigpio_command(self.sl, _PI_CMD_PUD, gpio, pud))
  File "/usr/local/lib/python2.7/dist-packages/pigpio.py", line 791, in _pigpio_command
    sl.s.send(struct.pack('IIII', cmd, p1, p2, 0))
AttributeError: 'NoneType' object has no attribute 'send'
[1]+  Done                    sudo pigpiod
[email protected]:~#

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

Re: DHT11 readings onto a web page!

Tue May 26, 2015 4:47 pm

Did you disable the loopback network?

it needs to be there in the /etc/network/interfaces

Code: Select all

[email protected] ~ $ cat /etc/network/interfaces
auto lo

iface lo inet loopback

...
...
Are you able to ping the localhost?

Code: Select all

ping localhost

Is "netstat" display the localhost:8888 in the list?


Code: Select all

[email protected] ~ $ netstat
Connexions Internet actives (sans serveurs)
Proto Recv-Q Send-Q Adresse locale          Adresse distante        Etat
tcp        0      0 Pi2.local:48895         BPlus.local:ssh         ESTABLISHED
tcp        0      0 Pi2.local:ssh           bas16-ottawa23-12:58868 ESTABLISHED
tcp        0      0 localhost:38344         localhost:8888          TIME_WAIT
tcp        0    216 Pi2.local:ssh           bas16-ottawa23-12:52942 ESTABLISHED
Sockets du domaine UNIX actives(sans serveurs)
if you use the IP of the Rpi instead of local host does it work?

do

Code: Select all

sudo ifconfig
to get the IP. MY RPi is 10.11.12.107

And check if you are able to connect with pigpio

Code: Select all

[email protected] ~ $ python
Python 2.7.3 (default, Mar 18 2014, 05:13:23)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pigpio
>>> pi = pigpio.pi("10.11.12.107",8888)
>>> pi.connected
True
>>> pi = pigpio.pi()
>>> pi.connected
True


Both "pi.connected" should return True! If the second pigpio.pi() return an error you have a problem with the loopback.

P.S. pigpiod needs to run all the times. And only one.

samip537
Posts: 31
Joined: Sat Aug 02, 2014 5:06 pm
Location: Turku, Finland

Re: DHT11 readings onto a web page!

Tue May 26, 2015 6:43 pm

danjperron wrote:Like I said , I use the same code with a slightly modified python code.

Image
Could you tell me what kind of modifications have you made to the Python code?

P.S I'm waiting on the sensor to arrive.

This is my setup.
https://www.youtube.com/watch?v=mYFDP4KZIZQ

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

Re: DHT11 readings onto a web page!

Tue May 26, 2015 6:59 pm

The python script didn't have the DHT11/22 sensor and didn't need pigpio.

You just need to create more point for rrdtool and extract more sensor point when you create the xml for chart. The temperature chart is the same except it is in french.

I did post how to do it on this post. Check my previous post when I add a ds18b20 sensor at the begining! It is all there.


The pond controller use a config method to figure out which ds18b20 you should read.

I made a document about it in french.
https://docs.google.com/document/d/1512 ... sp=sharing

dj_janker
Posts: 59
Joined: Thu Jan 08, 2015 6:15 pm

Re: DHT11 readings onto a web page!

Tue May 26, 2015 7:29 pm

danjperron wrote:Did you disable the loopback network?

it needs to be there in the /etc/network/interfaces

Code: Select all

[email protected] ~ $ cat /etc/network/interfaces
auto lo

iface lo inet loopback

...
...
Ok, now works ok!!! :D :D :D
The problem was in the interfaces folder. It was desappeared the auto lo line....
I have rewritten it, and the problem was solved.

Thanks a lot.

P.D: How could I agree a code, like the next, to DHT22.py?

Code: Select all

import urllib

def Jeedom(id,value):
  base = "http://"+ip_domotic_center+"/core/api/jeeApi.php?api="
  key = API_KEY
  type = "virtual"
  req = base + key + "&type=" + type + "&id=" + str(id) + "&value=" + value
  urllib.urlopen(req)
  # print "Req Virtuel : " + req
I need to send the humidity and temperature de DHT11 sensor to my domotic center, using it url API KEY.
value is humidity or temperature

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

Re: DHT11 readings onto a web page!

Wed May 27, 2015 1:44 am

P.D: How could I agree a code, like the next, to DHT22.py?
Sorry be more specific i can't figure it out what you mean?
....to my domotic center, using it url API KEY.
Same thing here ??????

What is you domotic center? Which protocol are you using ?

Could you use MQTT because with MQTT is simple.

something similar to

Code: Select all

import paho.mqtt.client as paho
#give a name to you client
client = paho.Client('RaspberryPi2')
#connect to the MQTT server
client.connect('10.11.12.192')
#publish your data using a specific topic that you choose.
client.publish('RF_DATA/DHT22_1/Temp',sensor.temperature())
client.publish('RF_DATA/DHT22_1/Hum',sensor.humidity())

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

Re: DHT11 readings onto a web page!

Wed May 27, 2015 4:02 am

@samip537 I took out my old script which use 5 DS18B20 sensors

The code is different since it does create some html frame and transfer data into my WD NAS using ftp.

I put the code into my google drive since it is not exactly related to this post.

StampTemp.py
https://drive.google.com/file/d/0B9H9nJ ... sp=sharing

And the bash script to append to the daily log file using ftp

AppendFile.sh
https://drive.google.com/file/d/0B9H9nJ ... sp=sharing

dj_janker
Posts: 59
Joined: Thu Jan 08, 2015 6:15 pm

Re: DHT11 readings onto a web page!

Wed May 27, 2015 5:20 am

danjperron wrote:
P.D: How could I agree a code, like the next, to DHT22.py?
Sorry be more specific i can't figure it out what you mean?
....to my domotic center, using it url API KEY.
Same thing here ??????

What is you domotic center? Which protocol are you using ?

Could you use MQTT because with MQTT is simple.

something similar to

Code: Select all

import paho.mqtt.client as paho
#give a name to you client
client = paho.Client('RaspberryPi2')
#connect to the MQTT server
client.connect('10.11.12.192')
#publish your data using a specific topic that you choose.
client.publish('RF_DATA/DHT22_1/Temp',sensor.temperature())
client.publish('RF_DATA/DHT22_1/Hum',sensor.humidity())
Sorry, you have the reason. I didn´t give you enough information.
My domotic center is Jeedom (http://jeedom.fr/), based in other Rpi inside my LAN.
I need to send the humidity and temperature information since other Rpi where is connected the DHT11.
The URL API HTTP protocol, can you see here: https://jeedom.fr/doc_api.php

I modified your script to send the humidity and temperature information to mi domotic center (Jeedom in other Rpi with ip: 192.168.1.20)

Code: Select all

if __name__ == "__main__":

 # Ajout pour Jeedom
   import urllib
   def Jeedom(id, value):
     base = "https://192.168.1.20/core/api/jeeApi.php?api="
     key = " xxxx"
     type = "virtual"
     req = base + key + "&type=" + type + "&id=" + str(id) + "&value=" + str(value)
     urllib.urlopen(req)
     # print "Req Virtuel : " + req
# fin
   import time

   import pigpio

   import DHT22

   # Intervals of about 2 seconds or less will eventually hang the DHT22.
   # INTERVAL=3

   pi = pigpio.pi()

   s = DHT22.sensor(pi, 22, LED=None, power=None,DHT11=True)

   # r = 0

   # next_reading = time.time()

   #while True:
   #   r += 1

   #   s.trigger()

    #  time.sleep(0.2)

    #  print("{} {} {} {:3.2f} {} {} {} {}".format(
    #     r, s.humidity(), s.temperature(), s.staleness(),
    #     s.bad_checksum(), s.short_message(), s.missing_message(),
    #     s.sensor_resets()))

   id = 1035
   value = s.temperature()
   Jeedom(id,value)

#   id2 = 1036
#  value2 = s.humidity()
#   Jeedom(id2,value2)


    #  next_reading += INTERVAL

    #  time.sleep(next_reading-time.time()) # Overall INTERVAL second polling.

   s.cancel()

   pi.stop()


Now when I execute the script I didn´t receive report....
do you know what´s the problem?
Last edited by dj_janker on Wed May 27, 2015 11:16 am, edited 4 times in total.

samip537
Posts: 31
Joined: Sat Aug 02, 2014 5:06 pm
Location: Turku, Finland

Re: DHT11 readings onto a web page!

Wed May 27, 2015 6:41 am

danjperron wrote:@samip537 I took out my old script which use 5 DS18B20 sensors

The code is different since it does create some html frame and transfer data into my WD NAS using ftp.

I put the code into my google drive since it is not exactly related to this post.

StampTemp.py
https://drive.google.com/file/d/0B9H9nJ ... sp=sharing

And the bash script to append to the daily log file using ftp

AppendFile.sh
https://drive.google.com/file/d/0B9H9nJ ... sp=sharing
I see, but your code is much more clean than the other one. Easier for me to understand.

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

Re: DHT11 readings onto a web page!

Wed May 27, 2015 11:03 am

@samip537 Be careful on that Pond version the ReadSensor function could lock up.

You need to add a counter just in case the probe doesn't work anymore.
And you should also add code to intercept the error. Check for None.

Code: Select all

def ReadSensor( SensorId):
  RetryCounter=5
  while RetryCounter >0 :
    fname = "/sys/bus/w1/devices/" + SensorId + "/w1_slave"
    tfile = open(fname)
    text = tfile.read()
    tfile.close()
    firstline  = text.split("\n")[0] 
    crc_check = text.split("crc=")[1]
    crc_check = crc_check.split(" ")[1]
    if crc_check.find("YES")>=0:
      break
    RetryCounter = RetryCounter - 1
  
  if RetryCounter < 1 :
      return None 
  secondline = text.split("\n")[1]
  temperaturedata = secondline.split(" ")[9]
  temperature = float(temperaturedata[2:])
  temperature = temperature / 1000.0
  return temperature

dj_janker
Posts: 59
Joined: Thu Jan 08, 2015 6:15 pm

Re: DHT11 readings onto a web page!

Wed May 27, 2015 1:36 pm

@danjperron

Code: Select all

    #  print("{} {} {} {:3.2f} {} {} {} {}".format(
    #     r, s.humidity(), s.temperature(), s.staleness(),
    #     s.bad_checksum(), s.short_message(), s.missing_message(),
    #     s.sensor_resets()))

    #  next_reading += INTERVAL

    #  time.sleep(next_reading-time.time()) # Overall INTERVAL second polling.

 # Ajout pour Jeedom
   import urllib
   def Jeedom(id, value):
     base = "https://192.168.1.20/jeedom/core/api/jeeApi.php?api="
     key = "xxxxx"
     type = "virtual"
     req = base + key + "&type=" + type + "&id=" + str(id) + "&value=" + str(value)
     urllib.urlopen(req)
     print "Req Virtuel : " + req
 # fin
   id = 1035
   value = s.temperature()
   Jeedom(id,value)

#   id2 = 1036
#  value2 = s.humidity()
#   Jeedom(id2,value2)

   s.cancel()

   pi.stop()
I add this code at the end of your script, to try to send the temperature value to my domotic center.
And when I extecute the script, I receive this report:

Code: Select all

[email protected]:~# python DHT22_.py
Req Virtuel : https://192.168.1.20/jeedom/core/api/jeeApi.php?api=xxxxch&type=virtual&id=1035&value=-999
[email protected]:~#
This send to my domotic centre the value=-999.
So, I think that my code is correct, but make that your script is wrong :( :( :(
Could you help me, please?

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

Re: DHT11 readings onto a web page!

Wed May 27, 2015 2:23 pm

Put some debug on the script to check if everything is working.


1- Re-enable the print("{} {} {} {:3.2F .......
We will be able to figure out if the DHT sensor work.

P.S. On power ON, the first reading is always bad. Also it looks like that the next reading was capture from the last request. This is why I always read the sensor twice and toss away the first reading. You need a mimimum dealy between each reading, ~ 2 seconds.

2- Print your "req" variable string and the value string. At least You will know if you are sending the correct string.

Adding print to debug code will help you a lot. This is the first thing I do normally to check things up.

dj_janker
Posts: 59
Joined: Thu Jan 08, 2015 6:15 pm

Re: DHT11 readings onto a web page!

Wed May 27, 2015 2:50 pm

danjperron wrote:Put some debug on the script to check if everything is working.


1- Re-enable the print("{} {} {} {:3.2F .......
We will be able to figure out if the DHT sensor work.

P.S. On power ON, the first reading is always bad. Also it looks like that the next reading was capture from the last request. This is why I always read the sensor twice and toss away the first reading. You need a mimimum dealy between each reading, ~ 2 seconds..
Making your last indications, the script works again, but it is printing superfast....
Now I cant´send info to my domotic center.

Code: Select all

   import time

   import pigpio

   import DHT22

   # Intervals of about 2 seconds or less will eventually hang the DHT22.
   INTERVAL=3

   pi = pigpio.pi()

   s = DHT22.sensor(pi, 22, LED=None, power=None,DHT11=True)

   r = 0

   next_reading = time.time()

   while True:
      r += 1

      s.trigger()

      time.sleep(0.2)

      print("{} {} {} {:3.2f} {} {} {} {}".format(
         r, s.humidity(), s.temperature(), s.staleness(),
         s.bad_checksum(), s.short_message(), s.missing_message(),
         s.sensor_resets()))

   next_reading += INTERVAL

   time.sleep(next_reading-time.time()) # Overall INTERVAL second polling.
   s.cancel()

 # Ajout pour Jeedom
   import urllib
   def Jeedom(id, value):
     base = "https://192.168.1.20/jeedom/core/api/jeeApi.php?api="
     key = "xxxx"
     type = "virtual"
     req = base + key + "&type=" + type + "&id=" + str(id) + "&value=" + str(value)
     urllib.urlopen(req)
     print "Req Virtuel : " + req
   id = 1035
   value = s.temperature()
   Jeedom(id,value)



#   id2 = 1036
#  value2 = s.humidity()
#   Jeedom(id2,value2

   pi.stop()
danjperron wrote: 2- Print your "req" variable string and the value string. At least You will know if you are sending the correct string.

Adding print to debug code will help you a lot. This is the first thing I do normally to check things up.
I did not understood you. Could you show me the code that you refer?

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

Re: DHT11 readings onto a web page!

Wed May 27, 2015 3:35 pm

Put a sleep of 30 second between readings . It will be more easier to debug. Don't forget a minimum of 2 seconds between readings.

In your jeedom() function add a print for req and value. You will see if you send the right thing.

Return to “Python”

Who is online

Users browsing this forum: No registered users and 23 guests