Last active
October 8, 2020 13:21
-
-
Save itskenny0/96d02f96deb5bda8b215e39f810b31ba to your computer and use it in GitHub Desktop.
Scans for BLE devices and publishes found devices to nsq topic.
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
from bluepy.btle import Scanner, DefaultDelegate | |
import json | |
import time | |
import gnsq | |
nsq = gnsq.Producer('127.0.0.1:4150') | |
nsq.start() | |
class ScanDelegate(DefaultDelegate): | |
def __init__(self): | |
DefaultDelegate.__init__(self) | |
def handleDiscovery(self, dev, isNewDev, isNewData): | |
output = {'ts': time.time(), 'rssi': dev.rssi, 'mac': dev.addr} | |
for (adtype, desc, value) in dev.getScanData(): | |
#if desc in ["Complete Local Name"]: | |
output[desc.replace(" ", "")] = value; | |
jsonOut = json.dumps(output) | |
nsq.publish('bluetooth', jsonOut) | |
scanner = Scanner().withDelegate(ScanDelegate()) | |
devices = scanner.scan(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment