@@ -4,20 +4,22 @@ Light-weight Shell for ESP8266 with support of simple and configurable control l
4
4
Developed and tested with my ESP-12E (4Mb) board.
5
5
6
6
Main Goals:
7
+ - OTA firmware update
7
8
- light-weight udp control/management protocol with python client [ esp8266-tshcli]
8
9
- cron-like task scheduler
9
10
- simple scripting language for making control logic with trace/debug feature
10
11
- almost fixed heap memory consumption
11
12
12
13
License: GPLv3
13
14
14
- * Some of internal solutions may looks weird, but all of it made just for fun and it works well.*
15
-
16
15
* Feel free to use, improve, report bugs, criticize and etc.*
17
16
18
17
Contributors
19
18
- Denis Muratov < xeronm@gmail.com >
20
19
20
+
21
+ [ ![ Paypal Donations] ( https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif )] ( https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=xeronm%40gmail.com¤cy_code=USD&source=url )
22
+
21
23
## 1. References
22
24
23
25
- [ esp-open-sdk] : Free and open (as much as possible) integrated SDK for ESP8266/ESP8285 chips
@@ -60,26 +62,36 @@ $ sudo docker run --name esp8266 -it --rm -v $PWD:/src/project dtec/esp8266:1.22
60
62
61
63
## 4. Usage
62
64
63
- ### 4.1. Service catalog
65
+ ### 4.1. System Documentation
66
+
67
+ #### 4.1.1. Safe Mode
68
+
69
+ If exception occurs, on system initialization will checked ` reason ` and ` exccause ` and will turn system in Safe Mode to 60 seconds.
70
+ Only few services need for logging and control operations starts immediately. All other services starts after 60 seconds timeout.
71
+ Unconfirmed firmware updates will be rolled back to the previous version of firmware.
72
+
73
+
74
+ ### 4.2. Service catalog
75
+
76
+ | Id | Name | Description | Safe Mode* |
77
+ | ---| ----------| -----------------------------| -----------|
78
+ | 0 | multicast | multicast messaging point | |
79
+ | 1 | service | service management | Yes |
80
+ | 2 | syslog | system message logging | Yes |
81
+ | 3 | espadmin | esp8266 system management | Yes (no configuration) |
82
+ | 4 | udpctl | UDP system management | Yes |
83
+ | 5 | lwsh | Light-weight shell | |
84
+ | 6 | ntp | Network Time Protocol client | |
85
+ | 7 | gpioctl | GPIO control management | |
86
+ | 8 | sched | Cron-like scheduler | |
87
+ | 21 | dev.dht | DHT11/AM2302 sensor | |
64
88
65
- | Id | Name | Description |
66
- | ---| ----------| -----------------------------|
67
- | 0 | multicast | multicast messaging point |
68
- | 1 | service | service management |
69
- | 2 | syslog | system message logging |
70
- | 3 | espadmin | esp8266 system management |
71
- | 4 | udpctl | UDP system management |
72
- | 5 | lwsh | Light-weight shell |
73
- | 6 | ntp | Network Time Protocol client |
74
- | 7 | gpioctl | GPIO control management |
75
- | 8 | sched | Cron-like scheduler |
76
- | 21 | dev.dht | DHT11/AM2302 sensor |
77
89
78
- ### 4.2 . Service documentation
90
+ ### 4.3 . Service documentation
79
91
80
- #### 4.2 .1. Service management (service)
92
+ #### 4.3 .1. Service management (service)
81
93
82
- ##### 4.2 .1.1. Message types
94
+ ##### 4.3 .1.1. Message types
83
95
84
96
| MsgType| Command| Multicast| Description|
85
97
| -------| -------| ---------| -----------|
@@ -99,9 +111,9 @@ $ sudo docker run --name esp8266 -it --rm -v $PWD:/src/project dtec/esp8266:1.22
99
111
| 40| MCAST_SIG4| Y| User signal |
100
112
101
113
102
- #### 4.2 .2. System logging (syslog)
114
+ #### 4.3 .2. System logging (syslog)
103
115
104
- ##### 4.2 .2.2. Configuration parameters
116
+ ##### 4.3 .2.2. Configuration parameters
105
117
106
118
| Parameter| Level| Description| Default|
107
119
| ---------| -----| -----------| -------|
@@ -112,9 +124,9 @@ Example:
112
124
{ "syslog.Log-Severity": 4 }
113
125
```
114
126
115
- #### 4.2 .3. esp8266 system management (espadmin)
127
+ #### 4.3 .3. esp8266 system management (espadmin)
116
128
117
- ##### 4.2 .3.1. Configuration parameters
129
+ ##### 4.3 .3.1. Configuration parameters
118
130
119
131
| Parameter| Level| Description| Default|
120
132
| ---------| -----| -----------| -------|
@@ -154,7 +166,7 @@ Example:
154
166
}
155
167
```
156
168
157
- ##### 4.2 .3.2. Message types
169
+ ##### 4.3 .3.2. Message types
158
170
159
171
| MsgType| Command| Description|
160
172
| -------| -------| -----------|
@@ -163,13 +175,14 @@ Example:
163
175
| 11| FDB_TRUNC| truncate Flash-DB|
164
176
| 12| FW_OTA_INIT| Initialize OTA firmware upgrade|
165
177
| 13| FW_OTA_UPLOAD| Upload firmware bin data |
166
- | 14| FW_OTA_DONE| Commit firmware upgrade|
178
+ | 14| FW_OTA_DONE| Commit firmware upgrade, will reboot with new firmware |
167
179
| 15| FW_OTA_ABORT| Abort firmware upgrade|
168
- | 16| FW_VERIFY| Verify firmware digest|
180
+ | 16| FW_OTA_VERIFY_DONE| Final commit firmware upgrade, if not successed by 60 sec after restart, will rollback to previous firmware |
181
+ | 17| FW_VERIFY| Verify firmware digest|
169
182
170
- #### 4.2 .4. UDP system management (udpctl)
183
+ #### 4.3 .4. UDP system management (udpctl)
171
184
172
- ##### 4.2 .4.1. Configuration parameters
185
+ ##### 4.3 .4.1. Configuration parameters
173
186
174
187
| Parameter| Level| Description| Default|
175
188
| ---------| -----| -----------| -------|
@@ -186,13 +199,13 @@ Example:
186
199
}
187
200
```
188
201
189
- ##### 4.2 .4.2. Message types
202
+ ##### 4.3 .4.2. Message types
190
203
191
204
| MsgType| Command| Description|
192
205
| -------| -------| -----------|
193
206
| 1| INFO| Query information (state, peers, etc.) |
194
207
195
- ##### 4.2 .4.3. Protocol
208
+ ##### 4.3 .4.3. Protocol
196
209
197
210
###### Message Flow
198
211
0 . Auth Request
@@ -249,7 +262,7 @@ Example:
249
262
- E flag - error answer
250
263
- ** Command Code** - corresponds to service Message type
251
264
- ** Identifier** - message sequence identifier (starts from 0 for every new authenticated connection)
252
- - ** Message Digest** - message digest for validate message originator
265
+ - ** Message Digest** - message digest for message originator and body validation
253
266
- ** Authenticator** - party authenticator issued by originator of auth request/answer message
254
267
255
268
###### Message Body
@@ -272,13 +285,13 @@ Message body is a sequence of AVP
272
285
- ** Data** - attribute value data (4-bytes aligned)
273
286
274
287
275
- #### 4.2 .5. Light-weight shell (lwsh)
288
+ #### 4.3 .5. Light-weight shell (lwsh)
276
289
277
- ##### 4.2 .5.1. Configuration parameters
290
+ ##### 4.3 .5.1. Configuration parameters
278
291
279
292
This service hasn't any configurable parameters
280
293
281
- ##### 4.2 .5.2. Message types
294
+ ##### 4.3 .5.2. Message types
282
295
283
296
| MsgType| Command| Description|
284
297
| -------| -------| -----------|
@@ -291,9 +304,9 @@ This service hasn't any configurable parameters
291
304
| 15| LOAD| Load existing script from source (Flash-DB)|
292
305
| 16| LIST| List all stored scripts from Flash-DB|
293
306
294
- #### 4.2 .6. Network Time Protocol client (ntp)
307
+ #### 4.3 .6. Network Time Protocol client (ntp)
295
308
296
- ##### 4.2 .6.1. Configuration parameters
309
+ ##### 4.3 .6.1. Configuration parameters
297
310
298
311
| Parameter| Level| Description| Default|
299
312
| ---------| -----| -----------| -------|
@@ -314,33 +327,33 @@ Example:
314
327
}
315
328
```
316
329
317
- ##### 4.2 .6.2. Message types
330
+ ##### 4.3 .6.2. Message types
318
331
319
332
| MsgType| Command| Description|
320
333
| -------| -------| -----------|
321
334
| 1| INFO| Query information (state, peers, etc.) |
322
335
| 10| SETDATE| Query NTP peers and try to set local datetime|
323
336
324
- #### 4.2 .7. GPIO control management (gpioctl)
337
+ #### 4.3 .7. GPIO control management (gpioctl)
325
338
326
- ##### 4.2 .7.1. Configuration parameters
339
+ ##### 4.3 .7.1. Configuration parameters
327
340
328
341
This service hasn't any configurable parameters
329
342
330
- ##### 4.2 .7.2. Message types
343
+ ##### 4.3 .7.2. Message types
331
344
332
345
| MsgType| Command| Description|
333
346
| -------| -------| -----------|
334
347
| 1| INFO| Query GPIO perepherial information |
335
348
| 10| OUTPUT_SET| Set output parameters for GPIO PIN (value, delay, function)|
336
349
337
- #### 4.2 .8. Cron-like scheduler (sched)
350
+ #### 4.3 .8. Cron-like scheduler (sched)
338
351
339
- ##### 4.2 .8.1. Configuration parameters
352
+ ##### 4.3 .8.1. Configuration parameters
340
353
341
354
This service hasn't any configurable parameters
342
355
343
- ##### 4.2 .8.2. Message types
356
+ ##### 4.3 .8.2. Message types
344
357
345
358
| MsgType| Command| Description|
346
359
| -------| -------| -----------|
@@ -351,9 +364,9 @@ This service hasn't any configurable parameters
351
364
| 13| SOURCE| Get source of existing task from Flash-DB|
352
365
| 14| LIST| List all stored tasks from Flash-DB|
353
366
354
- #### 4.2 .9. DHT11/AM2302 sensor (dev.dht)
367
+ #### 4.3 .9. DHT11/AM2302 sensor (dev.dht)
355
368
356
- ##### 4.2 .9.1. Configuration parameters
369
+ ##### 4.3 .9.1. Configuration parameters
357
370
358
371
| Parameter| Level| Description| Default|
359
372
| ---------| -----| -----------| -------|
@@ -371,7 +384,7 @@ This service hasn't any configurable parameters
371
384
| dht.Temperature| 1 | Temperature Celseus (1/100) | |
372
385
| common.Milticast-Signal| 1 | Notification multicast signal_id (32-63)|
373
386
374
- ##### 4.2 .9.2. Message types
387
+ ##### 4.3 .9.2. Message types
375
388
376
389
| MsgType| Command| Description|
377
390
| -------| -------| -----------|
@@ -533,7 +546,7 @@ Following terms were used:
533
546
# temp = 0; # hmd = 0; # res := ! dht_get(1, hmd, temp);
534
547
((last_ev != 2) && res && (hmd >= 3600) && (last_dt + 300 < sdt)) ?? { gpio_set(0, 0); last_ev := 2; last_dt := sdt; print(last_ev) }; // humidity high threshold
535
548
((last_ev = 2) && res && (hmd < 3600) && (last_dt + 300 < sdt)) ?? { gpio_set(0, 1); last_ev := 3; last_dt := sdt; print(last_ev) }; // humidity low threshold
536
- ((last_ev = 1) && (last_dt + 720 < sdt) || (last_ev = 2) && (last_dt + 1800 < sdt)) ?? { gpio_set(0, 1); last_ev := 4; last_dt := sdt; print(last_ev) }; // power off timeout
549
+ ((last_ev = 1) && (last_dt + 720 < sdt) || (last_ev = 2) && res && (hmd < 4500) && (last_dt + 1800 < sdt)) ?? { gpio_set(0, 1); last_ev := 4; last_dt := sdt; print(last_ev) }; // power off timeout
537
550
```
538
551
539
552
###### 2. Add peristent named statement ` fan_control ` for common control logic
@@ -542,7 +555,7 @@ $ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 lsh add -m '
542
555
{
543
556
"lsh.Statement-Name": "fan_control",
544
557
"lsh.Persistent-Flag": 1,
545
- "lsh.Statement-Text": "## last_dt; ## last_ev; # sdt := sysctime();\n(last_ev <= 0) ?? { gpio_set(0, 0); last_ev := 1; last_dt := sdt; print(last_ev) };\n\n# temp = 0; # hmd = 0; # res := !dht_get(1, hmd, temp);\n((last_ev != 2) && res && (hmd >= 3600) && (last_dt + 300 < sdt)) ?? { gpio_set(0, 0); last_ev := 2; last_dt := sdt; print(last_ev) };\n((last_ev = 2) && res && (hmd < 3600) && (last_dt + 300 < sdt)) ?? { gpio_set(0, 1); last_ev := 3; last_dt := sdt; print(last_ev) };\n((last_ev = 1) && (last_dt + 720 < sdt) || (last_ev = 2) && (last_dt + 1800 < sdt)) ?? { gpio_set(0, 1); last_ev := 4; last_dt := sdt; print(last_ev) };"
558
+ "lsh.Statement-Text": "## last_dt; ## last_ev; # sdt := sysctime();\n(last_ev <= 0) ?? { gpio_set(0, 0); last_ev := 1; last_dt := sdt; print(last_ev) };\n\n# temp = 0; # hmd = 0; # res := !dht_get(1, hmd, temp);\n((last_ev != 2) && res && (hmd >= 3600) && (last_dt + 300 < sdt)) ?? { gpio_set(0, 0); last_ev := 2; last_dt := sdt; print(last_ev) };\n((last_ev = 2) && res && (hmd < 3600) && (last_dt + 300 < sdt)) ?? { gpio_set(0, 1); last_ev := 3; last_dt := sdt; print(last_ev) };\n((last_ev = 1) && (last_dt + 720 < sdt) || (last_ev = 2) && res && (hmd < 4500) && (last_dt + 1800 < sdt)) ?? { gpio_set(0, 1); last_ev := 4; last_dt := sdt; print(last_ev) };"
546
559
}'
547
560
```
548
561
0 commit comments