diff options
| author | Damien George <damien.p.george@gmail.com> | 2018-11-28 11:55:27 +1100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2018-12-01 17:20:05 +1100 |
| commit | 321d75e08769b82d951fdf65379dab8d0ce76e2f (patch) | |
| tree | 4a65251644c0565e72f613458eaff6ca176ab012 /ports/esp8266 | |
| parent | 9e2dd931455eba4bd3967f9357c919d4e9676ddf (diff) | |
esp8266/modnetwork: Automatically do radio sleep if no interface active.
Reduces current of device by about 55mA when radio is sleeping.
Diffstat (limited to 'ports/esp8266')
| -rw-r--r-- | ports/esp8266/main.c | 7 | ||||
| -rw-r--r-- | ports/esp8266/modnetwork.c | 8 |
2 files changed, 15 insertions, 0 deletions
diff --git a/ports/esp8266/main.c b/ports/esp8266/main.c index 7bb2d8d57..482e32e4d 100644 --- a/ports/esp8266/main.c +++ b/ports/esp8266/main.c @@ -102,6 +102,13 @@ void soft_reset(void) { } void init_done(void) { + // Configure sleep, and put the radio to sleep if no interfaces are active + wifi_fpm_set_sleep_type(MODEM_SLEEP_T); + if (wifi_get_opmode() == NULL_MODE) { + wifi_fpm_open(); + wifi_fpm_do_sleep(0xfffffff); + } + #if MICROPY_REPL_EVENT_DRIVEN uart_task_init(); #endif diff --git a/ports/esp8266/modnetwork.c b/ports/esp8266/modnetwork.c index c7f3397c4..16401c939 100644 --- a/ports/esp8266/modnetwork.c +++ b/ports/esp8266/modnetwork.c @@ -83,7 +83,15 @@ STATIC mp_obj_t esp_active(size_t n_args, const mp_obj_t *args) { } else { mode &= ~mask; } + if (mode != NULL_MODE) { + wifi_fpm_do_wakeup(); + wifi_fpm_close(); + } error_check(wifi_set_opmode(mode), "Cannot update i/f status"); + if (mode == NULL_MODE) { + wifi_fpm_open(); + wifi_fpm_do_sleep(0xfffffff); + } return mp_const_none; } |
