51 lines
1.5 KiB
Python
Executable File
51 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Paul Wiegmans (p.wiegmans@bonhoeffer.nl)
|
|
2009 dec 18
|
|
This munin-node plugin reads a temperature value from a serial port,
|
|
provided by a Arduino with temperature sensor.
|
|
For details see: http://amber.bonhoeffer.nl/temperatuur/
|
|
|
|
|
|
Linux: "/dev/usb/ttyUSB[n]" or "/dev/ttyUSB[n]"
|
|
first for for RedHat, second form for Debian.
|
|
e.g. "/dev/usb/ttyUSB0"
|
|
"""
|
|
|
|
import sys
|
|
|
|
import serial
|
|
|
|
|
|
# Open named port at "19200,8,N,1", 1s timeout::
|
|
def gettemperature():
|
|
connection = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
|
|
# default to munin's value "unknown"
|
|
result = "U"
|
|
while True:
|
|
line = connection.readline().strip()
|
|
if line:
|
|
# temperature in tenths celsius
|
|
temp = str(line.split(" ")[0])
|
|
# return only integer value (as a string)
|
|
result = temp[:-1]
|
|
break
|
|
connection.close()
|
|
return result
|
|
|
|
|
|
# shamelessly copied from weather_temp_
|
|
if len(sys.argv) == 2 and sys.argv[1] == "autoconf":
|
|
print("yes")
|
|
elif len(sys.argv) == 2 and sys.argv[1] == "config":
|
|
print('graph_title Temperatuur in de serverruimte')
|
|
print('graph_vlabel temperature in C')
|
|
print('graph_category sensors')
|
|
print('temperature.label temperature')
|
|
print('graph_info Dit is de temperatuur in het rek in de serverruimte B104')
|
|
print('graph_scale no')
|
|
# lower limit 10, upper limit 50
|
|
print('graph_args --base 1000 -l 10 -u 50')
|
|
else:
|
|
print('temperature.value %s' % gettemperature())
|