Skip to content

Commit b4c8aab

Browse files
committed
Reset via input switch toggles, doc updates
1 parent 61be264 commit b4c8aab

File tree

3 files changed

+87
-6
lines changed

3 files changed

+87
-6
lines changed

README.md

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Firmware is compatible with stock and can be uploaded via OTA.
66

77
Reverting to stock firmware is also supported (see below).
88

9+
At the moment only switch functionality is supported - no scheduling, power measurement, etc.
10+
911
## Updating from stock firmware
1012

1113
* Download one of the release builds (see Releases) or build a firmware package yourself (see Building below).
@@ -41,12 +43,18 @@ Reverting to stock firmware is also supported (see below).
4143

4244
* Enjoy!
4345

44-
## Reset
46+
## Recovery
47+
48+
Device can be recovered from invalid wifi configuration with one of two methods:
4549

50+
* On Shelly2.5 press and hold the button for 10 seconds.
51+
* On both models within first 60 seconds of boot, toggle input switch 10 times in succession.
52+
53+
Both of these methods will make device go int AP mode where they can be reconfigured.
4654

4755
## LED indication
4856

49-
Shelly25 has an LED that is used to indicate current status of the device
57+
Shelly2.5 has an LED that is used to indicate current status of the device
5058

5159
* Off - fully provisioned, connected to WiFi, paired.
5260
* Off, short on pulses - HAP server not provisioned (code not set).
@@ -59,14 +67,59 @@ Reverting to stock firmware is also supported (see below).
5967

6068
It is possible to revert back to stock firmware.
6169

62-
TODO(rojer): document.
70+
Stock firmware for Shelly1 can be downloaded [here](http://api.shelly.cloud/firmware/SHSW-1_build.zip),
71+
for Shelly2.5 it's [here](http://api.shelly.cloud/firmware/SHSW-25_build.zip).
72+
73+
Download it and upload via web interface (this firmware does not support pulling from a remote URL).
6374

6475
## Building
65-
* Build and flash the firmware
6676

67-
* When building, specify `MODEL=Shelly1` or `MODEL=Shelly25`
77+
When building, specify `MODEL=Shelly1` or `MODEL=Shelly25`
6878

6979
```
7080
mos build --verbose --local --platform esp8266 --build-var MODEL=Shelly1
7181
```
7282

83+
## Contributions and development
84+
85+
Contributions are welcome!
86+
87+
### OTA method
88+
89+
For development, OTA method is recommended.
90+
91+
Firmware suports OTA via both RPC and HTTP POST, so something like
92+
93+
```
94+
$ make Shelly25 && curl -F commit_timeout=120 -F file=@build_Shelly25/fw.zip http://192.168.11.75/update
95+
```
96+
97+
Note the use of commit timeout: if something goes wrong (as it invariably does during development),
98+
device will revert to previous firmware automatically. If you are happy with the result, you have 2 minutes
99+
to commit the firmware via `curl http://192.168.11.75/update/commit` or `mos --port=ws://192.168.11.75/rpc call OTA.Commit`.
100+
101+
### UDP logging
102+
103+
To get remote access to logs, configure UDP logging:
104+
105+
```
106+
$ mos --port=ws://192.168.11.75/rpc config-set debug.udp_log_addr=192.168.11.30:1234
107+
```
108+
109+
192.168.11.30 is the address of your workstation (or any address, really - even external).
110+
111+
Then use any UDP listener such as netcat to catch the logs. It is also integrated into mos console:
112+
113+
```
114+
$ mos --port udp://:1234/ console
115+
Listening on UDP port 1234...
116+
[Feb 2 03:45:27.030] shellyswitch25-B955B6 59 18.558 2|shelly_main.c:248 Tick uptime: 18.55, RAM: 32880, 22264 free
117+
[Feb 2 03:45:28.058] shellyswitch25-B955B6 60 19.558 2|shelly_main.c:248 Tock uptime: 19.55, RAM: 32880, 22264 free
118+
...
119+
```
120+
121+
122+
## License
123+
124+
This firmware is distributed under Apache 2.0 license.
125+

mos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
author: 'Deomid "rojer" Ryabkov'
22
description: A HomeKit firmware for Shelly switches
3-
version: 0.5.1
3+
version: 1.0.0
44
platform: esp8266
55

66
libs_version: ${mos.version}

src/shelly_sw_service.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,24 @@ struct shelly_sw_service_ctx {
2828
const HAPAccessory *hap_accessory;
2929
const HAPService *hap_service;
3030
bool state;
31+
int change_cnt; // State change counter for reset.
32+
double last_change_ts; // Timestamp of last change (uptime).
3133
};
3234

3335
static struct shelly_sw_service_ctx s_ctx[NUM_SWITCHES];
3436

37+
static void do_reset(void *arg) {
38+
struct shelly_sw_service_ctx *ctx = arg;
39+
mgos_gpio_blink(ctx->cfg->out_gpio, 0, 0);
40+
LOG(LL_INFO, ("Performing reset"));
41+
#ifdef MGOS_SYS_CONFIG_HAVE_WIFI
42+
mgos_sys_config_set_wifi_sta_enable(false);
43+
mgos_sys_config_set_wifi_ap_enable(true);
44+
mgos_sys_config_save(&mgos_sys_config, false, NULL);
45+
mgos_wifi_setup((struct mgos_config_wifi *) mgos_sys_config_get_wifi());
46+
#endif
47+
}
48+
3549
static void shelly_sw_set_state_ctx(struct shelly_sw_service_ctx *ctx,
3650
bool new_state, const char *source) {
3751
const struct mgos_config_sw *cfg = ctx->cfg;
@@ -51,6 +65,20 @@ static void shelly_sw_set_state_ctx(struct shelly_sw_service_ctx *ctx,
5165
mgos_sys_config_save(&mgos_sys_config, false /* try_once */,
5266
NULL /* msg */);
5367
}
68+
double now = mgos_uptime();
69+
if (now < 60) {
70+
if (now - ctx->last_change_ts > 10) {
71+
ctx->change_cnt = 0;
72+
}
73+
ctx->change_cnt++;
74+
ctx->last_change_ts = now;
75+
if (ctx->change_cnt >= 10) {
76+
LOG(LL_INFO, ("Reset sequence detected"));
77+
ctx->change_cnt = 0;
78+
mgos_gpio_blink(cfg->out_gpio, 100, 100);
79+
mgos_set_timer(600, 0, do_reset, ctx);
80+
}
81+
}
5482
}
5583

5684
bool shelly_sw_set_state(int id, bool new_state, const char *source) {

0 commit comments

Comments
 (0)