Skip to content

Commit 6477600

Browse files
committed
indent
1 parent f9087e8 commit 6477600

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4723
-4501
lines changed

README.md

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Please feel free to use, improve, report bugs, etc. And if you find my work usef
1515
Contributors:
1616
- Denis Muratov <[email protected]>
1717

18-
## 1. References
18+
## References
1919

2020
- [esp-open-sdk]: Free and open (as much as possible) integrated SDK for ESP8266/ESP8285 chips
2121
- [docker-esp8266]: Toolchain for esp8266 based on crosstool-NG 1.22.x
@@ -25,35 +25,35 @@ Contributors:
2525
[docker-esp8266]: https://github.com/xeronm/docker-esp8266
2626
[esp8266-tshcli]: https://github.com/xeronm/esp8266-tshcli
2727

28-
## 2. Definitions and Abbrevations
28+
## Definitions and Abbrevations
2929

30-
## 3. Buld Firmware from scratch
30+
## Buld Firmware from scratch
3131

32-
### 3.1. Prepare build environment
32+
### Prepare build environment
3333

3434
```
3535
$ sudo docker pull dtec/esp8266:1.22-p
3636
$ git clone https://github.com/xeronm/esp8266-tsh.git
3737
$ cd esp8266-tsh
3838
```
3939

40-
### 3.2. Configure project
40+
### Configure project
4141

4242
Configurables are:
4343
- APP, SPI_MODE, SDK_IMAGE_TOOL in `Makefile`
4444
- Global project defines in `./include/core/config.h`
4545

46-
### 3.3. Buld Firmware
46+
### Buld Firmware
4747

4848
```
4949
$ sudo docker run --name esp8266 -it --rm -v $PWD:/src/project dtec/esp8266:1.22-p
5050
/src/project# make build
5151
```
5252

5353

54-
## 4. Usage
54+
## Usage
5555

56-
### 4.1. Service catalog
56+
### Service catalog
5757

5858
| Id | Name | Description |
5959
| ---| ----------| -----------------------------|
@@ -67,11 +67,11 @@ $ sudo docker run --name esp8266 -it --rm -v $PWD:/src/project dtec/esp8266:1.22
6767
| 7 | gpioctl | GPIO control management |
6868
| 8 | sched | Cron-like scheduler |
6969

70-
### 4.2. Service documentation
70+
### Service documentation
7171

72-
#### 4.2.1. System logging (syslog)
72+
#### System logging (syslog)
7373

74-
##### 4.2.1.2. Configuration parameters
74+
##### Configuration parameters
7575

7676
|Parameter|Level|Description|Default|
7777
|---------|-----|-----------|-------|
@@ -82,9 +82,9 @@ Example:
8282
{ "syslog.Log-Severity": 4 }
8383
```
8484

85-
#### 4.2.2. esp8266 system management (espadmin)
85+
#### esp8266 system management (espadmin)
8686

87-
##### 4.2.2.1. Configuration parameters
87+
##### Configuration parameters
8888

8989
|Parameter|Level|Description|Default|
9090
|---------|-----|-----------|-------|
@@ -95,7 +95,7 @@ Example:
9595
|esp.WiFi-Password| 1 | Password | |
9696
|esp.WiFi-Auto-Connect| 1 | Station mode auto connect (0- disabled, 1- enabled)| 1- enabled |
9797
|esp.WIFI-Soft-AP| 0 | Soft AP mode parameters (object) |
98-
|esp.WiFi-SSID| 1 | SSID | `${HOST_NAME}` or `ESP_${MAC48[3:6]}` |
98+
|esp.WiFi-SSID| 1 | SSID | `${HOST_NAME}` or `ESP_${MAC48[3:6]}`> |
9999
|esp.WiFi-Password| 1 | Password | `${MAC48}` |
100100
|esp.WiFi-Auth-Mode| 1 | Soft AP authentication mode (0- open, 1- wep, 2- wpa psk, 3- wpa2 psk, 4- wpa/wpa2 psk) | 4- wpa/wpa2 psk |
101101

@@ -120,9 +120,9 @@ Example:
120120
}
121121
```
122122

123-
#### 4.2.3. UDP system management (udpctl)
123+
#### UDP system management (udpctl)
124124

125-
##### 4.2.3.1. Configuration parameters
125+
##### Configuration parameters
126126

127127
|Parameter|Level|Description|Default|
128128
|---------|-----|-----------|-------|
@@ -134,53 +134,52 @@ Example:
134134
Example:
135135
```
136136
{
137-
"common.IP-Port": 3901,
137+
"common.IP-Port": 3900,
138138
"uctl.Secret": "mysecret"
139139
}
140140
```
141141

142142

143-
#### 4.2.4. Network Time Protocol client (ntp)
143+
#### Network Time Protocol client (ntp)
144144

145-
##### 4.2.4.1. Configuration parameters
145+
##### Configuration parameters
146146

147147
|Parameter|Level|Description|Default|
148148
|---------|-----|-----------|-------|
149149
|common.Time-Zone| 0 | Local Timezone (1/4 hours) | +0:00 |
150-
|ntp.Poll-Interval| 0 | Poll interval (minutes) | 15 |
150+
|ntp.Poll-Interval| 0 | Poll interval (minutes) | 20 |
151151
|ntp.Peer| 0 |NTP Server peers (object list 0-2 items) | 0.pool.ntp.org, 1.pool.ntp.org |
152152
|common.Host-Name| 1 | NTP Server host | |
153153

154154
Example:
155155
```
156156
{
157157
"common.Time-Zone": "+3:00",
158-
"ntp.Poll-Interval": 15,
158+
"ntp.Poll-Interval": 10,
159159
"ntp.Peer": [
160160
{ "common.Host-Name": "0.pool.ntp.org" },
161161
{ "common.Host-Name": "1.pool.ntp.org" }
162162
]
163163
}
164164
```
165165

166-
## 5. Examples
166+
## Examples
167167

168-
### 5.1. FAN Control Unit
168+
### FAN Control Unit
169169

170-
#### 5.1.1. Scope
170+
#### Scope
171171

172172
Bathroom FAN control unit with DHT11 sensor and 1P solid state relay.
173173

174174
Conrol Logic Goals
175-
- Force turn on FAN when system startup and every day-time hour. Turn off after 12 minutes timeout.
176-
- Turn on/off FAN when humidity reached high/low threshold. Regardless of humidity turn off after 30 minutes.
175+
- Force turn on FAN when system startup and every day-time hour. Turn off after 10 minutes timeout.
176+
- Turn on/off FAN when humidity reached high/low threshold. Regardless of humidity turn off after 20 minutes.
177177
- Cool-down turn on/off humidity event by 5 minutes after last on/off event.
178178

179+
#### Flash Initial Firmware Image
179180

180-
#### 5.1.2. Flash Initial Firmware Image
181-
182-
###### 1. Connect ESP12E to host by serial cable
183-
###### 2. Use esptool for query module `MAC` (in our example was `5ccf7f85e196`)
181+
1. Connect ESP12E to host by serial cable
182+
2. Use esptool for query module `MAC` (in our example was `5ccf7f85e196`)
184183
```
185184
$ sudo esptool.py -p /dev/ttyUSB0 -b 115200 read_mac
186185
esptool.py v2.5.0
@@ -197,7 +196,7 @@ MAC: 5c:cf:7f:85:e1:96
197196
Hard resetting via RTS pin...
198197
```
199198

200-
###### 3. Flash Things-Shell firmware
199+
3. Flash Things-Shell firmware
201200
```
202201
$ cd ./bin
203202
$ sudo esptool.py -p /dev/ttyUSB0 -b 115200 write_flash --flash_freq 80m --flash_mode dio --flash_size 32m --verify \
@@ -208,8 +207,8 @@ $ sudo esptool.py -p /dev/ttyUSB0 -b 115200 write_flash --flash_freq 80m --flash
208207
0x3fe000 blank.bin
209208
```
210209

211-
###### 4. Connect to hidden WiFi AP `ESPTSH_85e196` (last 6 digit of MAC) with password `5ccf7f85e196` (MAC)
212-
###### 5. Check that firmware and `udpctl` service works. Query system information
210+
4. Connect to hidden WiFi AP `ESPTSH_85e196` (last 6 digit of MAC) with password `5ccf7f85e196` (MAC)
211+
5. Check that firmware and `udpctl` service works. Query system information
213212
```
214213
$ ./tcli.py -H 192.168.4.1 -s 5ccf7f85e196 system info
215214
{
@@ -243,9 +242,9 @@ $ ./tcli.py -H 192.168.4.1 -s 5ccf7f85e196 system info
243242
}
244243
```
245244

246-
#### 5.1.3. Configure System
245+
#### Configure System
247246

248-
###### 1. Setup Wi-Fi station mode and system description
247+
1. Setup Wi-Fi station mode and system description
249248
```
250249
$ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 service config set -m '
251250
{
@@ -266,7 +265,7 @@ $ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 service config set -m '
266265
]}'
267266
```
268267

269-
###### 2. Setup Time-Zone
268+
2. Setup Time-Zone
270269
```
271270
$ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 service config set -m '
272271
{
@@ -279,7 +278,7 @@ $ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 service config set -m '
279278
}'
280279
```
281280

282-
###### 3. Save configuration
281+
3. Save configuration
283282
```
284283
$ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 service config save -m '
285284
{
@@ -291,7 +290,7 @@ $ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 service config save -m '
291290
```
292291

293292

294-
#### 5.1.4. Configure Script Logic and Schedule
293+
#### Configure Script Logic and Schedule
295294

296295
Following terms were used:
297296
- global variable `last_ev` - last state change event (0- reset state, 1-force power on, 2- humidity high threshold, 3- humidity low threshold, 4- power off timeout)
@@ -300,8 +299,12 @@ Following terms were used:
300299
- humidity turn on threshold: >= 36%
301300
- humidity turn off threshold: < 36%
302301
- used estimated moving average results from DHT sensor
302+
- force on power off timeout: 12 minutes
303+
- humidity on power off timeout: 30 minutes
304+
- humidity on/off cool down timeout: 5 minutes
305+
303306

304-
###### 1. Make light-shell script with control rule logic. Solution is not optimal, may improved by using dht service thresholds and multicast signal handling
307+
1. Make light-shell script with control rule logic. Solution is not optimal, may improved by using dht service thresholds and multicast signal handling
305308
```
306309
## last_dt; ## last_ev; # sdt := sysctime();
307310
(last_ev <= 0) ?? { gpio_set(0, 0); last_ev := 1; last_dt := sdt; print(last_ev) }; // set initial state, force power on
@@ -312,7 +315,7 @@ Following terms were used:
312315
((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
313316
```
314317

315-
###### 2. Add peristent named statement `fan_control` for common control logic
318+
2. Add peristent named statement `fan_control` for common control logic
316319
```
317320
$ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 lsh add -m '
318321
{
@@ -322,7 +325,7 @@ $ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 lsh add -m '
322325
}'
323326
```
324327

325-
###### 3. Add peristent named statement `fan_force_on` for force turn on by schedule, startum signal, or manual run
328+
3. Add peristent named statement `fan_force_on` for force turn on by schedule, startum signal, or manual run
326329
```
327330
$ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 lsh add -m '
328331
{
@@ -332,7 +335,7 @@ $ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 lsh add -m '
332335
}'
333336
```
334337

335-
###### 4. Perform simple tests
338+
4. Perform simple tests
336339
```
337340
# Force turn on when no initial state
338341
$ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 lsh run -m '{ "lsh.Statement-Name": "fan_control" }'
@@ -386,7 +389,7 @@ $ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 lsh run -m '{ "lsh.Statement-Name":
386389
}
387390
```
388391

389-
###### 5. Output results on uart port
392+
5. Output results on uart port
390393
```
391394
[1200.868] [warn ][ntp] adjust time to: 2018.12.07 08:35:35+3:00 offset:-1.7
392395
[1674.718] [info ][lwsh] load "fan_control"
@@ -397,7 +400,7 @@ $ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 lsh run -m '{ "lsh.Statement-Name":
397400
[2639.283] [info ][lwsh] fan_force_on out: 1
398401
```
399402

400-
###### 6. Add schedules. `fan_force_on` at system startup and every 30th minutes of 09 - 21 day hours. `fan_control` at 15th seconds of every minute
403+
6. Add schedules. `fan_force_on` at system startup and every 30th minutes of 09 - 21 day hours. `fan_control` at 15th seconds of every minute
401404
```
402405
$ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 sched add -m '{
403406
"sched.Entry-Name": "fan_force_on",
@@ -416,10 +419,10 @@ $ ./tcli.py -H 192.168.5.86 -s 5ccf7f85e196 sched add -m '{
416419
```
417420

418421

419-
## 6. Appendix: Memos
422+
## Appendix: Memos
420423

421-
### 6.1. Indent
424+
### Indent
422425
```
423-
$ find ./ -name '*.h' -exec indent -l120 -brs -br -i4 -ci4 -di16 -sc {} -o {} \;
424-
$ find ./ -name '*.c' -exec indent -l120 -brs -br -i4 -ci4 -di16 -sc {} -o {} \;
426+
$ find ./ -name '*.h' -exec indent -l120 -brs -br -i4 -ci4 -di16 --no-tabs -sc {} -o {} \;
427+
$ find ./ -name '*.c' -exec indent -l120 -brs -br -i4 -ci4 -di16 --no-tabs -sc {} -o {} \;
425428
```

arch/default/sysinit.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ system_get_time (void)
4646
return 0;
4747
}
4848

49-
uint32 ICACHE_FLASH_ATTR
50-
system_rtc_clock_cali_proc(void)
49+
uint32 ICACHE_FLASH_ATTR
50+
system_rtc_clock_cali_proc (void)
5151
{
5252
return 0;
5353
}
5454

55-
size_t ICACHE_FLASH_ATTR
56-
fio_user_format(uint32 size)
55+
size_t ICACHE_FLASH_ATTR
56+
fio_user_format (uint32 size)
5757
{
58-
FILE * fp = fopen ("./flash_userdata.bin", "w+");
58+
FILE *fp = fopen ("./flash_userdata.bin", "w+");
5959
if (!fp)
6060
return 0;
6161

@@ -64,34 +64,34 @@ fio_user_format(uint32 size)
6464
}
6565

6666
size_t ICACHE_FLASH_ATTR
67-
fio_user_read(uint32 addr, uint32 *buffer, uint32 size)
67+
fio_user_read (uint32 addr, uint32 * buffer, uint32 size)
6868
{
69-
FILE * fp = fopen ("./flash_userdata.bin", "rb");
69+
FILE *fp = fopen ("./flash_userdata.bin", "rb");
7070
if (!fp || fseek (fp, addr, SEEK_SET))
7171
return 0;
72-
size_t res = fread (buffer, 1, size, fp);
72+
size_t res = fread (buffer, 1, size, fp);
7373
fclose (fp);
7474

7575
return res;
7676
}
7777

78-
size_t ICACHE_FLASH_ATTR
79-
fio_user_write(uint32 addr, uint32 *buffer, uint32 size)
78+
size_t ICACHE_FLASH_ATTR
79+
fio_user_write (uint32 addr, uint32 * buffer, uint32 size)
8080
{
81-
FILE * fp = fopen ("./flash_userdata.bin", "rb+");
81+
FILE *fp = fopen ("./flash_userdata.bin", "rb+");
8282
if ((!fp) && (errno == ENOENT))
8383
fp = fopen ("./flash_userdata.bin", "wb+");
8484

8585
if (!fp || fseek (fp, addr, SEEK_SET))
8686
return 0;
87-
size_t res = fwrite (buffer, 1, size, fp);
87+
size_t res = fwrite (buffer, 1, size, fp);
8888
fclose (fp);
8989

9090
return res;
9191
}
9292

93-
size_t ICACHE_FLASH_ATTR
94-
fio_user_size(void)
93+
size_t ICACHE_FLASH_ATTR
94+
fio_user_size (void)
9595
{
96-
return 2*1024*1024; // 2 Mb
96+
return 2 * 1024 * 1024; // 2 Mb
9797
}

0 commit comments

Comments
 (0)