OK, first, to answer @rickaves question, I’m using BlynkEdgent, Edgent add to your sketch a lot of processes that manages all the wifi, comissioning, led indicator a lot more. Please, Edgent authors forgive me.
Well. I have good news. I modified the edgent code in order to check if moving BlynkEdgent processes to the second core (Core 0), and keeping my own processes ins the main core (Core 1) will assure that my devices processes will keep running wthout being blocked by the Blynk Wifi reconection.
And it worked!
This is the Edgent example modified. Thanks @PeteKnight for the hint for solving the Stack overflow issue.
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "XXXXX"
#define BLYNK_DEVICE_NAME "XXXXX"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#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"
unsigned long millis_anterior;
unsigned long millis_actual;
unsigned long Intervalo_dosis = 0;
unsigned long Ciclo_dosis;
bool dosificar = false;
void setup()
{
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
xTaskCreatePinnedToCore(loop1, "loop1", 8192, NULL, 1, NULL, 0);
}
void loop1(void *pvParameters) //loop para procesos de BLYNK en Core0
{
while (1)
{
BlynkEdgent.run();
delay(1);
// timer.run();
}
}
void loop() {
millis_actual = millis();
if ( (millis_actual - millis_anterior) >= 30000)
{
dosificar = true;
millis_anterior = millis_actual;
Serial.println("proceso Dispositivo");
}
}
My device have to do a task every 30 seconds, even if the device is offline. (this code still assume that at the power ON the wifi will available to connect Blynk Cloud…
This is the result of the test (serial port):
18:48:35.360 -> [221]
18:48:35.360 -> ___ __ __
18:48:35.360 -> / _ )/ /_ _____ / /__
18:48:35.360 -> / _ / / // / _ \/ '_/
18:48:35.360 -> /____/_/\_, /_//_/_/\_\
18:48:35.360 -> /___/ v1.1.0 on ESP32
18:48:35.360 ->
18:48:35.360 -> #StandWithUkraine https://bit.ly/swua
18:48:35.360 ->
18:48:35.360 ->
18:48:35.360 -> [231] --------------------------
18:48:35.360 -> [231] Product: Dosif Continuo 4Ch
18:48:35.407 -> [241] Firmware: 0.1.18 (build Aug 25 2022 17:47:45)
18:48:35.407 -> [242] Token: XjFX - •••• - •••• - ••••
18:48:35.407 -> [252] Device: ESP32 @ 240MHz
18:48:35.407 -> [252] MAC: 30:C6:F7:30:6B:C4
18:48:35.407 -> [252] Flash: 4096K
18:48:35.407 -> [253] ESP sdk: v4.4.1-472-gc9140caf8c
18:48:35.407 -> [263] Chip rev: 1
18:48:35.407 -> [263] Free mem: 243864
18:48:35.407 -> [263] --------------------------
18:48:35.407 ->
18:48:35.407 -> >[264] INIT => CONNECTING_NET
18:48:35.407 -> [267] Connecting to WiFi: Wifi-Test
18:48:36.815 -> [1655] Using Dynamic IP: 192.168.72.76
18:48:36.815 -> [1658] CONNECTING_NET => CONNECTING_CLOUD
18:48:36.815 -> [1668] Connecting to blynk.cloud:443
18:48:38.030 -> [2877] Certificate OK
18:48:38.217 -> [3088] Ready (ping: 205ms).
18:48:38.311 -> [3158] CONNECTING_CLOUD => RUNNING
18:49:05.118 -> proceso Dispositivo
18:49:35.150 -> proceso Dispositivo
18:50:05.144 -> proceso Dispositivo
18:50:08.130 -> [92991] RUNNING => CONNECTING_NET
18:50:08.130 -> [92995] Connecting to WiFi: Wifi-Test
18:50:35.148 -> proceso Dispositivo
18:50:58.165 -> [143006] Connecting to WiFi: Wifi-Test
18:51:05.147 -> proceso Dispositivo
18:51:17.922 -> [162767] Using Dynamic IP: 192.168.72.76
18:51:17.922 -> [162767] CONNECTING_NET => CONNECTING_CLOUD
18:51:17.922 -> [162779] Connecting to blynk.cloud:443
18:51:19.179 -> [164030] Certificate OK
18:51:19.603 -> [164450] Ready (ping: 416ms).
18:51:19.650 -> [164521] CONNECTING_CLOUD => RUNNING
18:51:35.139 -> proceso Dispositivo
18:52:05.122 -> proceso Dispositivo
18:52:35.144 -> proceso Dispositivo
18:53:05.147 -> proceso Dispositivo
18:53:11.194 -> [276058] RUNNING => CONNECTING_NET
18:53:11.194 -> [276063] Connecting to WiFi: Wifi-Test
18:53:35.127 -> proceso Dispositivo
18:54:01.217 -> [326079] Connecting to WiFi: Wifi-Test
18:54:05.140 -> proceso Dispositivo
18:54:35.145 -> proceso Dispositivo
18:54:51.211 -> [376086] Connecting to WiFi: Wifi-Test
18:55:05.107 -> proceso Dispositivo
18:55:35.120 -> proceso Dispositivo
18:55:41.247 -> [426100] Connecting to WiFi: Wifi-Test
18:56:05.129 -> proceso Dispositivo
18:56:31.243 -> [476117] Connecting to WiFi: Wifi-Test
18:56:35.126 -> proceso Dispositivo
18:57:05.128 -> proceso Dispositivo
18:57:21.255 -> [526131] Connecting to WiFi: Wifi-Test
18:57:35.120 -> proceso Dispositivo
18:58:05.099 -> proceso Dispositivo
18:58:11.282 -> [576140] Connecting to WiFi: Wifi-Test
18:58:35.104 -> proceso Dispositivo
18:59:01.299 -> [626159] Connecting to WiFi: Wifi-Test
18:59:05.131 -> proceso Dispositivo
18:59:35.103 -> proceso Dispositivo
18:59:51.284 -> [676177] Connecting to WiFi: Wifi-Test
19:00:05.111 -> proceso Dispositivo
19:00:35.107 -> proceso Dispositivo
19:00:41.301 -> [726195] Connecting to WiFi: Wifi-Test
19:01:05.126 -> proceso Dispositivo
19:01:31.334 -> [776209] Connecting to WiFi: Wifi-Test
19:01:35.137 -> proceso Dispositivo
19:02:05.109 -> proceso Dispositivo
19:02:21.320 -> [826219] Connecting to WiFi: Wifi-Test
19:02:35.114 -> proceso Dispositivo
19:03:05.110 -> proceso Dispositivo
19:03:11.359 -> [876233] Connecting to WiFi: Wifi-Test
19:03:20.392 -> [885279] Using Dynamic IP: 192.168.72.76
19:03:20.392 -> [885279] CONNECTING_NET => CONNECTING_CLOUD
19:03:20.392 -> [885292] Connecting to blynk.cloud:443
19:03:21.936 -> [886832] Certificate OK
19:03:22.169 -> [887038] Ready (ping: 201ms).
19:03:22.216 -> [887108] CONNECTING_CLOUD => RUNNING
19:03:35.132 -> proceso Dispositivo
As you can see, every 30 seconds, with or without Wifi, my own task will de done by the device, despite the edgent status.
As soon as the wifi is recovered, the Blynk connection will be.
Just a trick, in order to avoid the hardware reset Edgent will do if the wifi doesn’t recover in a long time, I modified the ConfigMode.h in Edgente as was suggested in some post i don’t remember (Be patient @PeteKnight).
void enterError() {
BlynkState::set(MODE_ERROR);
unsigned long timeoutMs = millis() + 10000;
while (timeoutMs > millis() || g_buttonPressed)
{
delay(10);
app_loop();
if (!BlynkState::is(MODE_ERROR)) {
return;
}
}
BlynkState::set(MODE_CONNECTING_NET); //Add this line and comment the original to just try to connect again without HW reset.
/*DEBUG_PRINT("Restarting after error.");
delay(10);
restartMCU();*/
}