Skip to content

Commit b7d3d76

Browse files
committed
First draft for v0.3 text mode
1 parent 70decda commit b7d3d76

File tree

14 files changed

+1244
-65
lines changed

14 files changed

+1244
-65
lines changed

docs/.vuepress/config.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,44 @@ module.exports = {
2525
text: 'History',
2626
ariaLabel: 'History Menu',
2727
items: [
28-
{ text: 'v0.2 (current)', link: '/' },
28+
{ text: 'develop', link: '/' },
29+
{ text: 'v0.2', link: '/v0.2/' },
2930
{ text: 'v0.1', link: '/v0.1/' }
3031
]
3132
}
3233
],
3334
sidebar: {
34-
'/v0.1/': [
35-
'general',
36-
'functions',
37-
'can'
38-
],
3935
'/': [{
4036
title: 'Why ThingSet?',
4137
collapsable: false,
4238
children: [
4339
'',
4440
'1b_existing_solutions'
4541
]
42+
},{
43+
title: 'Application Layer',
44+
collapsable: false,
45+
children: [
46+
'2a_general',
47+
'2b_text_mode',
48+
'2c_binary_mode',
49+
]
50+
},{
51+
title: 'Lower Layers',
52+
collapsable: false,
53+
children: [
54+
'3a_serial',
55+
'3b_can',
56+
'3c_lora'
57+
]
58+
}],
59+
'/v0.2/': [{
60+
title: 'Why ThingSet?',
61+
collapsable: false,
62+
children: [
63+
'/v0.2/',
64+
'1b_existing_solutions'
65+
]
4666
},{
4767
title: 'Application Layer',
4868
collapsable: false,
@@ -58,7 +78,12 @@ module.exports = {
5878
'3b_can',
5979
'3c_lora'
6080
]
61-
}]
81+
}],
82+
'/v0.1/': [
83+
'general',
84+
'functions',
85+
'can'
86+
]
6287
},
6388
// if your docs are in a different repo from your main project:
6489
docsRepo: 'LibreSolar/thingset',

docs/2a_general.md

Lines changed: 123 additions & 54 deletions
Large diffs are not rendered by default.

docs/2b_text_mode.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Text Mode
2+
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).
4+
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.
6+
7+
### Requests
8+
9+
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).
10+
11+
request = get / fetch / patch / append / delete / exec
12+
13+
get = "?" path [ "/" ] ; CoAP equivalent: GET request
14+
15+
fetch = "?" path " " json-array ; CoAP equivalent: FETCH request
16+
17+
patch = "=" path " " json-object ; CoAP equivalent: iPATCH request
18+
19+
append = "+" path " " json-value ; CoAP equivalent: POST request
20+
21+
delete = "-" path " " json-value ; CoAP equivalent: DELETE request
22+
23+
exec = "!" path [ " " json-value ] ; CoAP equivalent: POST request
24+
25+
path = node-name [ "/" node-name ]
26+
27+
node-name = ALPHA / DIGIT / "_" / "-" / "." ; compatible to URIs (RFC 3986)
28+
29+
The path to access a specific node is a JSON pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)) without the forward slash at the beginning. The useable characters for node names are further restricted to allow un-escaped usage in URLs.
30+
31+
### Response
32+
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.
34+
35+
The bytes after the dot contain the requested data.
36+
37+
response = ":" status [ " " json-value ] ; response code and data
38+
39+
status = status-code [ " " status-msg ] "."
40+
41+
status-code = 2( hex )
42+
43+
status-msg = *( ALPHA / SP )
44+
45+
hex = DIGIT / %x41-46 ; upper-case HEXDIG
46+
47+
### Publication message
48+
49+
pub-msg = "# " json-map ; publication message
50+
51+
## Read data
52+
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.
54+
55+
The FETCH function allows to retrieve only subset of the child nodes, defined by an array with the node names passed to the function.
56+
57+
Only those data objects are returned which are at least readable. Thus, the result might differ after authentication.
58+
59+
**Example 1:** Discover all child nodes of the root node (i.e. categories)
60+
61+
?/
62+
:85 Content. ["info","conf","input","output","rec","exec","pub"]
63+
64+
**Example 2:** Retrieve all content of output path (keys + values)
65+
66+
?output
67+
:85 Content. {"Bat_V":14.2,"Bat_A":0.13,"Ambient_degC":22}
68+
69+
**Example 3:** List all sub-nodes of output path as an array
70+
71+
?output/
72+
:85 Content. ["Bat_V","Bat_A","Ambient_degC"]
73+
74+
**Example 4:** Retrieve single data node "Bat_V"
75+
76+
?output ["Bat_V"]
77+
:85 Content. {"Bat_V":14.2}
78+
79+
## Update data
80+
81+
Requests to overwrite the value of a data node.
82+
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.
84+
85+
**Example 1:** Disable charging
86+
87+
=input {"EnableCharging":false}
88+
:84 Changed.
89+
90+
**Example 2:** Attempt to write read-only measurement values (output category)
91+
92+
=output {"Bat_V":15.2,"Ambient_degC":22}
93+
:A3 Forbiden.
94+
95+
## Create data
96+
97+
Appends new data to a data node.
98+
99+
**Example 1:** Add "Bat_V" to the serial publication channel
100+
101+
+pub/serial/ids "Bat_V"
102+
:81 Created.
103+
104+
## Delete data
105+
106+
Removes data from a node of array type.
107+
108+
**Example 1:** Remove "Bat_V" from "serial" publication channel
109+
110+
-pub/serial/ids "Bat_V"
111+
:82 Deleted.
112+
113+
## Execute function
114+
115+
Executes a function identified by a data object name of category "exec"
116+
117+
**Example 1:** Reset the device
118+
119+
!exec/reset
120+
:83 Valid.
121+
122+
## Authentication
123+
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.
125+
126+
The password is transferred as a plain text string. Encryption has to be provided by lower layers.
127+
128+
Internally, the authentication function is implemented as a data node of exec type.
129+
130+
!exec/auth "mypass"
131+
:83 Valid.
132+
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.
134+
135+
## Publication messages
136+
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.
140+
141+
**Example 1:** List all available publication channels
142+
143+
?pub/
144+
:85 Content. ["serial","can"]
145+
146+
**Example 2:** Enable "serial" publication channel
147+
148+
?pub/serial {"Enable":true}
149+
:84 Changed.
150+
151+
With this setting, the following message is automatically sent by the device once per hour:
152+
153+
# {"Bat_V":14.1,"Bat_A":5.13}
154+
155+
Publication messages are broadcast to all connected devices. No response is sent from devices receiving the message.
156+
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.

0 commit comments

Comments
 (0)