Skip to content

Instantly share code, notes, and snippets.

@bmidgley
Created March 9, 2016 04:00
Show Gist options
  • Save bmidgley/0f9d4e23147697ee892c to your computer and use it in GitHub Desktop.
Save bmidgley/0f9d4e23147697ee892c to your computer and use it in GitHub Desktop.
collect scores from multiple beans
#!/usr/bin/env python
import blescan
import sys
import re
import bluetooth._bluetooth as bluez
dev_id = 0
try:
sock = bluez.hci_open_dev(dev_id)
print "ble thread started"
except:
print "error accessing bluetooth device..."
sys.exit(1)
blescan.hci_le_set_scan_parameters(sock)
blescan.hci_enable_le_scan(sock)
scores = {}
names = {"0": "sl0ths", "1": "1eaps", "2": "2leepers", "3": "33ls", "4": "4appy"}
while True:
returnedList = blescan.parse_events(sock, 10)
for beacon in returnedList:
score = beacon.split(",")
match = re.search('a495a10(\d)c5b14b44b5121370f02d74de', score[1])
if match:
scores[match.group(1)] = score[2]
for key in sorted(scores):
print "Player %s bumps: %s" % (names[key], scores[key])
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment