Raspberry Pi: Temperature & Humidity Sensor (DHT22) - How to display values in LibreNMS

Hi,

I am using a docker container of LibreNMS to monitor several devices in my network, including a Raspberry Pi with a DHT22 sensor (temperature & humidity) connected to it.
On the Raspberry Pi, SNMP is installed and configured, as described in “Applications - LibreNMS Docs” and in “Check_MK Setup - LibreNMS Docs”.
The expected values are diaplay in LibreNMS:

Regarding the connected DHT22 sensor, I was able to include the values temperature & humidity values from the sensor into the SNMP response using following configuration in “snmp.conf” and using following scripts:

/etc/snmp/snmpd.conf

pass .1.3.6.1.2.1.25.1.8.2 /bin/sh /usr/local/bin/DHT-temp-snmp
pass .1.3.6.1.2.1.25.1.8.1 /bin/sh /usr/local/bin/DHT-hum-snmp
extend temp /bin/sh /usr/local/bin/DHT-temp-snmp -g
extend hum /bin/sh /usr/local/bin/DHT-hum-snmp -g

/usr/local/bin/DHT-temp-snmp (same approach for “DHT-hum-snmp”)

#!/bin/bash
if [ “$1” = “-g” ]
then
python3 /usr/local/bin/DHT-temp-snmp.py
fi
exit 0

/usr/local/bin/DHT-temp-snmp.py (same approach for “DHT-hum-snmp.py”)

#!/usr/bin/python3
import sys
import Adafruit_DHT

pin = “4”;
sensor = Adafruit_DHT.DHT22;

humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)

if humidity is not None and temperature is not None:
_ print(‘.1.3.6.1.2.1.25.1.8.2’)_
_ print(‘gauge’)_
_ print(‘{0:0.1f}’.format(temperature))_
else:
_ print(‘Failed to get reading. Try again!’)_
_ sys.exit(1)_

This part is working fine and the SNMP response in LibreNMS is:

.1.3.6.1.4.1.8072.1.3.2.3.1.1.3.104.117.109 = STRING: “.1.3.6.1.2.1.25.1.8.1”
.1.3.6.1.4.1.8072.1.3.2.3.1.1.4.116.101.109.112 = STRING: “.1.3.6.1.2.1.25.1.8.2”
.1.3.6.1.4.1.8072.1.3.2.2.1.2.3.104.117.109 = STRING: “/bin/sh”
.1.3.6.1.4.1.8072.1.3.2.2.1.2.4.116.101.109.112 = STRING: “/bin/sh”
.1.3.6.1.4.1.8072.1.3.2.2.1.3.3.104.117.109 = STRING: “/usr/local/bin/DHT-hum-snmp -g”
.1.3.6.1.4.1.8072.1.3.2.2.1.3.4.116.101.109.112 = STRING: “/usr/local/bin/DHT-temp-snmp -g”
.1.3.6.1.4.1.8072.1.3.2.4.1.2.3.104.117.109.1 = STRING: “.1.3.6.1.2.1.25.1.8.1”
.1.3.6.1.4.1.8072.1.3.2.4.1.2.3.104.117.109.2 = STRING: “gauge”
.1.3.6.1.4.1.8072.1.3.2.4.1.2.3.104.117.109.3 = STRING: “41.2”
.1.3.6.1.4.1.8072.1.3.2.4.1.2.4.116.101.109.112.1 = STRING: “.1.3.6.1.2.1.25.1.8.2”
.1.3.6.1.4.1.8072.1.3.2.4.1.2.4.116.101.109.112.2 = STRING: “gauge”
.1.3.6.1.4.1.8072.1.3.2.4.1.2.4.116.101.109.112.3 = STRING: “28.3”

But I did not find a way to display those values in the “Overview” section of this device in LibreNMS. Does anyone knows how to configure LibreNMS in order to have those values correctly displayed?

Thanks in advance for your help and kind regards.

Hi,
Does anyone have a similar configuration and/or know how to set it up?
Thanks and kind regards.

Hi,

You need to define your own operating system in LibreNMS, then use one of your own OIDs as a way for LibreNMS to recognize it from a standard Raspberry device.
When done, you can create include/definitions/discovery/yourownos.yaml which will graph any sensor you like. look at the other yaml files in that directory, search for sensors of temperature and humidity type. You also need to write your own mibfile to do a proper YAML discovery.

Hi PipoCanaja,

Thanks a lot for your answer!

Do you perhaps have a few details (or better a tutorial / links) on how to setup this up?
I am a newbie for this kind of configuration in LibreNMS…

Thanks in advance and kind regards.

The documentation is here :
https://docs.librenms.org/Developing/Support-New-OS/

You can come back here to ask questions of course. Discord is also a good way to get some help in the Devel chan.

Hi crivchri,

Is this coding suitable for DHT11 sensor ? Seeking your advise. Thanks