nrf5/sdk: Adding work-in-progress script to connect to bluetooth le REPL using bluepy python module in linux.

This commit is contained in:
Glenn Ruben Bakke 2017-02-04 01:12:30 +01:00
parent 4ddc213d7f
commit 918617d1eb
1 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,46 @@
from bluepy.btle import Scanner, DefaultDelegate, Peripheral, UUID
import struct
class NotificationDelegate(DefaultDelegate):
def __init__(self):
DefaultDelegate.__init__(self)
def handleNotification(self, cHandle, data):
print data
def find_mac_by_name(name):
scanner = Scanner(iface=1)
devices = scanner.scan(5.0)
found_device = None
for dev in devices:
print "Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi)
for (adtype, desc, value) in dev.getScanData():
if (desc == "Short Local Name"):
if value == name:
found_device = dev
break
if found_device:
break
return dev
dev = find_mac_by_name("micr")
peri = Peripheral(dev)
peri.setDelegate(NotificationDelegate())
# service = peri.getServiceByUUID(UUID("6e400001-b5a3-f393-e0a9-e50e24dcca9e"))
rx_char = peri.getCharacteristics(uuid=UUID("6e400002-b5a3-f393-e0a9-e50e24dcca9e"))[0]
tx_char = peri.getCharacteristics(uuid=UUID("6e400003-b5a3-f393-e0a9-e50e24dcca9e"))[0]
# enable cccd
cccd = peri.writeCharacteristic(0x0e, struct.pack('<bb', 0x01, 0x00))
while True:
if peri.waitForNotifications(0.1):
pass
c = raw_input().encode('utf-8')
rx_char.write(c)