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
Copy file name to clipboardExpand all lines: devices/api/index.md
+12-5Lines changed: 12 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,21 +8,28 @@ import ProtocolBytes from '../../components/ProtocolBytes.vue';
8
8
9
9
# Device API
10
10
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:
12
22
- send commands to the device
13
23
- ask for data (GET)
14
24
- subscribe to data streams (SUBSCRIBE)
15
25
- receive responses, instructions and other data from the device
16
26
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
-
19
27
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.
20
28
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
22
30
23
31
Typically, it can be accessed via UART, I2C, or a UDP network connection.
24
32
25
-
26
33
## Availability
27
34
28
35
Device API access depends on the device and may not be supported on all models.
Copy file name to clipboardExpand all lines: devices/api/messages/index.md
+41-13Lines changed: 41 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,30 +5,58 @@ import ProtocolBytes from '../../../components/ProtocolBytes.vue'
5
5
6
6
# Messages
7
7
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.
9
9
10
-
## Requests
10
+
All messages follow a common structure, but each type of message has its own specific purpose, payload, requirements and usage.
11
11
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
13
13
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.
15
15
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
+
- ...
16
21
22
+
You can find complete documentation for the messages used as part of the device API in the sidebar of this page.
17
23
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.
19
25
20
-
You should receive a response to every valid and expected message when the recipient is able to process the request.
26
+
## Header fields
21
27
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.
23
29
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
25
35
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.
27
37
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
29
47
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.
31
49
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.
33
61
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.
0 commit comments