Data Packet for Classic Bluetooth
When a gadget and an Echo device exchange data over a Classic Bluetooth connection, they use Serial Port Profile (SPP). This topic describes the packet format for this case.
Packet format
Because packets can break up into multiple parts during transmission, the Alexa Gadgets interfaces use the following rules to denote packet boundaries:
- Each packet must begin with a start of frame (SOF) =
0xF0
. - Each packet must end with an end of frame (EOF) =
0xF1
. - To escape characters in the payload, use ESC =
0xF2
.
A packet is as follows:

The components of the packet are:
Description | Number of Bytes | Value |
---|---|---|
Start of frame (SOF) |
1 |
Always |
Packet ID |
1 |
Always |
Error ID |
1 |
Always |
Sequence ID |
1 |
Rotating sequence that increments every time a packet is sent. Special characters (SOF, EOF, and ESC) are skipped. |
Payload |
Varies |
The complete directive or event in protocol buffer format as described in Protocol Buffer Format for Alexa Gadgets. |
Checksum |
2 |
A big-endian checksum that is calculated using the following formula: |
End of frame (EOF) |
1 |
Always |
Cases that your gadget must handle
In a Classic Bluetooth RFCOMM connection, the gadget receives data from the Echo device in a stream buffer, not necessarily packet by packet. The gadget's RFCOMM server attempts to fill the stream buffer with every byte it receives, and periodically flushes the buffer and returns the data to the application layer (and thus your packet-processing code) using a callback.
You therefore need to make sure that your gadget's packet-processing code operates on the packets extracted from the stream buffer, not the stream buffer itself. As such, your gadget must be able to handle cases where it receives:
- One packet
- Multiple packets
- A fraction of a packet
For an example of how to extract packets from a stream buffer, see the Alexa Gadgets Sample Code GitHub repository.
Last updated: Feb 14, 2022