Created
April 15, 2018 19:07
-
-
Save danielkucera/fe8e4792d988e320c7af35838a65494a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python -u | |
from bluepy.btle import Scanner, DefaultDelegate | |
import json | |
import subprocess | |
myDevices = [ | |
"f8:f6:98:d7:33:fd", #gas meter | |
"f8:6a:94:76:a3:76", #power meter | |
] | |
zabbixParams = [ "zabbix_sender", "-c", "/etc/zabbix/zabbix_agentd.conf", "-s", "p.danman.eu" ] | |
def zabbixSend(key, value): | |
cmd = zabbixParams+["-k", str(key), "-o", str(value)] | |
print "sending", cmd | |
popen = subprocess.Popen(cmd) | |
print "send returned" | |
class ScanDelegate(DefaultDelegate): | |
def __init__(self): | |
DefaultDelegate.__init__(self) | |
scanner = Scanner().withDelegate(ScanDelegate()) | |
while True: | |
devices = scanner.scan(1.0) | |
for dev in devices: | |
if dev.addr in myDevices: | |
print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi) | |
for (adtype, desc, value) in dev.getScanData(): | |
rawval = "" | |
if desc == "Manufacturer": | |
rawval = value.decode("hex").encode("ascii") | |
j = json.loads(rawval) | |
for key, val in j.iteritems(): | |
zkey=str("ble."+key+"["+dev.addr+"]") | |
zabbixSend(zkey, val) | |
print " %s = %s, %s" % ( desc, value, rawval) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment