root / plugins / system / read_serial_temperature @ 6ffdebec
Historique | Voir | Annoter | Télécharger (1,32 ko)
| 1 |
#!/usr/bin/env python |
|---|---|
| 2 |
""" |
| 3 |
Paul Wiegmans (p.wiegmans@bonhoeffer.nl) |
| 4 |
2009 dec 18 |
| 5 |
This munin-node plugin reads a temperature value from a serial port, |
| 6 |
provided by a Arduino with temperature sensor. |
| 7 |
For details see: http://amber.bonhoeffer.nl/temperatuur/ |
| 8 |
|
| 9 |
|
| 10 |
Linux: "/dev/usb/ttyUSB[n]" or "/dev/ttyUSB[n]" |
| 11 |
first for for RedHat, second form for Debian. |
| 12 |
e.g. "/dev/usb/ttyUSB0" |
| 13 |
""" |
| 14 |
|
| 15 |
import sys, serial |
| 16 |
|
| 17 |
# Open named port at "19200,8,N,1", 1s timeout:: |
| 18 |
|
| 19 |
def gettemperature(): |
| 20 |
ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
|
| 21 |
t = 0 |
| 22 |
while t<1: |
| 23 |
line = ser.readline().strip() |
| 24 |
if line: |
| 25 |
temp = str(line.split(" ")[0]) # temperature in tenths celsius
|
| 26 |
i = len(temp)-1 |
| 27 |
temp = temp[:i] # return only integer value (as a string) |
| 28 |
return temp |
| 29 |
t += 1 |
| 30 |
ser.close() |
| 31 |
|
| 32 |
# shamelessly copied from weather_temp_ |
| 33 |
|
| 34 |
if len(sys.argv) == 2 and sys.argv[1] == "autoconf": |
| 35 |
|
| 36 |
print "yes" |
| 37 |
|
| 38 |
elif len(sys.argv) == 2 and sys.argv[1] == "config": |
| 39 |
|
| 40 |
print 'graph_title Temperatuur in de serverruimte' |
| 41 |
print 'graph_vlabel temperature in C' |
| 42 |
print 'graph_category sensors' |
| 43 |
print 'temperature.label temperature' |
| 44 |
print 'graph_info Dit is de temperatuur in het rek in de serverruimte B104' |
| 45 |
print 'graph_scale no' |
| 46 |
# lower limit 10, upper limit 50 |
| 47 |
print 'graph_args --base 1000 -l 10 -u 50' |
| 48 |
|
| 49 |
else: |
| 50 |
|
| 51 |
print 'temperature.value %s' % gettemperature() |
| 52 |
|
| 53 |
|
