You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"""Minimum working example adapted from https://github.com/adafruit/Adafruit_CircuitPython_BLE/blob/main/examples/ble_hid_periph.py"""# import boardimportsysimporttimeimportmicrocontrollerfromadafruit_hid.keyboardimportKeyboardfromadafruit_hid.keyboard_layout_usimportKeyboardLayoutUSimportadafruit_bleimport_bleiofromadafruit_ble.advertisingimportAdvertisementfromadafruit_ble.advertising.standardimportProvideServicesAdvertisementfromadafruit_ble.services.standard.hidimportHIDServicefromadafruit_ble.services.standard.device_infoimportDeviceInfoService# Use default HID descriptorhid=HIDService()
device_info=DeviceInfoService(
software_revision=adafruit_ble.__version__, manufacturer="Adafruit Industries"
)
advertisement=ProvideServicesAdvertisement(hid)
advertisement.appearance=961# scan_response = Advertisement() # not used# ble handleble=adafruit_ble.BLERadio()
# prepare mac address poolcpu_id=list(microcontroller.cpu.uid)
cpu_id_reverse=list(microcontroller.cpu.uid)
cpu_id_reverse.reverse()
mac_pool=bytearray(cpu_id+cpu_id_reverse)
# set bt id# that's to say:# 1. stop advertising and drop all existing connections# 2. change full_name, MAC address# 3. start advertisingdefset_bt_id(bt_id):
ble.stop_advertising()
ifble.connected:
forcinble.connections:
c.disconnect()
# change namename='PYKB %d'%bt_idadvertisement.full_name=nameble.name=name# change macuid=mac_pool[bt_id : bt_id+6]
uid[-1] =uid[-1] |0xC0address=_bleio.Address(uid, _bleio.Address.RANDOM_STATIC)
ble._adapter.address=address# logprint(ble._adapter.address)
print(ble.name)
# start advertisingprint("advertising")
ble.start_advertising(advertisement, timeout=60) # 60 secs# set bt id and start the main loopset_bt_id(0)
k=Keyboard(hid.devices)
kl=KeyboardLayoutUS(k)
whileTrue:
whilenotble.connected:
passprint("Start typing:")
whileble.connected:
c=sys.stdin.read(1)
# change to PYKB #n by entering corresponding numberif'0'<=c<='9':
set_bt_id(int(c))
continuesys.stdout.write(c)
kl.write(c)
# print("sleeping")time.sleep(0.1)
ifnotble.advertising:
print('restart advertising')
ble.start_advertising(advertisement)
Behavior
I'm using a custom bluetooth keyboard based on CircuitPython which can switch to different hosts by changing its bluetooth MAC and full name. The code above is provided as a minimum working example. You can switch to different MAC and full name by entering 0-9 in the REPL. There should be no error.
Recently I encounter the issue that if I use the keyboard on two different Linux setups, after pairing to the second host, the pairing key for the first linux host is replaced/invalidated(my presumption), and the first host won't be able to connect to my keyboard without another manual pairing(connected and then immediately disconnected, see btmon.log). I have to adapt some tricks for dual boot pairing to share keys between two different Linux hosts to work it around.
There may be some bugs in either CircuitPython or Linux's bluetooth implementation(I think it's the latter).
Description
Only occurs between my Linux based hosts
on iPad, Windows, Android device work as expected
tested with 2 Arch Linux hosts, my laptop and my mini PC
CircuitPython version
Code/REPL
Behavior
I'm using a custom bluetooth keyboard based on CircuitPython which can switch to different hosts by changing its bluetooth MAC and full name. The code above is provided as a minimum working example. You can switch to different MAC and full name by entering 0-9 in the REPL. There should be no error.
Recently I encounter the issue that if I use the keyboard on two different Linux setups, after pairing to the second host, the pairing key for the first linux host is replaced/invalidated(my presumption), and the first host won't be able to connect to my keyboard without another manual pairing(connected and then immediately disconnected, see btmon.log). I have to adapt some tricks for dual boot pairing to share keys between two different Linux hosts to work it around.
There may be some bugs in either CircuitPython or Linux's bluetooth implementation(I think it's the latter).
Description
Additional information
btmon.log
The text was updated successfully, but these errors were encountered: