Thursday, July 11, 2013

RPi-Monitor: Use a DHT11 or DHT22 humidity and temperature sensor

In this post we will see how to connect a DHT11 or DHT22 Temperature and Humidity sensor and configure RPi-Monitor to present and draw the outputs.

Photo from Flickr AttributionNoncommercialNo Derivative Works cc-by-nc-nd by Ham Hock
This article will also explain another capability of RPi-Monitor 2.x: the dual-axis.


Adafruit created a very good tutorial explaining how to use DHT11 or DHT22 . This tutorial is available at this address: http://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/wiring.


Electronic assembly
This electronic assembly is quite simple and will need:
  • 1 x DHT11 or 1 x DHT22
  • 1 x 4.7k resistor
Plug them as described in the following schema:

Schema extracted from Adafruit but using GPIO #27 instead of GPIO #4

Software installation
Thanks to Adafruit ( again ;-) ) the installation is quite simple and can be done with two command lines.
Download Adafruit_DHT form Adafruit's github repository and copy is in /usr/bin as follow:
wget http://goo.gl/oadpl -O Adafruit_DHT
sudo cp Adafruit_DHT /usr/bin/
To test the electronic assembly and the software installation execute the following command (for DHT11):
pi@raspberrypi ~ $ sudo Adafruit_DHT 11 27
Using pin #17Data (40): 0x28 0x0 0x18 0x0 0x40
Temp = 24 *C, Hum = 40 %
You should see the information about temperature and humidity displayed as shown upper.

Note: The DHT11 and DHT22 sensors will only respond every second so if you are not getting data, be sure to wait few seconds before trying again.


RPi-Monitor configuration

Warning: Be sure to use Linux linefeed format with line ending with LF (and not CR/LF like in Windows).

Let's now use this information and add humidity graphs on existing temperature graph.

We first have to extract the data. This is done like this:

For more information about this configuration, refer to the post:  RPi-Monitor: Version 2.0 advance usage and customization

We will now add the humidity curve into the graph of temperature. This can be done with the configuration bellow:
As the unit are different than the one existing on the initial axis, we will add a second axis for the percentage of humidity. This is the purpose of the two last lines of the configuration bellow.
The first line is defining the usage of axis number 2 for the humidity.
The last line is defining how this graph should be drawn: On the right, starting from 0 up to 100.

graph_options can have other usefull option. They are described in the documentation of javascriptrrd.

After restarting RPi-Monotor with the command:
service rpimonitor restart
You will see a new curve in Temperature graph as shown in the screenshot bellow:

Graph with 2 Y axis: °C in left axis and % humidity (fixed from 0% to 100%) on right axis


65 comments :

  1. Hello.
    I am using Rpi-monitor for use radiooaficionado Raspberry with.
    But I am unable to join in a plot temp and hum with the DHT22.
    Adafruit command if I read well the values, but I can not do well because the temp change I always get 0.
    Can you help?

    dynamic.15.name=humidity
    dynamic.15.source=Adafruit_DHT 22 10
    dynamic.15.regexp=Hum = (\S+)
    dynamic.15.postprocess=$1/1
    dynamic.15.rrd=GAUGE

    dynamic.16.name=temperature
    dynamic.16.source=Adafruit_DHT 22 10
    dynamic.16.regexp=Temp = (\d+)$
    dynamic.16.postprocess=$1/1
    dynamic.16.rrd=GAUGE


    ==============================

    web.statistics.1.content.9.name=Temperature & Humidity BOX
    web.statistics.1.content.9.graph.1=humidity
    web.statistics.1.content.9.graph.2=temperature
    web.statistics.1.content.9.ds_graph_opts.humidity.label=Humidity (%)
    web.statistics.1.content.9.ds_graph_opts.temperature.label=Temperature (*C)
    web.statistics.1.content.9.ds_graph_opts.humidity.yaxis=1
    web.statistics.1.content.9.ds_graph_opts.temperature.yaxis=2
    web.statistics.1.content.9.graph_opts.y1axis={ position: "right", min: 0, max: 100 }
    web.statistics.1.content.9.graph_opts.y2axis={ position: "right", min: 0, max: 100 }

    ReplyDelete
    Replies
    1. Hello,

      The first thing is to check if the command from Adafruit is working. I guess you checked that. Be sure th install this command in /usr/bin to ensure it is in the path.

      To configure rpimonitor, you should ensure that the dynamic Id (15 and 16 in your example) are immédialtely followin the last number already existing in the configuration file.

      The same comment goes to the Id of web.satsistics.1.content.

      You don't need to pose process the result. You can let the temperature axis be defined automatically (remove y1axis).

      The regexp for temperature is wrong, it should be: dynamic.16.regexp=Temp = (\S+)

      I hope it will help.

      You can refer to github to see how I did customize my installation.
      https://github.com/XavierBerger/RPi-Monitor/blob/master/rpimonitor/custo.conf

      Delete
    2. Hello, I am having the same issue, I have changed the temp to (\S+), and my code is nearly identical. Cant quite get it to work. Any suggestions? Thanks

      Delete
    3. Hello,

      To define the exact command and regular expression to add in customized configuration file, it is recommended to test and validate the command before adding it into the configuration file. This can be done easily like this:

      COMMAND | perl -ne '/REGEXP/' and print "$1\n"'

      Example:

      Adafruit_DHT 11 27 | perl -ne '/Hum = (\S+)/' and print "$1\n"'

      The expected result is a valid number (integer or real).

      Note: $1 can be replaced by the porsprocessing formula.

      Once you are sure the value is extracted correctly, you can check if the configuration made is not going in conflict with other definition.

      Delete
    4. In fact there is a double space after the = sign in Adafruit_DHT's output.

      Putting two spaces between = and (\S+) works fine in my custom config, without the additional space it was returning 0.0.

      It looks like double spaces are suppressed in the comment publishing
      dynamic.16.regexp=Temp = (\S+)

      Delete
    5. remove $1/1 from dynamic.16.postprocess=
      and from
      dynamic.15.postprocess=
      Your code is playing with my rasp, and DHT 22.

      Delete
  2. Hello guys,

    I am also using DHT11 with adafruit code, and I found a possible bug.
    In the file Adafruit_DHT.c, line 94, the while loop waits for the gpio pin to rise.
    However, if for some reason this does not happens, the program hangs.
    So I added a counter (named safety) to wait maximum 1 millisec.
    If no answer comes, the function returns with error code 2.


    int safety=0;
    while (bcm2835_gpio_lev(pin) == 1 || safety > 1000) { // wait max 1000us
    usleep(1);
    safety++;
    }
    if (safety > 1000){ // if no answer, quit
    return 2;

    ReplyDelete
  3. My conf
    ########################################################################
    # Living root temperature and humidity added in dedicated pages
    ########################################################################
    dynamic.15.name=living_room_temp
    dynamic.15.source=Adafruit_DHT 2302 4
    dynamic.15.regexp=Temp = (\d+)$
    dynamic.15.postprocess=$1/1
    dynamic.15.rrd=GAUGE

    web.status.2.name=Living room
    web.status.2.content.1.name=Temperature
    web.status.2.content.1.icon=cpu_temp.png
    web.status.2.content.1.line.1="Ambiant Temperature: "+data.living_room_temp+"°C"

    web.statistics.2.name=Living room
    web.statistics.2.content.1.name=Temperature
    web.statistics.2.content.1.graph.1=living_room_temp
    web.statistics.2.content.1.ds_graph_options.living_room_temp.label=Ambient temp. (deg C)

    dynamic.16.name=humidity
    dynamic.16.source=Adafruit_DHT 22 4
    dynamic.16.regexp=Hum = (\S+)
    dynamic.16.postprocess=$1/1
    dynamic.16.rrd=GAUGE

    web.statistics.2.content.1.graph.2=humidity
    web.statistics.2.content.1.ds_graph_options.humidity.label=Humidity (%)
    web.statistics.2.content.1.ds_graph_options.humidity.yaxis=2
    #web.statistics.2.content.1.graph_options.legend= { position: "sw"}
    web.statistics.2.content.1.graph_options.y2axis={ position: "right", min: 0, max: 100 }

    dht22 on 4
    Humidty is ok but not temp. Adafruit_DHT 2302 4 write right temp and hum.
    What is wrong? Please help My Raspberry http://aiamaa.no-ip.org:8888

    ReplyDelete
    Replies
    1. I notice that command used as source is different... sometime 22 sontime 2302...
      You also use a postprocess command which have no sense: $1/1
      Did you check the regular expression? I would advise to read the comments I mase upper, you will certainly find interresting tips helping you to find the solution.

      Delete
  4. rpi-monitor 2.0
    /etc/rpimonitor.conf
    part of this file
    ########################################################################
    # Living root temperature and humidity added in dedicated pages
    ########################################################################
    dynamic.15.name=living_room_temp
    dynamic.15.source=Adafruit_DHT 22 4
    dynamic.15.regexp=Temp = (\d+)$
    dynamic.15.postprocess=$1/1000
    dynamic.15.rrd=GAUGE

    web.status.2.name=Living room
    web.status.2.content.1.name=Temperature
    web.status.2.content.1.icon=cpu_temp.png
    web.status.2.content.1.line.1="Ambiant Temperature: "+data.living_room_temp+"°C"

    web.statistics.2.name=Living room
    web.statistics.2.content.1.name=Temperature
    web.statistics.2.content.1.graph.1=living_room_temp
    web.statistics.2.content.1.ds_graph_options.living_room_temp.label=Ambient temp. (deg C)

    dynamic.16.name=humidity
    dynamic.16.source=Adafruit_DHT 22 4
    dynamic.16.regexp=Hum = (\S+)
    dynamic.16.postprocess=$1/1
    dynamic.16.rrd=GAUGE

    web.statistics.2.content.1.graph.2=humidity
    web.statistics.2.content.1.ds_graph_options.humidity.label=Humidity (%)
    web.statistics.2.content.1.ds_graph_options.humidity.yaxis=2
    #web.statistics.2.content.1.graph_options.legend= { position: "sw"}
    web.statistics.2.content.1.graph_options.y2axis={ position: "right", min: 0, max: 100 }

    not working.

    Adafruit_DHT 22 4 command working ok. Where is error ?

    ReplyDelete
    Replies
    1. What's not working? You description of the problem is not detailled enough to allow me to help you but I'll try....

      Did you check the regular expression as proposed in my previous answer? (Ref comment of September 10, 2013 at 11:34 AM) ... I guess no :-(.

      If the output of DHT22 is the same as DHT11:

      Temp = 24 *C, Hum = 40 %

      Then, your regular expression for tempetature is wrong. Remove the tailing $ and check the RegExp with the command line described upper.
      Once your regular expression will work, then add it into the configuration file.

      Delete
  5. Good morning Xavier,
    first thanks very much for your nice and valuable monitor!!
    I added the DHT11 to my RPI and found, thst every 2nd or 3rd measurement goes to zero, and so there are gaps in the graph. I think this is due to much to short delays between triggering of the readout program.
    My question is, how to stretch the delay between the measurements?

    Many Regards,
    Christoph

    ReplyDelete
    Replies
    1. Hi Christoph,

      The delay is configurable. There is a parameter to set into /etc/rpimonitord.conf.
      I let you read the comment in this file to find the parameter to update.
      This value will be active after restarting rpimonitord: sudo service rpimonitor restart

      Cheers,
      Xavier

      Delete
  6. Hi Xavier

    I really appreciate you making this tool available. Thank you.

    I am having trouble with a DHT22 and version 2.5.1. When I run on 2.4 version 2.4 I get nice clean graph.

    After updating to 2.5.1 I get a very noisey graph with lots of 0 values.

    If I downgrade to 2.4.1 the graph becomes clean again

    I think its because the DHT22 gives lots of unknown data readings and because the two versions of RPi-Monitor treat unknown data differently.

    Can you tell me a little about what

    "Update rrd graph with unkown data if fetched information is not a valid number"

    means in the 2.5.1 release notes?

    Regards
    Brian Pratt

    ReplyDelete
    Replies
    1. Hi Brian,

      RPi-Monitor is designed to graph the data extracted. In previous version the behavior of the graph was not reliable since sometime no data were stored in the RRD. Now, it stored the data extracted or unknow, there is no more hole in the RRD.
      You are experiencing a side effect now and it let me wonder if your previous graph was correct or not... Not sure that the timeline was correct.
      With a sensor which is not reliable, I would propose to do like this:
      1/Create a script which is getting the info from the sensor and updating a file when the data is correct.
      2/Configure Rpi-Monitor to read the information in this file.
      Like this, if your sensor doesn't send information, the data stored in RRD will be the same as the previous one.

      I think this will solve your issue.

      Rgds,
      Xavier

      Delete
  7. Hi Xavier,

    I can't put temperature readings from DHT22 to RPi-mon statistics. My DHT22 (AM2302) are working fine and I am able to get temp and hum data from it:
    sudo Adafruit_DHT 2302 18
    Using pin #18
    Data (40): 0x0 0xd1 0x1 0x2c 0xfe
    Temp = 30.0 *C, Hum = 20.9 %
    Can you help me to add both temperature and humidity data from DHT22 to RPi-monitor?

    ReplyDelete
    Replies
    1. Here is my config:


      dynamic.21.name=t5
      dynamic.21.source=Adafruit_DHT 2302 18
      dynamic.21.regexp=Temp = (\S+)
      dynamic.21.postprocess=
      dynamic.21.rrd=GAUGE

      dynamic.22.name=humidity
      dynamic.22.source=Adafruit_DHT 2302 18
      dynamic.22.regexp=Hum = (\S+)
      dynamic.22.postprocess=
      dynamic.22.rrd=GAUGE

      web.statistics.1.content.8.graph.7=t5
      web.statistics.1.content.8.ds_graph_options.t5.label=t5 (deg C)
      web.statistics.1.content.8.graph.8=humidity
      web.statistics.1.content.8.ds_graph_options.humidity.label=Humidity (%)
      web.statistics.1.content.8.ds_graph_options.humidity.yaxis=2
      web.statistics.1.content.8.graph_options.y2axis={ position: "right", min: 0, max: 100 }

      What's wrong with it?

      Delete
    2. Nothing obvious...
      I would advise to read upper comments about perl command to check the regular expression and to have a look to the sample files in github like https://github.com/XavierBerger/RPi-Monitor/blob/master/rpimonitor/custo.conf

      Delete
  8. Solved:

    dynamic.21.regexp=Temp =<--!!ADD TWO SPACES HERE!!-->(\S+)

    So, the line should be:

    dynamic.21.regexp=Temp = (\S+)

    And only ONE space for Humidity line:

    dynamic.22.regexp=Hum = (\S+)

    Take care!

    ReplyDelete
  9. Hi Xavier,

    first I would like to thank you for this great tool!
    It took me a bit of tinkering but now I got it (mostly) to show what I want.

    There is one thing that I would like to correct: I am reading information from a remote sensor into a file. Among other I read the voltage of the battery in form of a number like 115. Then I calculate the voltage 115*0.02+1 (3.3V) this value is stored in the database.
    dynamic.24.name=voltage
    dynamic.24.source=/home/pi/script/sensor.txt
    dynamic.24.regexp=/(.*?)/(.*?)/(.*)
    dynamic.24.postprocess=$3*0.02+1
    dynamic.24.rrd=GAUGE
    The status page shows 3.3 which is correct but the statistic page shows values like:
    3.3000000000000007
    3.2999999999999994
    Is there a way to correct this?

    Cheers
    Harry

    ReplyDelete
    Replies
    1. Ok here is how I solved the problem:
      web.statistics.2.content.3.graph_options.yaxis={min: 3, max: 5}
      This prevents it from auto-scaling the y-axis.

      Cheers
      Harry

      Delete
  10. Xaiver:

    This is a great tool, thanks for pulling it together.

    The DHT22 has an issue where it returns bad data if you query it too often. To work around that, I've created a script that queries the sensor once for temperature and humidity and then appends it to a file. The script is executed by cron on a periodic basis.

    I then configured rpimonitor to read that file for the values as follows:

    dynamic.17.name=ambient_humid
    dynamic.17.source=/home/pi/humid.out
    dynamic.17.regexp=Hum = (\S+)
    dynamic.17.postprocess=
    dynamic.17.rrd=GAUGE

    dynamic.18.name=ambient_temp
    dynamic.18.source=/home/pi/humid.out
    dynamic.18.regexp=Temp = (\S+)
    dynamic.18.postprocess=($1*1.8)+32
    dynamic.18.rrd=GAUGE

    Collection and graphing seem to be working as I expect, but I'm curious as to what method rpimonitor uses to read a file.

    If I'm reading the code right, sub Process() in package Monitor handles this. It looks to me as though it iterates through all lines in the data file and will write each value into the RRD. However, when I dump the rrd, I see far fewer datapoints than I'd expect if it were doing that. Instead, rpimonitor looks as though it is looking at the last line in the file only. (Which is what I want it to do.)

    Can you shed some light on this? Does rpimonitor read all lines and aggregate the data, or does it just read the last?

    Thanks.

    ReplyDelete
    Replies
    1. Hello,

      I didn't design rpimonitor to read more than one postprocess line and I don't know how it will behave if more than one.

      Cheers,

      Xavier

      Delete
  11. Hello Xavier!

    Thank you for your RPI monitor, its awesome, but something is not working for me.

    Well the DHT22 is works fine i get temperatures. But the graph is wrong, i can't do the same like your. This is my config and graph:

    https://dl.dropboxusercontent.com/u/13922338/Screen%20Shot%202013-12-31%20at%2017.18.07.png

    All i want same the cpu temperature or your graph, but i can't fix that. :(

    Best Regards,
    Szergely

    ReplyDelete
  12. Everything worked perfectly, thanks Xavier.

    ReplyDelete
  13. Hello Xavier, when I try to test Adafruit_DHT it says: sudo: Adafruit_DHT: command not found
    First I run:
    wget http://goo.gl/oadpl -O Adafruit_DHT
    sudo cp Adafruit_DHT /usr/bin/

    Do I need to chmod Adafruit_DHT?

    Thanks

    ReplyDelete
  14. Alright, I installed like the tutorial link above and copied to /usr/bin, now it works in terminal, I just have to write:
    'sudo Adafruit_DHT 2302 4' instead of 'Adafruit_DHT 2302 4', don't know why I need sudo...

    ReplyDelete
  15. Xavier, I edit the /etc/rpimonitord.conf/default.conf and added this:

    'dynamic.17.name=humidity
    dynamic.17.source=Adafruit_DHT 2302 4
    dynamic.17.regexp=Hum = (\S+)
    dynamic.17.postprocess=
    dynamic.17.rrd=GAUGE'

    and this:

    'web.statistics.1.content.8.graph.3=humidity
    web.statistics.1.content.8.ds_graph_options.humidity.label=Humidity (%)
    web.statistics.1.content.8.ds_graph_options.humidity.yaxis=2
    web.statistics.1.content.8.graph_options.y2axis={ position: "right", min: 0, max: 100 }'

    But know when I go to Statics in Rpi-monitor it gimes me the following error:

    'File stat/null.rrd is not a valid RRD archive!'

    note that I used 'dynamic.17.source=Adafruit_DHT 2302 4' instead of Adafruit_DHT 11 27

    Hope you can help me.

    ReplyDelete
  16. On the basis of all of the above I was able to do so. Everything works.

    dynamic.16.name=humidity
    dynamic.16.source=/home/pi/humid.out
    dynamic.16.regexp=Hum = (\S+)
    dynamic.16.postprocess=
    dynamic.16.rrd=GAUGE

    dynamic.17.name=temperature
    dynamic.17.source=/home/pi/humid.out
    dynamic.17.regexp=Temp = (\S+)
    dynamic.17.postprocess=
    dynamic.17.rrd=GAUGE


    web.statistics.1.content.9.name=Temperature & Humidity
    web.statistics.1.content.9.graph.1=humidity
    web.statistics.1.content.9.graph.2=temperature
    web.statistics.1.content.9.ds_graph_opts.humidity.label=Humidity (%)
    web.statistics.1.content.9.ds_graph_opts.temperature.label=Temperature (*C)
    web.statistics.1.content.9.ds_graph_opts.humidity.yaxis=1
    web.statistics.1.content.9.ds_graph_opts.temperature.yaxis=2
    web.statistics.1.content.9.graph_opts.y1axis={ position: "right", min: 0, max: $
    web.statistics.1.content.9.graph_opts.y2axis={ position: "right", min: 0, max: $

    Script that writes data to a file:
    #!/usr/bin/python

    import subprocess
    import re
    import sys

    while(True):
    output = subprocess.check_output(["./Adafruit_DHT", "22", "4"]);
    f1 = open("humid.out", 'w')
    f1.write (output)
    f1.close()
    print output
    matches = re.search("Temp =\s+([0-9.]+)", output)
    if (not matches):
    time.sleep(2)
    continue
    temp = float(matches.group(1))
    matches = re.search("Hum =\s+([0-9.]+)", output)
    if (not matches):
    time.sleep(2)
    continue
    humidity = float(matches.group(1))
    sys.exit()

    ReplyDelete
    Replies
    1. Alezxxx when I try to run your script this is what I get:

      "pi@raspberrypi ~ $ ./humid.out
      File "./humid.out", line 8
      output = subprocess.check_output(["./Adafruit_DHT", "22", "4"]);
      ^
      IndentationError: expected an indented block"

      Already tried with sudo and the result is the same.


      When I run: sudo ./Adafruit_DHT 22 4
      Using pin #4
      Data (40): 0x2 0x17 0x0 0xa9 0xc2
      Temp = 16.9 *C, Hum = 53.5 %

      The results are ok, but if I try to run without sudo this is what I get:
      "bcm2835_init: Unable to open /dev/mem: Permission denied"

      What I'm doing wrong?
      Hope you can help me.
      Thanks.

      Delete
    2. This comment has been removed by the author.

      Delete
  17. What is the problem with sampling? It's common for an undefined value. I have DHT11.
    Screnshot from graph:
    http://dl.dropbox.com/u/3577295/Kijel%C3%B6l%C3%A9s_015.png

    ReplyDelete
    Replies
    1. I often answer to such a question...
      You will now find the answer into the FAQ page.

      Delete
    2. Try to record the temperature and humidity readings in a file with check writing the correct value, and then add the file to the chart.

      Delete
  18. Dear Xavier,

    first of all, thank for sharing your work with us. I am not a programmer just a computer enthusiast. I am trying to do something...easy I think but due to lack of knowledge I stuck. I want to graph 3 sources on the same graph (I have a BMP085 sensor connected to a Pi), Temp, Hum and Pressure. The problem is the value of the barometric pressure which is hundred of times higher that the temperature and humidity and can't be represented on the same axis without jeopardizing the other two. I want to transfer the Pressure values on the left vertical axis of the graph table but...I don't know how! I have tried several things but no luck. Could you please help me ?

    Thanks in Advance!

    ReplyDelete
    Replies
    1. RPi-Monitor is fully configurable. Each configuration is different and have his specificity. It is not possible to provide a configuration for each situation.
      Nevertheless, to reach you objective, I would advise you to read carefully this article and try to reproduce what is described here sharply. Once this will work, you will have enough knowledge to update and customize your configuration file to your wishes.

      Delete
    2. Thanks for your reply. I solved it somehow by following your example. This is my configuration:

      dynamic.17.name=pressure
      dynamic.17.source=bmp085
      dynamic.17.regexp=Pressure (\S+)
      dynamic.17.postprocess=
      dynamic.17.rrd=GAUGE

      dynamic.18.name=humidity
      dynamic.18.source=nice -20 loldht 7
      dynamic.18.regexp=Humidity = (\S+)
      dynamic.18.postprocess=$1/1
      dynamic.18.rrd=GAUGE

      dynamic.19.name=temperature
      dynamic.19.source=bmp085
      dynamic.19.regexp=Temperature (\S+)
      dynamic.19.postprocess=$1/1
      dynamic.19.rrd=GAUGE

      web.statistics.1.content.9.name=PC Room
      web.statistics.1.content.9.graph.1=humidity
      web.statistics.1.content.9.graph.2=pressure
      web.statistics.1.content.9.graph.3=temperature
      web.statistics.1.content.9.ds_graph_options.humidity.label=Hum (%)
      web.statistics.1.content.9.ds_graph_options.pressure.label=Bar (hPa)
      web.statistics.1.content.9.ds_graph_options.temperature.label=Temp (*C)
      web.statistics.1.content.9.ds_graph_options.humidity.yaxis=1
      web.statistics.1.content.9.ds_graph_options.pressure.yaxis=2
      web.statistics.1.content.9.graph_options.y1axis={ position: "right", min: 0, max: 100 }
      web.statistics.1.content.9.graph_options.y2axis={ position: "left", min: 0, max: 1150 }


      Thanks again and keep up good work.

      Delete
  19. This comment has been removed by the author.

    ReplyDelete
  20. Hey,

    everytime i get this error:
    File stat/null.rrd is not a valid RRD archive!

    Here my code:

    ### Sensor 2
    dynamic.16.name=humidity
    dynamic.16.source=Adafruit_DHT 22 17
    dynamic.16.regexp=Hum = (\S+)
    dynamic.16.postprocess=
    dynamic.16.rrd=GAUGE

    dynamic.17.name=temper
    dynamic.17.source=Adafruit_DHT 22 17
    dynamic.17.regexp=Temp = (\S+)
    dynamic.17.postprocess=
    dynamic.17.rrd=GAUGE

    ### Sensor 2
    web.statistics.1.content.9.graph.3=humidity
    web.statistics.1.content.9.ds_graph_options.humidity.label=Humidity (%)
    web.statistics.1.content.9.ds_graph_options.humidity.yaxis=2
    web.statistics.1.content.9.graph_options.y2axis={ position: "right", min: 0, max: 100 }

    web.statistics.1.content.10.graph.3=temper
    web.statistics.1.content.10.ds_graph_options.temper.label=Temp (deg C)
    web.statistics.1.content.10.ds_graph_options.temper.yaxis=2
    web.statistics.1.content.10.graph_options.y2axis={ position: "right", min: 0, max: 50 }

    Thanks!

    ReplyDelete
    Replies
    1. When I read your comment, I thought "Where this 'graph.3' is coming from?" and I finally realized that it comes from the text of this post. This mistake certainly come from the spell check I made recently. The post is fixed.
      You should just change "graph.3" by "name" and it should work.

      Delete
    2. Working version

      dynamic.17.name=humidity
      dynamic.17.source=Adafruit_DHT 22 4
      dynamic.17.regexp=Hum = (\S+)
      dynamic.17.postprocess=
      dynamic.17.rrd=GAUGE

      dynamic.18.name=temp
      dynamic.18.source=Adafruit_DHT 22 4
      dynamic.18.regexp=Temp = (\S+)
      dynamic.18.postprocess=
      dynamic.18.rrd=GAUGE

      web.statistics.1.content.9.name=Temperature & Humidity
      web.statistics.1.content.9.graph.1=humidity
      web.statistics.1.content.9.graph.2=temp
      web.statistics.1.content.9.ds_graph_options.humidity.label=Humidity (%)
      web.statistics.1.content.9.ds_graph_options.temp.label=Temperature (*C)
      web.statistics.1.content.9.ds_graph_options.humidity.yaxis=1
      web.statistics.1.content.9.ds_graph_options.temp.yaxis=2
      web.statistics.1.content.9.graph_options.y1axis={ position: "right", min: 0, max: 100 }
      web.statistics.1.content.9.graph_options.y2axis={ position: "right", min: 0, max: 100 }

      Delete
  21. Hey thanks for your answer.
    I have change the code and I don't have this error anymore, but now when i open the site it's loading and loading and loading, no statistics come...
    Sorry for my bad english...

    ReplyDelete
  22. Hey thanks for the code, but now i have no value at temperature. Hum works! But not Temp... :(

    ReplyDelete
    Replies
    1. Need to line dynamic.18.regexp = Temp = sentry 2 spaces (\ S +)

      Delete
    2. Yeah it works!!! I thank you for your help with the code! :)

      Delete
  23. At last, just did it! There is no more leaky DHT11 graph! :) I was a little modified the python script.
    Screnshot: http://goo.gl/Ip9H5k

    The script create a log directly, not using the print method:


    ...
    if humidity is not None and temperature is not None:

    line= 'Temp = {0:0.0f} *C, Hum = {1:0.0f} %'.format(temperature, humidity)
    print line
    file = open("/var/log/dht11.log", "w")
    file.write(line)
    file.close()

    else:
    print 'Failed to get reading. Try again!'



    The CRON run every minute:
    */1 * * * * sudo /home/pi/Adafruit_Python_DHT/examples/./AdafruitDHT.py 11 4 >/dev/null 2>&1

    The RPi-Monitor read the log, the sensor isn't directly query by it (see my temp.conf):

    dynamic.16.name=temp_in
    dynamic.16.source=cat /var/log/dht11.log
    dynamic.16.regexp=Temp = (\S+)
    dynamic.16.postprocess=$1/1
    dynamic.16.rrd=GAUGE

    dynamic.17.name=humidity_in
    dynamic.17.source=cat /var/log/dht11.log
    dynamic.17.regexp=Hum = (\S+)
    dynamic.17.postprocess=$1/1
    dynamic.17.rrd=GAUGE
    ...

    ReplyDelete
    Replies
    1. in your configuration, 'cat' is not needed. By default, RPi-Monitor read the content of a file given as source. Removing 'cat' will reduce the load of your system (a little bit...).

      Delete
    2. Such a script has been requested many time.
      Can you share the final version of your script (dropbox link)?
      I'll add it into the script directory and provide it with the future release of RPi-Monitor.

      Delete
    3. Forked version of it on GitHub. :) The original version created by Adafruit.

      Delete
  24. I finally got a 22 in the mail this morning, so this one had to be tested :)
    In order to get this graph displayed, I had to alter the configuration part that was given (and saw later on other people did so as well :) )
    I altered the line "web.statistics.1.content.8.name=humidity" into "web.statistics.1.content.8.graph.3=humidity" and then it worked fine .. with the orinial line, I got the temperature statistics renamed to humidity but humidity wasn't showing up :)
    Thanks again Xavier

    ReplyDelete
  25. Thanks to Sancho and all the people participating! I have just set up the logging using the script that Sancho posted about 2 weeks ago. It is called every minute (cron job modified for use with DHT22). There is just one problem left that I cannot work out: the graph displayed has a not the correct scaling. For humidity and temperature it should be 0 to 100 (for both) but on the left side of the graph I only get a scale from 0 to 60 (humidity)! The right side displays 0 to 100 properly. What is wrong about this config?
    ##############################
    dynamic.17.name=humidity
    dynamic.17.source=/var/log/dht11.log
    dynamic.17.regexp=Hum = (\S+)
    dynamic.17.postprocess=
    dynamic.17.rrd=GAUGE

    dynamic.18.name=temp
    dynamic.18.source=/var/log/dht11.log
    dynamic.18.regexp=Temp = (\S+)
    dynamic.18.postprocess=
    dynamic.18.rrd=GAUGE

    ###########################

    web.statistics.1.content.9.name=Temperatur & Luftfeuchtigkeit
    web.statistics.1.content.9.graph.1=humidity
    web.statistics.1.content.9.graph.2=temp
    web.statistics.1.content.9.ds_graph_options.humidity.label=rel. Luftfeuchte (%)
    web.statistics.1.content.9.ds_graph_options.temp.label=Temperatur (*C)
    web.statistics.1.content.9.ds_graph_options.humidity.yaxis=1
    web.statistics.1.content.9.ds_graph_options.temp.yaxis=2
    web.statistics.1.content.9.graph_options.y1axis={ position: "right", min: 0, max: 100 }
    web.statistics.1.content.9.graph_options.y2axis={ position: "right", min: 0, max: 100 }

    Another question is how are negative temperatures treated / is negative scale allowed? The Sensor is mounted outside the house and will pick up negatiev temps of course.

    Any help is much appreciated!


    ReplyDelete
    Replies
    1. One strange thing on your configuration is that you add both axis on the "right". I don't know how rrdFlot is behaving in such a situation.
      For the temperature, I would advise to not define axis and let the graph generator manage it. If you really want to define your axis, I think negative value is allowed for min parameter.

      Delete
  26. Thanks for your reply Xavier! It does not not matter in the graph drawn if I set the position of y1axis (humidity scale) to left or right. Also the min and max values for manually scaling this graph are ignored and instead auto-scaled always. Here is a screenhot how it looks like with the above configuration: http://abload.de/img/rpidbj1zgc.jpg
    The strange thing is that y2axis (temperature) behaves exactly as configured (while the config format is identical)! It rather seems to be a problem when using multiple axis.
    If possible I would like to avoid autoscaling both axis and set them manually.

    PS: I can confirm that negative values work :)

    ReplyDelete
  27. Hi Again,

    I have installed rpimonitor to a raspberry pi in order to monitor two sensors. A DHT22 and a BMP085. Every time I have to restart Pi for some reason, the rpimonitor stops reading the sensors and create graphs. I have to manually stop and start the service in order to get readings and graphs again. This is happening only with those two sensors. The rest graphs works after Pi restart. Any advice ?

    Thanks!

    ReplyDelete
    Replies
    1. I would bet you did enter the command to extract data whitout the full path. For example 'gettemp.sh' instead of /usr/bin/gettemp.sh'.
      The first command is working in your shell because the variable $PATH is set and contains '/usr/bin'. When you start your computer, the $PATH variable is not set so 'gettemp.sh' will not work. The solution is to use the full path command '/usr/bin/gettemp.sh'

      Delete
  28. Hello Xavier,

    you were 100% right. That was the problem. I entered the full command path and now it works. Thanks for your prompt reply. Keep the good work up!

    Nikolas

    ReplyDelete
  29. Thank you very much for this.
    I am very much looking forward to having this functional but have seemed to come to an impasse that surely can be accredited to my novice skill level with the Pi.

    After installing all software and wiring, I was receiving an error stating
    "Adafruit_DHT command not found"
    I found elsewhere the instruction to execute:
    "sudo chmod 777 /usr/bin/Adafruit_DHT"
    after which I appeared to have communication but still no results produced.
    I now receive the prompt "Using pin #xx", but no data is produced (I've tried a couple different pins)

    I've noticed that if I specify a pin that I am not using (ex: sudo Adafruit_DHT 11 25)
    I get:
    "Using pin #25
    Data (0) 0x0 0x0 0x0 0x0 0x0"

    Any suggestions as to how I could proceed from here?

    ReplyDelete
    Replies
    1. First, use complete path into your configuration instead of relative:
      /usr/bin/Adafruit_DHT instead of Adafruit_DHT

      Secondly, you can have a look the the FAQ of RPi-Monitor's blog, you may find interresting tips.

      Finally, Adafruit_DHT as its prefix says is coming from adafruit.com. Its usage is described in this page: https://learn.adafruit.com/dht/overview
      RPi-Monitor is just using the data given by this application (as it does from others). Once will work, I would advise to use RPi-Monitor Interactive (rpimonitor -i) to setup your configuration file.

      Delete
    2. Better link to adafruit site: https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging

      Delete
  30. I use a DTH11 and alternatively DTH22 sensor.
    Why is the measurement series so sketchy.
    and what I do not understand why I have to ask twice for the sensor temperature and humidity?

    ReplyDelete
  31. I was very sad about instability of DHT11 sensor and made some tricky soft update.
    Here it is :

    ...
    int ok = 0 ; // global variable , our flaf that read value is not ok when we start
    ...

    void read_dht11_dat(){
    ...
    if((j>=40) && (...) {
    printf("Temp = %d *C, Hum = %d \%\n", data[2], data[0]);
    ok=1; // global variable changes to 1 as soon as we recieve good data
    }

    ...
    }

    int main(){
    ...

    while(ok==0){
    read_dht11_dat();
    delay(500);
    }
    ....

    return 0;
    }

    ReplyDelete
  32. Latest AdafruitDHT lib changed the Humidity title, my config using GPIO 23:

    dynamic.1.name=living_room_temp
    dynamic.1.source=AdafruitDHT.py 11 23
    dynamic.1.regexp=Temp=(\d+.\d+)
    dynamic.1.postprocess=
    dynamic.1.rrd=GAUGE

    dynamic.2.name=humidity
    dynamic.2.source=AdafruitDHT.py 11 23
    dynamic.2.regexp=Humidity=(\d+.\d+)
    dynamic.2.postprocess=
    dynamic.2.rrd=GAUGE

    Anyway I've used fraglord2000 script modified to also store a time,temp,humidy log in var/log.
    Thanks

    ReplyDelete
  33. Also, donation sent, thanks for this awesome piece of software!

    ReplyDelete