2009-12-18 12:19:14 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
|
|
|
Paul Wiegmans (p.wiegmans@bonhoeffer.nl)
|
|
|
|
2009 dec 18
|
2018-08-02 02:03:42 +02:00
|
|
|
This munin-node plugin reads a temperature value from a serial port,
|
2009-12-18 12:19:14 +01:00
|
|
|
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, serial
|
|
|
|
|
|
|
|
# Open named port at "19200,8,N,1", 1s timeout::
|
|
|
|
|
|
|
|
def gettemperature():
|
|
|
|
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
|
|
|
|
t = 0
|
|
|
|
while t<1:
|
|
|
|
line = ser.readline().strip()
|
|
|
|
if line:
|
|
|
|
temp = str(line.split(" ")[0]) # temperature in tenths celsius
|
|
|
|
i = len(temp)-1
|
|
|
|
temp = temp[:i] # return only integer value (as a string)
|
|
|
|
return temp
|
|
|
|
t += 1
|
|
|
|
ser.close()
|
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
# shamelessly copied from weather_temp_
|
2009-12-18 12:19:14 +01:00
|
|
|
|
|
|
|
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'
|
2017-02-24 05:01:30 +01:00
|
|
|
print 'graph_category sensors'
|
2009-12-18 12:19:14 +01:00
|
|
|
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()
|
|
|
|
|
2018-08-02 02:03:42 +02:00
|
|
|
|