Skip to content

Commit 94157a4

Browse files
committed
Intro to device messaging changes
1 parent 0fc9247 commit 94157a4

File tree

5 files changed

+61
-26
lines changed

5 files changed

+61
-26
lines changed

devices/api/index.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,28 @@ import ProtocolBytes from '../../components/ProtocolBytes.vue';
88

99
# Device API
1010

11-
The device API is a messaging system for communicating with Lightbug devices. It allows you to:
11+
The device API is a messaging system for communicating with Lightbug devices. It allows you to send and receive [messages](/devices/api/messages/) to and from the device, enabling control and data exchange.
12+
13+
It makes use of the [Lightbug communication protocol](/devices/api/protocol/), which is a byte oriented protocol used for device communication.
14+
15+
This documentation focuses on the higher level element of this API first, including the [Toit SDK](/devices/api/sdks/toit/), before working its was down to the [message level](/devices/api/messages/), and finally the [protocol level](/devices/api/protocol/) which underpins it all.
16+
17+
You can [get started with Toit quickly](/devices/api/sdks/toit/), using an SDK built on top of the messages as another layer of abstraction.
18+
19+
## Capabilities
20+
21+
The Device API allows you to:
1222
- send commands to the device
1323
- ask for data (GET)
1424
- subscribe to data streams (SUBSCRIBE)
1525
- receive responses, instructions and other data from the device
1626

17-
It makes use of the Lightbug communication protocol, also known as the V3 protocol, which is a byte oriented protocol used for device communication.
18-
1927
On the wire, a single message might look like `4c 42 03 0b 00 01 00 00 00 00 00 4b be`, however, the API abstracts this away so you can work with high level messaging concepts.
2028

21-
And you can [get started with Toit quickly](/devices/api/sdks/toit/), using an SDK built on top of the messages as another layer of abstraction.
29+
## Accessability
2230

2331
Typically, it can be accessed via UART, I2C, or a UDP network connection.
2432

25-
2633
## Availability
2734

2835
Device API access depends on the device and may not be supported on all models.

devices/api/messages/5-ack.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ import PayloadTable from '../../../components/PayloadTable.vue'
1111
import HeaderTable from '../../../components/HeaderTable.vue'
1212
</script>
1313

14-
::: danger ⚠️ Not yet public
15-
The Device API currently in development and is not yet accessible on production devices.
16-
17-
These pages can be seen as a view of what is to come later this year.
18-
:::
19-
2014
# 5: ACK
2115

2216
<SplitColumnView>

devices/api/messages/index.md

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,58 @@ import ProtocolBytes from '../../../components/ProtocolBytes.vue'
55

66
# Messages
77

8-
Messages often make use of a few common [header fields](/devices/api/protocol/headers), and you can expect to see these in most messages types:
8+
Messages are the core building blocks of the protocol, allowing you to send and receive data and commands to and from devices.
99

10-
## Requests
10+
All messages follow a common structure, but each type of message has its own specific purpose, payload, requirements and usage.
1111

12-
Requests may or may not require a [MH 5: Method](../protocol/headers#_5-method) header field, such as `GET`, `DO`, `SET` or `SUBSCRIBE`.
12+
## Types
1313

14-
This is decided by the individual message type, and if required, should be included in the header.
14+
Messages all have a type, represented as a `uint16` value, which defines the structure and purpose of the message, including what headers and payload it may or should contain.
1515

16+
Some example message types for the device API include:
17+
- [13: Heartbeat](./13-heartbeat) - A simple message to indicate the communication link is alive
18+
- [34: Device Status](./34-device-status) - A message containing various status information about the device
19+
- [10011: Draw Element](./10011-draw-element) - A message to draw a shape on the device's display
20+
- ...
1621

22+
You can find complete documentation for the messages used as part of the device API in the sidebar of this page.
1723

18-
## Responses
24+
Values of `60,000` to `61,000` are currently reserved for custom use. Feel free to implement your own messages within this range.
1925

20-
You should receive a response to every valid and expected message when the recipient is able to process the request.
26+
## Header fields
2127

22-
When a message ID is provided in the request, any direct response should include the initiating message ID in the header [MH 3: Response Message ID](../protocol/headers#_3-response-message-id).
28+
Messages make use of a few common [header fields](/devices/api/protocol/headers) that are defined at the protocol level that you'll likely want to familiarize yourself with as they are used in device messaging.
2329

24-
Responses can come in the form of a basic [MT 5: ACK](./5-ack) or as the same message type as the request.
30+
Such as:
31+
- [1: Message ID](../protocol/headers#_1-message-id) for uniquely identifying messages
32+
- [3: Response to](../protocol/headers#_3-response-to) for linking responses to requests
33+
- [4: Status](../protocol/headers#_4-status) for indicating the status of a message
34+
- [5: Method](../protocol/headers#_5-method) for optionally specifying the action to be taken
2535

26-
Responses should contain a [MH 4: Response Status](../protocol/headers#_4-response-status) in the header, where 0 and below are various OK responses, and anything higher than 0 indicates a warning or error.
36+
You can find the full list of header fields in the [Headers documentation](/devices/api/protocol/headers) for the protocol.
2737

28-
## Types
38+
### Methods
39+
40+
A method is an optional header field that can be included in messages, and is sometimes used throughout the device API.
41+
42+
Currently defined methods are:
43+
- `1: SET` - Set a value or state on the device
44+
- `2: GET` - Get a value or state from the device
45+
- `3: SUBSCRIBE` - Subscribe to updates for a value or state on the device
46+
- `5: UNSUBSCRIBE` - Unsubscribe from updates for a value or state on the device
2947

30-
Per the specification, message types are represented by a single `uint16` value.
48+
You can find more information about these methods in the [MH 5: Method](../protocol/headers#_5-method) section.
3149

32-
Values of `60,000` to `61,000` are currently reserved for custom use.
50+
## Communication patterns
51+
52+
You should receive a response to every valid and expected message when the recipient is able to process the request.
53+
54+
When your message includes a [MH 1: Message ID](../protocol/headers#_1-message-id), the response should include the same message ID in the [MH 3: Response to](../protocol/headers#_3-response-to) header field.
55+
56+
:::warning
57+
If you do not include a message ID, you may not receive a response
58+
:::
59+
60+
Responses can come in the form of a basic [MT 5: ACK](./5-ack) or as the same message type as the request.
3361

34-
Feel free to implement your own messages within this range.
62+
Responses can contain a [MH 4: Response Status](../protocol/headers#_4-message-status) in the header, where 0 and below are various OK responses, and anything higher than 0 indicates a warning or error.

devices/api/protocol/headers.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import GenerateConsts from '../../../components/GenerateConsts.vue'
1010

1111
These header field types are reserved across all message types and usages of the protocol.
1212

13-
<GenerateConsts :dataName="'MH'" :dataPath="'header'"/>
13+
For use in code, you can find a code generation section at the [bottom of this page](#code-generation).
1414

1515
## 1: Message ID
1616

@@ -124,3 +124,7 @@ Reserved for future use.
124124
## 16: Message Level
125125

126126
Reserved for future use.
127+
128+
## Code generation
129+
130+
<GenerateConsts :dataName="'MH'" :dataPath="'header'"/>

devices/api/sdks/toit/getting-started.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ Once the code is running, you should see some output through the `monitor` comma
126126
💬 Sending text to device
127127
```
128128

129-
And you should see the device screen update, saying `Lightbug...` in the top right.
129+
And you should see the device screen update, saying `Lightbug...` in the top left.
130+
131+
![](https://i.imgur.com/8QP1022.png)
130132

131133
### 7. Inspect the code
132134

0 commit comments

Comments
 (0)