Created
November 26, 2019 13:47
-
-
Save itskenny0/ae263358a5d08c1f9696e617d7a95256 to your computer and use it in GitHub Desktop.
submit scanned BLE devices into NSQ queue in JSON format
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