Hi,
I found viewtopic.php?t=7268&p=41350 to answer the question how to detect brownouts, but it opens another one:
If the right way to detect brownouts is to check the reset_cause() to be machine.WDT_RESET, then how can I differentiate brownouts from custom watchdog setups? In my case, I configured the watchdog to listen for pings from a timer function (capturing and uploading data points) . If it fails too often, the watchdog will restart the device. But I can't figure out if there was a brownout this way.
Did I miss something?
Brownout detection vs custom WDT usage
Re: Brownout detection vs custom WDT usage
I don't believe this is true anymore for detecting a brownout, it's reported as a PWRON cause, not a WDT_RESET cause.From MicroPython, a brownout reset can be detected using machine.reset_cause() (which will return machine.WDT_RESET for a brownout).
Code: Select all
STATIC mp_obj_t machine_reset_cause(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
if (is_soft_reset) {
return MP_OBJ_NEW_SMALL_INT(MP_SOFT_RESET);
}
switch (esp_reset_reason()) {
case ESP_RST_POWERON:
case ESP_RST_BROWNOUT:
return MP_OBJ_NEW_SMALL_INT(MP_PWRON_RESET);
break;
case ESP_RST_INT_WDT:
case ESP_RST_TASK_WDT:
case ESP_RST_WDT:
return MP_OBJ_NEW_SMALL_INT(MP_WDT_RESET);
break;
case ESP_RST_DEEPSLEEP:
return MP_OBJ_NEW_SMALL_INT(MP_DEEPSLEEP_RESET);
break;
case ESP_RST_SW:
case ESP_RST_PANIC:
case ESP_RST_EXT: // Comment in ESP-IDF: "For ESP32, ESP_RST_EXT is never returned"
return MP_OBJ_NEW_SMALL_INT(MP_HARD_RESET);
break;
case ESP_RST_SDIO:
case ESP_RST_UNKNOWN:
default:
return MP_OBJ_NEW_SMALL_INT(0);
break;
}
}
Code: Select all
case ESP_RST_POWERON:
case ESP_RST_BROWNOUT:
return MP_OBJ_NEW_SMALL_INT(MP_PWRON_RESET);
break;
You can inspect the reset cause register explicitly if you need to know it was a brownout. I cover how to do this here: viewtopic.php?f=18&t=10751