bricknil.ble_queue

Singleton interface to the Adafruit Bluetooth library

Classes

BLEventQ(ble) All bluetooth comms go through this object

Members

class bricknil.ble_queue.BLEventQ(ble)[source]

Bases: bricknil.process.Process

All bluetooth comms go through this object

Provides interfaces to connect to a device/hub, send_messages to, and receive_messages from. Also abstracts away the underlying bluetooth library that depends on the OS (Adafruit_Bluefruit for Mac, and Bleak for Linux/Win10)

All requests to send messages to the BLE device must be inserted into the bricknil.BLEventQ.q Queue object.

connect(hub)[source]

We probably need a different ble_queue type per operating system, and try to abstract away some of these hacks.

Todo

  • This needs to be cleaned up to get rid of all the hacks for different OS and libraries
get_messages(hub)[source]

Instance a Message object to parse incoming messages and setup the callback from the characteristic to call Message.parse on the incoming data bytes

run()[source]
send_message(characteristic, msg)[source]

Prepends a byte with the length of the msg and writes it to the characteristic

Parameters:
  • characteristic – An object from bluefruit, or if using Bleak, a tuple (device, uuid : str)
  • msg (bytearray) – Message with header