adafruit_bluefruit_connect

This module helps you to communicate with the Adafruit Bluefruit Connect App or use its protocols with boards that run Adafruit CircuitPython firmware.

  • Author(s): Dan Halbert for Adafruit Industries

adafruit_bluefruit_connect.packet

Bluefruit Connect App packet superclass

  • Author(s): Dan Halbert for Adafruit Industries

class adafruit_bluefruit_connect.packet.Packet

A Bluefruit app controller packet. A packet consists of these bytes, in order:

  • ‘!’ - The first byte is always an exclamation point.

  • type - A single byte designating the type of packet: b’A’, b’B’, etc.

  • data … - Multiple bytes of data, varying by packet type.

  • checksum - A single byte checksum, computed by adding up all the data bytes and inverting the sum.

This is an abstract class.

add_checksum(partial_packet: bytes) bytes

Compute the checksum of partial_packet and return a new bytes with the checksum appended.

static checksum(partial_packet: bytes) int

Compute checksum for bytes, not including the checksum byte itself.

classmethod from_bytes(packet: bytes) Packet

Create an appropriate object of the correct class for the given packet bytes. Validate packet type, length, and checksum.

classmethod from_stream(stream: RawIOBase) Packet | None

Read the next packet from the incoming stream. Wait as long as the timeout set on stream, using its own preset timeout. Return None if there was no input, otherwise return an instance of one of the packet classes registered with Packet. Raise an Error if the packet was not recognized or was malformed.

If a packet of type “RT” (like RawTextPacket) is registered, it will be used to return the raw data line when no packet type was recognized.

Parameters:

stream (stream) – an input stream that provides standard stream read operations, such as ble.UARTServer or busio.UART.

classmethod parse_private(packet: bytes) Packet | None

Default implementation for subclasses. Assumes arguments to __init__() are exactly the values parsed using cls._FMT_PARSE. Subclasses may need to reimplement if that assumption is not correct.

Do not call this directly. It’s called from cls.from_bytes(). pylint makes it difficult to call this method _parse(), hence the name.

classmethod register_packet_type() None

Register a new packet type, using this class and its cls._TYPE_HEADER. The from_bytes() and from_stream() methods will then be able to recognize this type of packet.

adafruit_bluefruit_connect.accelerometer_packet

Bluefruit Connect App Accelerometer data packet.

  • Author(s): Dan Halbert for Adafruit Industries

class adafruit_bluefruit_connect.accelerometer_packet.AccelerometerPacket(x: float, y: float, z: float)

A packet of x, y, z float values from an accelerometer.

adafruit_bluefruit_connect.button_packet

Bluefruit Connect App Button data packet (button_name, pressed/released)

  • Author(s): Dan Halbert for Adafruit Industries

class adafruit_bluefruit_connect.button_packet.ButtonPacket(button: str, pressed: bool)

A packet containing a button name and its state.

Construct a ButtonPacket from a button name and the button’s state.

Parameters:
  • button (str) – a single character denoting the button

  • pressed (bool) – True if button is pressed; False if it is released.

BUTTON_1: str = '1'

Code for Button 1 on the Bluefruit LE Connect app Control Pad screen.

BUTTON_2: str = '2'

Button 2.

BUTTON_3: str = '3'

Button 3.

BUTTON_4: str = '4'

Button 4.

DOWN: str = '6'

Down Button.

LEFT: str = '7'

Left Button.

RIGHT: str = '8'

Right Button.

UP: str = '5'

Up Button.

property button: str

A single character string (not bytes) specifying the button that the user pressed or released.

classmethod parse_private(packet: bytes) Packet | None

Construct a ButtonPacket from an incoming packet. Do not call this directly; call Packet.from_bytes() instead. pylint makes it difficult to call this method _parse(), hence the name.

property pressed: bool

True if button is pressed, or False if it is released.

to_bytes() bytes

Return the bytes needed to send this packet.

adafruit_bluefruit_connect.color_packet

Bluefruit Connect App color data packet.

  • Author(s): Dan Halbert for Adafruit Industries

class adafruit_bluefruit_connect.color_packet.ColorPacket(color: Tuple)

A packet containing an RGB color value.

Construct a ColorPacket from a 3-element tuple of RGB values, or from an int color value 0xRRGGBB.

Parameters:

color (tuple/int) – an RGB tuple (red, green, blue) or an int color value 0xRRGGBB

property color: tuple

A tuple (red, green blue) representing the color the user chose in the BlueFruit Connect app.

classmethod parse_private(packet: bytes) Packet | None

Construct a ColorPacket from an incoming packet. Do not call this directly; call Packet.from_bytes() instead. pylint makes it difficult to call this method _parse(), hence the name.

to_bytes() bytes

Return the bytes needed to send this packet.

adafruit_bluefruit_connect.gyro_packet

Bluefruit Connect App Gyro data packet.

  • Author(s): Dan Halbert for Adafruit Industries

class adafruit_bluefruit_connect.gyro_packet.GyroPacket(x: float, y: float, z: float)

A packet of x, y, z float values from a gyroscope.

adafruit_bluefruit_connect.location_packet

Bluefruit Connect App geographical location packet.

  • Author(s): Dan Halbert for Adafruit Industries

class adafruit_bluefruit_connect.location_packet.LocationPacket(latitude: float, longitude: float, altitude: float)

A packet of latitude, longitude, and altitude values.

Construct a LocationPacket from the given values.

property altitude: float

The altitude value.

property latitude: float

The latitude value.

property longitude: float

The longitude value.

to_bytes() bytes

Return the bytes needed to send this packet.

adafruit_bluefruit_connect.magnetometer_packet

Bluefruit Connect App Magnetometer data packet.

  • Author(s): Dan Halbert for Adafruit Industries

class adafruit_bluefruit_connect.magnetometer_packet.MagnetometerPacket(x: float, y: float, z: float)

A packet of x, y, z float values from a magnetometer.

adafruit_bluefruit_connect.quaternion_packet

Bluefruit Connect App Quaternion data packet.

  • Author(s): Dan Halbert for Adafruit Industries

class adafruit_bluefruit_connect.quaternion_packet.QuaternionPacket(x: float, y: float, z: float, w: float)

Device Motion data to describe device attitude. This data is derived from Accelerometer, Gyro, and Magnetometer readings.

Construct a QuaternionPacket from the given x, y, z, and w float values.

to_bytes() bytes

Return the bytes needed to send this packet.

property w: float

The w value.

adafruit_bluefruit_connect.raw_text_packet

Bluefruit Connect App raw text data packet.

Note that the raw text data packet is different from those used by the Controller module (e.g. Accelerometer, Control Pad, and Color Picker). Those use the bytes “!x” (where x is specific to the type of packet), followed by data specific to the packet, followed by a checksum. The UART text sender instead sends the bytes followed by a newline. There is no length indicator, no checksum, etc. Of course, that also precludes the use of an “!” at the beginning of the string.

Consequently, this packet type is MUCH simpler than the other packet types.

  • Author(s): Tony Hansen

class adafruit_bluefruit_connect.raw_text_packet.RawTextPacket(text: str)

A packet containing a text string.

Construct a RawTextPacket from a binary string.

property text: str

Return the text associated with the object.