Einleitung
(Zurück zum Inhaltsverzeichnis)
Voraussetzung ist, das SNMP und der I2C-Bus bereits eingerichtet sind.
Desweiteren habe ich mich an diese (private!) OID-Liste gehalten
MRTG ist hierfür nicht nötig.
Eigentlich ist es ein (hm) Abfallprodukt aus der Grabbelkiste, das mich hin und wieder anlächelte.
Es entstand so nebenbei eine Anzeige mit einen Oled-Display.
Ein Arbeitskollege hatte es mir mal hier mitbestellt.
Eine Library fand sich hier, und so entstand dann dieses "Abfallprojekt".
Da ich zur Zeit ein bißchen mit SNMP herumspiele, kam mir die Idee, auf dem Display die Umgebungswerte anzuzeigen.
Erstmal das Script:
#!/usr/bin/python
import os, sys
import commands
from time import sleep
from datetime import datetime
from lib_oled96 import ssd1306
from PIL import ImageFont, ImageDraw, Image
from smbus import SMBus # These are the only two variant lines !!
i2cbus = SMBus(1) #
oled = ssd1306(i2cbus)
# Display
width = 127
height = 63
# SNMP Client
Client = "raspi13"
Pass = "public"
# OIDs
oid_temp = ".1.3.6.1.2.1.25.1.40.1"
oid_hum = ".1.3.6.1.2.1.25.1.41.1"
oid_press = ".1.3.6.1.2.1.25.1.42.1"
oid_absHum = ".1.3.6.1.2.1.25.1.43.1"
oid_DP = ".1.3.6.1.2.1.25.1.44.1"
def snmp_temp():
args = "/usr/bin/snmpget -v1 -Oqv -c " + Pass + " " + Client + " " + oid_temp
temp = float(commands.getoutput(args))
# print "Temp: %s C" % str(temp / 1000)
return "Temp: %s C" % str(temp / 1000)
def snmp_hum():
args = "/usr/bin/snmpget -v1 -Oqv -c " + Pass + " " + Client + " " + oid_hum
hum = float(commands.getoutput(args))
# print "Humitity: %s%%" % str(hum / 1000)
return "Humitity: %s%%" % str(hum / 1000)
def snmp_press():
args = "/usr/bin/snmpget -v1 -Oqv -c " + Pass + " " + Client + " " + oid_press
press = float(commands.getoutput(args))
# print "Press: %s hPa" % str(press / 10)
return "Press: %s hPa" % str(press / 10)
def snmp_absHum():
args = "/usr/bin/snmpget -v1 -Oqv -c " + Pass + " " + Client + " " + oid_absHum
ahum = float(commands.getoutput(args))
# print "Abs.Hum: %s g/m^3" % str(ahum / 1000)
return "Abs.Hum: %s g/m^3" % str(ahum / 1000)
def snmp_DP():
args = "/usr/bin/snmpget -v1 -Oqv -c " + Pass + " " + Client + " " + oid_DP
dewpoint = float(commands.getoutput(args))
# print "Dewpoint: %s C" % str(dewpoint / 1000)
return "Dewpoint: %s C" % str(dewpoint / 1000)
oled.cls()
draw = oled.canvas
font = ImageFont.load_default()
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((2, 0), str(datetime.now().strftime('%Y %m %d %H:%M:%S')), font=font, fill=1)
draw.text((2, 10), snmp_temp(), font=font, fill=1)
draw.text((2, 20), snmp_hum(), font=font, fill=1)
draw.text((2, 30), snmp_press(), font=font, fill=1)
draw.text((2, 40), snmp_DP(), font=font, fill=1)
draw.text((2, 50), snmp_absHum(), font=font, fill=1)
oled.display()
Alles anzeigen
Die Variablen Client und Pass sollte man auf sein eigenes System anpassen.
Auch die OIDs sind nur Vorschläge.
Dann kopiert man noch das File: "lib_oled96.py" aus dem oben erwähnten Github nach /usr/local/bin,
Dann sollte ein Aufruf mit:
das Oled zur Anzeige bringen.
Das Script wird bei mir alle 5 min. über cron aufgerufen, der Start sollte aber 5-10s verzögert werden,
da zur gleichen Zeit auch der(die) Client(s) seine(ihre) Werte aktualisieren. Zumindestens bei mir.
Wo sich die Messstation befindet, spielt dank SNMP hier keine Rolle mehr.
Was man sonst noch damit anfangen kann? Soviel Phantasie kann ich mir garnicht vorstellen
Damit ihr wisst, wovon der alte Sack überhaupt schreibt:
MfG
Jürgen
Edit: Oled-Link korrigiert