Skip to content

Commit 134a707

Browse files
committed
Merge branch 'dev-0.2.1'
- #1 udpctl: send notification multicast signal messages to target host - #2 udpctl: disable softap by timeout after system start - #3 bug: ntp: sometimes set wrong time, differs from actual by 0.5 - 3 hours - #4 bug: flashdb lost write and corruption - #5 bug: system: startup services in safemode after exception - fixed lots of minor bugs - made some cosmetic improvements
2 parents 77e5faf + b7e0b8f commit 134a707

File tree

31 files changed

+862
-260
lines changed

31 files changed

+862
-260
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ bin/
88

99
# Python cache
1010
__pycache__/
11-
*.pyc
11+
*.pyc
12+
13+
.vscode/

README.md

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@ Light-weight Shell for ESP8266 with support of simple and configurable control l
44
Developed and tested with my ESP-12E (4Mb) board.
55

66
Main Goals:
7+
- OTA firmware update
78
- light-weight udp control/management protocol with python client [esp8266-tshcli]
89
- cron-like task scheduler
910
- simple scripting language for making control logic with trace/debug feature
1011
- almost fixed heap memory consumption
1112

1213
License: GPLv3
1314

14-
*Some of internal solutions may looks weird, but all of it made just for fun and it works well.*
15-
1615
*Feel free to use, improve, report bugs, criticize and etc.*
1716

1817
Contributors
1918
- Denis Muratov <xeronm@gmail.com>
2019

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&currency_code=USD&source=url)
22+
2123
## 1. References
2224

2325
- [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
6062

6163
## 4. Usage
6264

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 | |
6488

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 |
7789

78-
### 4.2. Service documentation
90+
### 4.3. Service documentation
7991

80-
#### 4.2.1. Service management (service)
92+
#### 4.3.1. Service management (service)
8193

82-
##### 4.2.1.1. Message types
94+
##### 4.3.1.1. Message types
8395

8496
|MsgType|Command|Multicast|Description|
8597
|-------|-------|---------|-----------|
@@ -99,9 +111,9 @@ $ sudo docker run --name esp8266 -it --rm -v $PWD:/src/project dtec/esp8266:1.22
99111
|40|MCAST_SIG4|Y| User signal |
100112

101113

102-
#### 4.2.2. System logging (syslog)
114+
#### 4.3.2. System logging (syslog)
103115

104-
##### 4.2.2.2. Configuration parameters
116+
##### 4.3.2.2. Configuration parameters
105117

106118
|Parameter|Level|Description|Default|
107119
|---------|-----|-----------|-------|
@@ -112,9 +124,9 @@ Example:
112124
{ "syslog.Log-Severity": 4 }
113125
```
114126

115-
#### 4.2.3. esp8266 system management (espadmin)
127+
#### 4.3.3. esp8266 system management (espadmin)
116128

117-
##### 4.2.3.1. Configuration parameters
129+
##### 4.3.3.1. Configuration parameters
118130

119131
|Parameter|Level|Description|Default|
120132
|---------|-----|-----------|-------|
@@ -154,7 +166,7 @@ Example:
154166
}
155167
```
156168

157-
##### 4.2.3.2. Message types
169+
##### 4.3.3.2. Message types
158170

159171
|MsgType|Command|Description|
160172
|-------|-------|-----------|
@@ -163,13 +175,14 @@ Example:
163175
|11|FDB_TRUNC|truncate Flash-DB|
164176
|12|FW_OTA_INIT| Initialize OTA firmware upgrade|
165177
|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|
167179
|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|
169182

170-
#### 4.2.4. UDP system management (udpctl)
183+
#### 4.3.4. UDP system management (udpctl)
171184

172-
##### 4.2.4.1. Configuration parameters
185+
##### 4.3.4.1. Configuration parameters
173186

174187
|Parameter|Level|Description|Default|
175188
|---------|-----|-----------|-------|
@@ -186,13 +199,13 @@ Example:
186199
}
187200
```
188201

189-
##### 4.2.4.2. Message types
202+
##### 4.3.4.2. Message types
190203

191204
|MsgType|Command|Description|
192205
|-------|-------|-----------|
193206
|1|INFO|Query information (state, peers, etc.) |
194207

195-
##### 4.2.4.3. Protocol
208+
##### 4.3.4.3. Protocol
196209

197210
###### Message Flow
198211
0. Auth Request
@@ -249,7 +262,7 @@ Example:
249262
- E flag - error answer
250263
- **Command Code** - corresponds to service Message type
251264
- **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
253266
- **Authenticator** - party authenticator issued by originator of auth request/answer message
254267

255268
###### Message Body
@@ -272,13 +285,13 @@ Message body is a sequence of AVP
272285
- **Data** - attribute value data (4-bytes aligned)
273286

274287

275-
#### 4.2.5. Light-weight shell (lwsh)
288+
#### 4.3.5. Light-weight shell (lwsh)
276289

277-
##### 4.2.5.1. Configuration parameters
290+
##### 4.3.5.1. Configuration parameters
278291

279292
This service hasn't any configurable parameters
280293

281-
##### 4.2.5.2. Message types
294+
##### 4.3.5.2. Message types
282295

283296
|MsgType|Command|Description|
284297
|-------|-------|-----------|
@@ -291,9 +304,9 @@ This service hasn't any configurable parameters
291304
|15|LOAD| Load existing script from source (Flash-DB)|
292305
|16|LIST| List all stored scripts from Flash-DB|
293306

294-
#### 4.2.6. Network Time Protocol client (ntp)
307+
#### 4.3.6. Network Time Protocol client (ntp)
295308

296-
##### 4.2.6.1. Configuration parameters
309+
##### 4.3.6.1. Configuration parameters
297310

298311
|Parameter|Level|Description|Default|
299312
|---------|-----|-----------|-------|
@@ -314,33 +327,33 @@ Example:
314327
}
315328
```
316329

317-
##### 4.2.6.2. Message types
330+
##### 4.3.6.2. Message types
318331

319332
|MsgType|Command|Description|
320333
|-------|-------|-----------|
321334
|1|INFO|Query information (state, peers, etc.) |
322335
|10|SETDATE| Query NTP peers and try to set local datetime|
323336

324-
#### 4.2.7. GPIO control management (gpioctl)
337+
#### 4.3.7. GPIO control management (gpioctl)
325338

326-
##### 4.2.7.1. Configuration parameters
339+
##### 4.3.7.1. Configuration parameters
327340

328341
This service hasn't any configurable parameters
329342

330-
##### 4.2.7.2. Message types
343+
##### 4.3.7.2. Message types
331344

332345
|MsgType|Command|Description|
333346
|-------|-------|-----------|
334347
|1|INFO|Query GPIO perepherial information |
335348
|10|OUTPUT_SET| Set output parameters for GPIO PIN (value, delay, function)|
336349

337-
#### 4.2.8. Cron-like scheduler (sched)
350+
#### 4.3.8. Cron-like scheduler (sched)
338351

339-
##### 4.2.8.1. Configuration parameters
352+
##### 4.3.8.1. Configuration parameters
340353

341354
This service hasn't any configurable parameters
342355

343-
##### 4.2.8.2. Message types
356+
##### 4.3.8.2. Message types
344357

345358
|MsgType|Command|Description|
346359
|-------|-------|-----------|
@@ -351,9 +364,9 @@ This service hasn't any configurable parameters
351364
|13|SOURCE| Get source of existing task from Flash-DB|
352365
|14|LIST| List all stored tasks from Flash-DB|
353366

354-
#### 4.2.9. DHT11/AM2302 sensor (dev.dht)
367+
#### 4.3.9. DHT11/AM2302 sensor (dev.dht)
355368

356-
##### 4.2.9.1. Configuration parameters
369+
##### 4.3.9.1. Configuration parameters
357370

358371
|Parameter|Level|Description|Default|
359372
|---------|-----|-----------|-------|
@@ -371,7 +384,7 @@ This service hasn't any configurable parameters
371384
|dht.Temperature| 1 | Temperature Celseus (1/100) | |
372385
|common.Milticast-Signal| 1 | Notification multicast signal_id (32-63)|
373386

374-
##### 4.2.9.2. Message types
387+
##### 4.3.9.2. Message types
375388

376389
|MsgType|Command|Description|
377390
|-------|-------|-----------|
@@ -533,7 +546,7 @@ Following terms were used:
533546
# temp = 0; # hmd = 0; # res := ! dht_get(1, hmd, temp);
534547
((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
535548
((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
537550
```
538551

539552
###### 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 '
542555
{
543556
"lsh.Statement-Name": "fan_control",
544557
"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) };"
546559
}'
547560
```
548561

0 commit comments

Comments
 (0)