Skip to content

Commit 6112e67

Browse files
committed
Review and update of binary mode for v0.3
1 parent b7d3d76 commit 6112e67

File tree

3 files changed

+244
-266
lines changed

3 files changed

+244
-266
lines changed

docs/2a_general.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ ThingSet defines three types of messages: Requests, responses and publication me
1414

1515
### Request/response or client/server model
1616

17-
The communication between two specific devices uses a request/response messaging pattern via so-called communication channels. A channel can be established either directly (e.g. serial interface, USB, Bluetooth) or via a network or bus with several devices attached (e.g. CAN, Ethernet, WiFi, LoRa). In case of a network, each device/node has to be uniquely addressable.
17+
The communication between two specific devices uses a request/response messaging pattern. A connection can be established either directly (e.g. serial interface, USB, Bluetooth) or via a network or bus with several devices attached (e.g. CAN, Ethernet, WiFi, LoRa). In case of a network, each device/node has to be uniquely addressable.
1818

1919
![Communication Channels](./images/communication_channels.png)
2020

21-
The device acts as the server and responds to the requests by a client. The client might be a laptop or mobile phone with a human interface application or a gateway.
21+
The device acts as the server and responds to the requests by a client. The client might be a display, a mobile phone application or a gateway.
2222

2323
The data transfer is always synchronous: The client sends a request, waits for the response (status code and requested data), processes the response and possibly starts with additional requests.
2424

2525
### Publication messages
2626

27-
Monitoring data is not intended for only a single device, but could be interesting for several devices (e.g. data logger, display, human interface device, etc.). Thus, the monitoring data is exchanged via a publish/subscribe messaging pattern.
27+
Monitoring data is not intended for only a single device, but could be interesting for several devices (e.g. data logger and display). Thus, the monitoring data can be exchanged via a publish/subscribe messaging pattern.
2828

2929
Publication messages are directly broadcast through the network. Unlike in MQTT, there is no intermediate broker to store the messages and published messages are not confirmed by recipients, so there is no guarantee if the message was received.
3030

@@ -34,17 +34,17 @@ Similar to Modbus, the ThingSet protocol supports two different modes: A human-r
3434

3535
In the text mode, payload data is encoded in JSON format ([RFC 8259](https://tools.ietf.org/html/rfc8259)). This mode is recommended when using serial communication interfaces as the low layer protocol, as it can be easily used directly on a terminal.
3636

37-
The binary mode uses the CBOR binary encoding ([RFC 7049](https://tools.ietf.org/html/rfc7049)) instead of JSON payload data in order to reduce the protocol overhead for ressource-constrained devices or low bandwith communication protocols like CAN and LoRa.
37+
The binary mode uses the CBOR ([RFC 7049](https://tools.ietf.org/html/rfc7049)) instead of JSON for payload data encoding in order to reduce the protocol overhead for ressource-constrained devices or low bandwith communication protocols like CAN and LoRa.
3838

3939
A device may implement both variants of the protocol, but it is also allowed to support only the mode most suitable for the application.
4040

4141
## Data Structure
4242

43-
All accessible data of a device is [structured as a tree](https://en.wikipedia.org/wiki/Tree_(data_structure)). Actual data is stored in leaf nodes, called data nodes. The data can be any kind of measurements (e.g. temperature), device configuration (e.g. setpoint of a controller) or similar. Internal nodes are used to structure the data and define paths for data access.
43+
All accessible data of a device is [structured as a tree](https://en.wikipedia.org/wiki/Tree_(data_structure)). Internal nodes are used to define paths or endpoints for data access. Actual data is stored in the leaf nodes and can be any kind of measurements (e.g. temperature), device configuration (e.g. setpoint of a controller) or similar information.
4444

45-
Each node is identified by a unique node ID and a name. The ID can be chosen by the firmware developer. The name of a data node must be unique per device. It is a short case-sensitive ASCII string containing only alphanumeric characters, an underscore, dots or dashes without any whitespace characters. The underscore is only used to specify the unit of the data (if applicable, also see below). No additional underscore is allowed in the name.
45+
Each node is identified by a unique node ID and a name. The ID can be chosen by the firmware developer. The name is a short case-sensitive ASCII string containing only alphanumeric characters, an underscore, dots or dashes without any whitespace characters. The underscore is only used to specify the unit of the data (if applicable, also see below). No additional underscore is allowed in the name and it should be unique per device at least for nodes that are used in publication messages.
4646

47-
The numeric IDs are used to define the relations between each nodes and to directly access data nodes in the binary protocol for reduced message size. For all interactions with users and in the text-based mode, only the node names and paths consisting of node names are used.
47+
The numeric IDs are used to define the relations between nodes and to directly access data nodes in the binary protocol for reduced message size. For all interactions with users and in the text-based mode, only the node names and paths (consisting of multiple node names) are used.
4848

4949
### Example
5050

@@ -71,8 +71,8 @@ For explanation of the protocol, the following simplified data structure of an M
7171
},
7272
"exec": {
7373
"reset": null,
74-
"auth": "password"
7574
},
75+
"auth": ["Password"],
7676
"pub": {
7777
"serial": {
7878
"Enable": true,
@@ -88,11 +88,11 @@ For explanation of the protocol, the following simplified data structure of an M
8888
}
8989
```
9090

91-
The data nodes are structured in 5 different categories info, conf, input, output and rec. By convention, data node names use [upper camel case](https://en.wikipedia.org/wiki/Camel_case), inner nodes nodes use lower case names.
91+
The data nodes are structured in the main different categories info, conf, input, output and rec. By convention, data node names use [upper camel case](https://en.wikipedia.org/wiki/Camel_case), inner nodes nodes use lower case names.
9292

93-
The exec category is special, as it contains functions that can be called. In order to distinguish it from a normal data node, executable node names are lower case.
93+
The exec category is special, as it provides functions that can be called. In order to distinguish functions from a normal data nodes, executable node names are lower case.
9494

95-
The pub node is used to configure different types of publication messages, so it doesn't hold actual data nodes.
95+
The pub node is used to configure different types of publication messages, so it doesn't hold normal data nodes.
9696

9797
### Categories
9898

@@ -101,20 +101,20 @@ The following categories for data nodes are used for the ThingSet protocol by de
101101
| Category | Description | Access |
102102
|----------|-------------|---------|
103103
| info | Device information (e.g. manufacturer, software version) | read access |
104-
| conf | Configurable settings, stored in non-volatile memory after change | read/write access, may be protected with user password |
104+
| conf | Configurable settings, stored in non-volatile memory after change | read/write access, expert settings may be password-protected |
105105
| input | Input nodes (e.g. actuators) | write access |
106106
| output | Output nodes (e.g. sensor data) | read access |
107-
| rec | Recorded (history-dependent) data (e.g. error counters) | read access, restricted write access to reset |
107+
| rec | Recorded (history-dependent) data (e.g. min/max values) | read access, restricted write access to reset |
108108
| cal | Factory-calibrated settings | read/write access, protected
109109
| exec | Executable functions | partly access restricted |
110110

111111
The nodes of input and output categories are used for instantaneous data. Changes to input nodes are only stored in RAM, so they get lost after a reset of the device. In contrast to that, conf data is stored in non-volatile memory (e.g. flash or EEPROM) after a change. As non-volatile memory has a limited amount of write cycles, configuration data should not be changed continously.
112112

113113
The recorded data category is used for history-dependent data like error memory, energy counters or min/max values of certain measurements. In contrast to data of output category, recorded data cannot be obtained through measurement after reset, so the current state has to be stored in non-volatile memory on a regular basis.
114114

115-
Factory calibration is only accessible for the manufacturer after authentication.
115+
Factory calibration data nodes are only accessible for the manufacturer after authentication.
116116

117-
Excecutable data means that they trigger a function call in the device firmware. Currently, only void functions without any parameters are supported.
117+
Excecutable data means that they trigger a function call in the device firmware. Child nodes of the executable node can be used to define parameters that can be passed to the function.
118118

119119
Data node IDs are stored as unsigned integers. The firmware developer should assign the lowest IDs to the most used data objects, as they consume less bytes during transfer (see CBOR representation of unsigned integers).
120120

@@ -139,7 +139,7 @@ The first byte of a ThingSet message is either a text-mode identifier ('?', '=',
139139

140140
### Requests
141141

142-
The protocol supports the typical [CRUD operations](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete). Request codes match with CoAP in order to allow transparent translation and routing between ThingSet and HTTP APIs or CoAP devices.
142+
The protocol supports the typical [CRUD operations](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete). Request codes match with CoAP to allow transparent translation and routing between ThingSet and HTTP APIs or CoAP devices.
143143

144144
| Code | Text ID | Method | Description |
145145
|------|---------|--------|---------------------------------------------|
@@ -149,6 +149,8 @@ The protocol supports the typical [CRUD operations](https://en.wikipedia.org/wik
149149
| 0x05 | ? | FETCH | Retrieve a subset of data from a node |
150150
| 0x07 | = | iPATCH | Update (overwrite) data of a node |
151151

152+
The CoAP PUT and PATCH methods are not explicitly implemented. PUT is equivalent to an update of all sub-nodes of a resource using a PATCH request. PATCH requests for ThingSet are always idempotent, so only the iPATCH request code is supported. The two different text IDs for POST requests are synonyms. It is decided based on the type of the node if the request is understood as a function call or a request to create a resource.
153+
152154
Additional request codes may be introduced in the future. Codes 0x0A, 0x0D and 0x20-0x7F are reserved, as they represent the ASCII characters for readable text including LF and CR.
153155

154156
### Responses

docs/2b_text_mode.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
# Text Mode
22

3-
The following description of the ThingSet text mode grammar uses ABNF according to [RFC 5234](https://tools.ietf.org/html/rfc5234) and [RFC 7405](https://tools.ietf.org/html/rfc7405).
3+
The following description of the ThingSet text mode grammar uses ABNF according to [RFC 5234](https://tools.ietf.org/html/rfc5234).
44

5-
For rule names prefixed with `json-` consider the JSON specification in [RFC 8259](https://tools.ietf.org/html/rfc8259). For the ThingSet protocol, JSON data must be in the most compact form, i.e. not contain any unnecessary whitespaces or line breaks.
5+
For rule names prefixed with `json-` consider the JSON specification in [RFC 8259](https://tools.ietf.org/html/rfc8259). In context of the ThingSet protocol, JSON data must be in the most compact form, i.e. not contain any unnecessary whitespaces or line breaks.
66

77
### Requests
88

99
Each request message consists of a first character as the request method identifier, a path specifying the endpoint of the request and a JSON string for the payload data (if applicable).
1010

11-
request = get / fetch / patch / append / delete / exec
11+
txt-request = txt-get / txt-fetch / txt-patch / txt-create / txt-delete / txt-exec
1212

13-
get = "?" path [ "/" ] ; CoAP equivalent: GET request
13+
txt-get = "?" path [ "/" ] ; CoAP equivalent: GET request
1414

15-
fetch = "?" path " " json-array ; CoAP equivalent: FETCH request
15+
txt-fetch = "?" path " " json-array ; CoAP equivalent: FETCH request
1616

17-
patch = "=" path " " json-object ; CoAP equivalent: iPATCH request
17+
txt-patch = "=" path " " json-object ; CoAP equivalent: iPATCH request
1818

19-
append = "+" path " " json-value ; CoAP equivalent: POST request
19+
txt-create = "+" path " " json-value ; CoAP equivalent: POST request
2020

21-
delete = "-" path " " json-value ; CoAP equivalent: DELETE request
21+
txt-delete = "-" path " " json-value ; CoAP equivalent: DELETE request
2222

23-
exec = "!" path [ " " json-value ] ; CoAP equivalent: POST request
23+
txt-exec = "!" path [ " " json-value ] ; CoAP equivalent: POST request
2424

2525
path = node-name [ "/" node-name ]
2626

@@ -30,31 +30,33 @@ The path to access a specific node is a JSON pointer ([RFC 6901](https://tools.i
3030

3131
### Response
3232

33-
The response starts with a colon ':' followed by the the status code and a plain text description of the status finished with a '.'. The description message content is not strictly specified and can be either the description from the table in the [General Concept chapter](2a_general.md) or a more verbose message. However, it must contain only one dot at the end of the description, signifying the end of the description.
33+
The response starts with a colon ':' followed by the the status code and a plain text description of the status finished with a '.'. The description is not strictly specified and can be according to the table in the [General Concept chapter](2a_general.md) or a more verbose message. However, it must contain only one dot at the end of the description, signifying the end of the description.
3434

3535
The bytes after the dot contain the requested data.
3636

37-
response = ":" status [ " " json-value ] ; response code and data
37+
txt-response = ":" status [ " " json-value ] ; response code and data
3838

3939
status = status-code [ " " status-msg ] "."
4040

4141
status-code = 2( hex )
4242

4343
status-msg = *( ALPHA / SP )
4444

45-
hex = DIGIT / %x41-46 ; upper-case HEXDIG
45+
hex = DIGIT / %x41-46 ; upper-case HEXDIG
4646

4747
### Publication message
4848

49-
pub-msg = "# " json-map ; publication message
49+
The publication message is very simple and consists of a hash sign and a whitespace at the beginning, followed by a map of data node name/value pairs.
50+
51+
txt-pubmsg = "# " json-map ; publication message
5052

5153
## Read data
5254

53-
The GET function allows to read all child nodes of the specified path. If a forward slash is appended at the end of the path, only an array with the node names of the next level is returned. Otherwise all content below that path (names and values) is returned.
55+
The GET function allows to read all child nodes of the specified path. If a forward slash is appended at the end of the path, only an array with the child node names is returned. Otherwise all content below that path (names and values) is returned.
5456

5557
The FETCH function allows to retrieve only subset of the child nodes, defined by an array with the node names passed to the function.
5658

57-
Only those data objects are returned which are at least readable. Thus, the result might differ after authentication.
59+
Only those data nodes are returned which are at least readable. Thus, the result might differ after authentication.
5860

5961
**Example 1:** Discover all child nodes of the root node (i.e. categories)
6062

@@ -64,7 +66,7 @@ Only those data objects are returned which are at least readable. Thus, the resu
6466
**Example 2:** Retrieve all content of output path (keys + values)
6567

6668
?output
67-
:85 Content. {"Bat_V":14.2,"Bat_A":0.13,"Ambient_degC":22}
69+
:85 Content. {"Bat_V":14.2,"Bat_A":5.13,"Ambient_degC":22}
6870

6971
**Example 3:** List all sub-nodes of output path as an array
7072

@@ -80,7 +82,7 @@ Only those data objects are returned which are at least readable. Thus, the resu
8082

8183
Requests to overwrite the value of a data node.
8284

83-
Data of category *conf* will be written into persistent memory, so it is not allowed to change settings periodically. Only data of category *input* can be changed regularly.
85+
Data of category conf will be written into persistent memory, so it is not allowed to change settings periodically. Only data of category input can be changed regularly.
8486

8587
**Example 1:** Disable charging
8688

@@ -121,22 +123,20 @@ Executes a function identified by a data object name of category "exec"
121123

122124
## Authentication
123125

124-
Some of the device parameters like calibration or config settings should be protected against unauthorized change. The protocol provides a simple authentication method. Multiple user levels can be implemented in the firmware using different passwords. The manufacturer would use a different one to authenticate than a normal user and thus get more rights to access data objects.
126+
Some of the device parameters like calibration or config settings should be protected against unauthorized change. A simple authentication method is suggested where multiple user levels can be implemented in the firmware using different passwords. The manufacturer would use a different one to authenticate than a normal user and thus get more rights to access data objects.
125127

126128
The password is transferred as a plain text string. Encryption has to be provided by lower layers.
127129

128130
Internally, the authentication function is implemented as a data node of exec type.
129131

130-
!exec/auth "mypass"
132+
!auth "mypass"
131133
:83 Valid.
132134

133-
After successful authentication, the device exposes restricted data objects via the normal data object access commands. The authentication stays valid until another auth command is received, either without password or with a password that doesn't match.
135+
After successful authentication, the device exposes restricted data nodes via the normal data access requests. The authentication stays valid until another auth command is received, either without password or with a password that doesn't match.
134136

135137
## Publication messages
136138

137-
A publication request configures the device to publish certain data on a regular basis through a defined communication channel (UART, CAN, LoRa, etc.). If implemented in the firmware, the publication interval may be adjustable.
138-
139-
The publication subsystem is configured via the pub endpoint.
139+
The pub node is used to configure the device to publish certain data on a regular basis through a defined communication channel (UART, CAN, LoRa, etc.). If implemented in the firmware, the publication interval may be adjustable.
140140

141141
**Example 1:** List all available publication channels
142142

@@ -148,10 +148,10 @@ The publication subsystem is configured via the pub endpoint.
148148
?pub/serial {"Enable":true}
149149
:84 Changed.
150150

151-
With this setting, the following message is automatically sent by the device once per hour:
151+
With this setting, the following message is automatically sent by the device once per second:
152152

153153
# {"Bat_V":14.1,"Bat_A":5.13}
154154

155155
Publication messages are broadcast to all connected devices. No response is sent from devices receiving the message.
156156

157-
The data nodes to be published in each message can be configured using POST and DELETE requests to the pub/serial/IDs channel, as shown in the examples above.
157+
The data nodes to be published in each message can be configured using POST and DELETE requests to the pub/serial/IDs endpoint, as shown in the examples above.

0 commit comments

Comments
 (0)