forked from yanjost/munin-rpi-internal-temp
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrpi-dht-sensor_
executable file
·63 lines (55 loc) · 1.7 KB
/
rpi-dht-sensor_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
# A basic munin-node plugin for AOSONG DHT11, DHT22, AM2302 sensors.
# Temperature and Humidity
# USAGE
# Please make the symlink as rpi-dht-sensor_TYPE_GPIOPIN
# Example rpi-dht-sensor_2302_24
sensor_GPIO=${0##*/rpi-dht-sensor_*_}
sensor_TYPE=${0##*/rpi-dht-sensor_}
#echo $sensor_GPIO
#echo ${sensor_TYPE%_*}
#function read_SENSOR {
# data=$( /usr/local/bin/AdafruitDHT.py ${sensor_TYPE%_*} $sensor_GPIO | tail -1 )
# if [[ "$data" =~ "Data" ]]; then
# return "#E#"
# else
# return "humidity.value ${data:23:4}\ntemp.value ${data:8:4}"
# fi
#}
if [[ ! "11 22 2302" =~ "${sensor_TYPE%_*}" ]]; then
echo "Please add a sensor type to the symlink. See usage!"
elif [[ ! "$sensor_GPIO" =~ [0-9] ]]; then
echo "Please specify the GPIO pin!"
elif [ "$1" == "autoconf" ]; then
if [ -e /usr/local/bin/AdafruitDHT.py ]; then
echo "yes"
else
echo "no"
exit 1
fi
elif [ "$1" == "config" ]; then
echo "graph_title Raspberry Pi Aosong ${sensor_TYPE%_*} Sensor"
echo "graph_vlabel Humidity and Temperature"
echo "graph_category Sensors"
echo "temp.warning 30"
echo "temp.critical 40"
echo "temp.label Temperature in Celsius"
echo "humidity.label Humidity in Percent"
echo "err.label Error Counter"
else
OK=0
while [ "$OK" -gt -1 ]; do
data=$( /usr/local/bin/AdafruitDHT.py ${sensor_TYPE%_*} $sensor_GPIO)
if [[ "${sensor_TYPE%_*}" =~ "11" ]]; then
echo "humidity.value ${data:21:4}"
echo "temp.value ${data:5:4}"
echo "err.value $OK"
OK=-1;
else
echo "humidity.value ${data:21:4}"
echo "temp.value ${data:5:4}"
echo "err.value $OK"
OK=-1;
fi
done
fi