I’m migrating my project to using Edgent for the next stage of development. Right now, I’m facing issue with using the reset button to trigger other actions in my code when I’m trying to use Edgent. Some info about my project:
- Custom designed ESP32 board, using ESP32-WROOM-32E
- Blynk library: 1.1.0
Here’s my main code:
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "TMPLMTq2KSTq"
#define BLYNK_DEVICE_NAME "TEST1"
#define BLYNK_FIRMWARE_VERSION "0.5.2"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_WROVER_BOARD
//#define USE_TTGO_T7
//#define USE_ESP32C3_DEV_MODULE
//#define USE_ESP32S2_DEV_KIT
#include "BlynkEdgent.h"
bool trainingState = false;
//V2 is the button for switching training mode, toggle the training state when its pushed
BLYNK_WRITE(V2) {
trainingState = param.asInt(); //store the value from the app/console button state
g_toggle = trainingState;
digitalWrite(LED_MIRROR, trainingState); //switch off the Mirror led
if (trainingState == 1) {
Blynk.virtualWrite(V3, "Training A");
}
else {
Blynk.virtualWrite(V3, "Training B");
}
}
/////////////////////////// SETUP ////////////////////////////////////
void setup() {
Serial.begin(115200);
delay(100);
pinMode(LED_MIRROR, OUTPUT);
BlynkEdgent.begin();
}
//////////////////////////// END OF SETUP ///////////////////////////////
///////////////// MAIN PROGRAM LOOP ///////////////////////////
void loop() {
BlynkEdgent.run();
digitalWrite(LED_MIRROR, g_toggle);
}
And here’s the modified ResetButton.h
:
#ifdef BOARD_BUTTON_PIN
volatile bool g_buttonPressed = false;
volatile uint32_t g_buttonPressTime = -1;
volatile bool g_toggle = false;
void button_action(void)
{
BlynkState::set(MODE_RESET_CONFIG);
}
void button_change(void)
{
#if BOARD_BUTTON_ACTIVE_LOW
bool buttonState = !digitalRead(BOARD_BUTTON_PIN);
#else
bool buttonState = digitalRead(BOARD_BUTTON_PIN);
#endif
if (buttonState && !g_buttonPressed) {
g_buttonPressTime = millis();
g_buttonPressed = true;
DEBUG_PRINT("Hold the button for 10 seconds to reset configuration...");
} else if (!buttonState && g_buttonPressed) {
g_buttonPressed = false;
uint32_t buttonHoldTime = millis() - g_buttonPressTime;
if (buttonHoldTime >= BUTTON_HOLD_TIME_ACTION) {
button_action();
} else if (buttonHoldTime >= BUTTON_PRESS_TIME_ACTION) {
// User action
g_toggle = !g_toggle;
Blynk.virtualWrite(V2, g_toggle);
}
g_buttonPressTime = -1;
}
}
void button_init()
{
#if BOARD_BUTTON_ACTIVE_LOW
pinMode(BOARD_BUTTON_PIN, INPUT_PULLUP);
#else
pinMode(BOARD_BUTTON_PIN, INPUT_PULLDOWN);
#endif
attachInterrupt(BOARD_BUTTON_PIN, button_change, CHANGE);
}
#else
#define g_buttonPressed false
#define g_buttonPressTime 0
void button_init() {}
#endif
Now everytime when I pressed the button, the ESP32 will reset itself. Here’s the debug message from serial monitor:
15:56:09.952 -> rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
15:56:09.952 -> configsip: 0, SPIWP:0xee
15:56:09.952 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
15:56:09.952 -> mode:DIO, clock div:1
15:56:09.952 -> load:0x3fff0030,len:1344
15:56:09.952 -> load:0x40078000,len:13864
15:56:09.952 -> load:0x40080400,len:3608
15:56:09.952 -> entry 0x400805f0
15:56:10.512 -> [228]
15:56:10.512 -> ___ __ __
15:56:10.512 -> / _ )/ /_ _____ / /__
15:56:10.512 -> / _ / / // / _ \/ '_/
15:56:10.512 -> /____/_/\_, /_//_/_/\_\
15:56:10.512 -> /___/ v1.1.0 on ESP32
15:56:10.512 ->
15:56:10.512 -> #StandWithUkraine https://bit.ly/swua
15:56:10.512 ->
15:56:10.512 ->
15:56:10.512 -> [239] --------------------------
15:56:10.512 -> [239] Product: TEST1
15:56:10.512 -> [249] Firmware: 0.5.2 (build Dec 22 2022 15:55:03)
15:56:10.512 -> [249] Token: ba3Y - •••• - •••• - ••••
15:56:10.512 -> [249] Device: ESP32 @ 240MHz
15:56:10.512 -> [260] MAC: C0:49:EF:32:D0:84
15:56:10.512 -> [260] Flash: 4096K
15:56:10.512 -> [260] ESP sdk: v4.4.2
15:56:10.512 -> [260] Chip rev: 3
15:56:10.512 -> [271] Free mem: 238712
15:56:10.512 -> [271] --------------------------
15:56:10.512 ->
15:56:10.512 -> >[271] INIT => CONNECTING_NET
15:56:10.512 -> [271] Connecting to WiFi: HOMEWIFI
15:57:00.514 -> [50289] Connecting to WiFi: HOMEWIFI
15:57:02.657 -> [52434] Using Dynamic IP: 192.168.0.8
15:57:02.657 -> [52434] CONNECTING_NET => CONNECTING_CLOUD
15:57:02.657 -> [52444] Connecting to blynk.cloud:443
15:57:03.726 -> [53474] Certificate OK
15:57:03.726 -> [53506] Ready (ping: 30ms).
15:57:03.820 -> [53574] CONNECTING_CLOUD => RUNNING
15:57:07.905 -> [57650] Hold the button for 10 seconds to reset configuration...
15:57:08.417 -> Guru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0).
15:57:08.417 ->
15:57:08.417 -> Core 0 register dump:
15:57:08.417 -> PC : 0x4009050b PS : 0x00060635 A0 : 0x8008fbf3 A1 : 0x3ffb32e0
15:57:08.417 -> A2 : 0x3ffbf188 A3 : 0xb33fffff A4 : 0x0000abab A5 : 0x00060623
15:57:08.417 -> A6 : 0x00060623 A7 : 0x0000cdcd A8 : 0x0000abab A9 : 0xffffffff
15:57:08.417 -> A10 : 0x3ffbea14 A11 : 0x3ffb342c A12 : 0x00000097 A13 : 0x0000e186
15:57:08.417 -> A14 : 0x007bf188 A15 : 0x003fffff SAR : 0x00000020 EXCCAUSE: 0x00000005
15:57:08.464 -> EXCVADDR: 0x00000000 LBEG : 0x40089988 LEND : 0x4008999e LCOUNT : 0xffffffff
15:57:08.464 ->
15:57:08.464 ->
15:57:08.464 -> Backtrace:0x40090508:0x3ffb32e00x4008fbf0:0x3ffb3320 0x4008d9e6:0x3ffb3340 0x4008de7e:0x3ffb3360 0x4010812a:0x3ffb33a0 0x40108442:0x3ffb33c0 0x40109697:0x3ffb33e0 0x4010adb5:0x3ffb3400 0x400f8ef3:0x3ffb3420
15:57:08.464 ->
15:57:08.464 ->
15:57:08.464 -> Core 1 register dump:
15:57:08.464 -> PC : 0x4009038a PS : 0x00060b35 A0 : 0x8008f0aa A1 : 0x3ffbe91c
15:57:08.464 -> A2 : 0x3ffcfb04 A3 : 0x3ffb8890 A4 : 0x00000004 A5 : 0x00060b23
15:57:08.509 -> A6 : 0x00060b23 A7 : 0x00000001 A8 : 0x3ffb8890 A9 : 0x00000018
15:57:08.509 -> A10 : 0x3ffb8890 A11 : 0x00000018 A12 : 0x3ffc557c A13 : 0x00060b23
15:57:08.509 -> A14 : 0x007bf188 A15 : 0x003fffff SAR : 0x00000018 EXCCAUSE: 0x00000005
15:57:08.509 -> EXCVADDR: 0x00000000 LBEG : 0x40089988 LEND : 0x4008999e LCOUNT : 0xffffffff
15:57:08.509 ->
15:57:08.509 ->
15:57:08.509 -> Backtrace:0x40090387:0x3ffbe91c |<-CORRUPTED
15:57:08.509 ->
15:57:08.509 ->
15:57:08.509 ->
15:57:08.509 ->
15:57:08.509 -> ELF file SHA256: 0000000000000000
15:57:08.509 ->
15:57:08.509 -> Rebooting...
15:57:08.556 -> ets Jul 29 2019 12:21:46
15:57:08.556 ->
I’m guessing I can’t use Blynk.virtualWrite()
in the ISR. But why?