Blynk EdgeNet Device Doesn't get Online

I’m using ESP32 Dev Module board with following:
• Blynk Library version 1.3.2
• ESP32 board version 2.0.14
I’ve tested the code without Edgenet by using simple Blynk examples and it is working fine. Now in order to configure wifi-credentials I have used same code with Edgenet example and I’m using Blynk application to configure the device. On application I can see the device successfully
• Configuring Devices
• Reconnecting Back to Cloud
Failed when
• Waiting for device Online
Help me in this why it’s not getting online.
If I use Blynk Edgenet example alone without adding my code it gets online easily by Copying Template_ID and Name.

#define BLYNK_TEMPLATE_ID "TMPL"
#define BLYNK_TEMPLATE_NAME "Testxxxx"

#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_ESP32_DEV_MODULE

#include "BlynkEdgent.h"
#include <TimeLib.h>
#include <WidgetRTC.h>

const byte blockPin = 22;  // Pin that we can use to block variablY

BlynkTimer timer;
WidgetRTC rtc;

#define RXp2 16
#define TXp2 17

// Blynk virtual pin assignments
#define VIRTUAL_ENABLE_VALUE V0
#define VIRTUAL_TIME_PIN V1        // time virtual pin
#define VIRTUAL_variablY_COUNT V2   // variablY count
#define VIRTUAL_variablX_COUNT V3    // variablX count
#define VIRTUAL_ERROR_COUNT V4     // Error count
#define VIRTUAL_WIFI V5            // wifi signal strength
#define VIRTUAL_BUTTON_DISABLE V6  // Disable button
#define VIRTUAL_variablZ_COUNT V7     // variablZ count
#define VIRTUAL_ERROR_FLAG V8      // error flag
#define VIRTUAL_BUTTON_TIME V9     // error flag
#define VIRTUAL_BUTTON_HOURS V10   // error flag
#define VIRTUAL_BUTTON_MINS V11    // error flag
#define VIRTUAL_BUTTON_SEC V12     // error flag

int variablYCount = 0;  // Variable to hold variablY count
int variablXCount = 0;   // variable to hold variablX count
int errorCount = 0;    // variable to hold error count
int variablZCount = 0;    // variable to hold variablZ count
int errorFlag = 0;     // variable to hold error flag


void clockDisplay() {
  // You can call hour(), minute(), ... at any time
  // Please see Time library examples for details

  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentTimeDisp = String(hour()) + ":" + minute();
  String currentDate = String(day()) + " " + month() + " " + year();

  // Send time to the App
  Blynk.virtualWrite(VIRTUAL_TIME_PIN, currentTime);
}
void getWifiStrength() {
  Blynk.virtualWrite(VIRTUAL_WIFI, WiFi.RSSI());
}

BLYNK_CONNECTED() {
  // Synchronize time on connection
  rtc.begin();
  // Blynk.syncAll();
}
void requestVariableValue(void);
void setup() {
  Serial.begin(115200);
  delay(100);

  BlynkEdgent.begin();
  // Synchronize values from server

  // Serial.begin(9600, SERIAL_8N1, RXp2, TXp2);

  pinMode(blockPin, OUTPUT);     // Set Block pin as output
  digitalWrite(blockPin, HIGH);  // Initially keep the pin high until blynk works

  Blynk.syncVirtual(VIRTUAL_BUTTON_DISABLE);

  setSyncInterval(10 * 60);  // sync interval in seconds (10 minutes)

  // Display digital clock every 10 seconds
  timer.setInterval(5000L, getWifiStrength);      // Get wifi strength after every 5 seconds
  timer.setInterval(1500L, requestVariableValue);  // Get clock after every 1 seconds
  timer.setInterval(1000L, clockDisplay);         // Get clock after every 1 seconds
}

void loop() {
  BlynkEdgent.run();
  timer.run();
}
void requestVariableValue() {
  if (Serial.available() > 0) {
    String inc = Serial.readStringUntil('x');
    inc.trim();  // Trim new line characters

    if (inc.startsWith("s,")) {                      // Check if incoming data starts's with 's'
      variablYCount = getValue(inc, ',', 1).toInt();  // get variablY count
      variablXCount = getValue(inc, ',', 2).toInt();   // get variablX count
      errorCount = getValue(inc, ',', 3).toInt();    // get error count


      Blynk.virtualWrite(VIRTUAL_variablY_COUNT, variablYCount);  // update values on blynk
      Blynk.virtualWrite(VIRTUAL_variablX_COUNT, variablXCount);    // update values on blynk
      Blynk.virtualWrite(VIRTUAL_ERROR_COUNT, errorCount);      // update values on blynk
    } else if (inc.startsWith("e,")) {                          // Check if incoming data starts's with 'e'
      variablZCount = getValue(inc, ',', 1).toInt();               // get variablY count
      errorFlag = getValue(inc, ',', 2).toInt();                // get variablX count

      Blynk.virtualWrite(VIRTUAL_variablZ_COUNT, variablZCount);  // update values on blynk
      Blynk.virtualWrite(VIRTUAL_ERROR_FLAG, errorFlag);    // update values on blynk
    } else if (inc.startsWith("b,")) {                      // Check if incoming data starts's with 'b' take it as button press
      //Serial.println("Button Press Flag Received");
      String currentTime = String(hour()) + ":" + minute() + ":" + second();
      // Send time to the App
      Blynk.virtualWrite(VIRTUAL_BUTTON_TIME, currentTime);
      Blynk.virtualWrite(VIRTUAL_BUTTON_HOURS, int(hour()));
      Blynk.virtualWrite(VIRTUAL_BUTTON_MINS, int(minute()));
      Blynk.virtualWrite(VIRTUAL_BUTTON_SEC, int(second()));
    }
  }
}

BLYNK_WRITE(VIRTUAL_BUTTON_DISABLE)  // this command is listening if variablY disable button was used
{
  int pinValue = param.asInt();  // assigning incoming value from pin V1 to a variable

  if (pinValue == 1) {
    Blynk.virtualWrite(VIRTUAL_ENABLE_VALUE, 1);
    //Serial.println("Disable variablY");
    digitalWrite(blockPin, HIGH);  // Set block pin as high
  } else if (pinValue == 0) {
    Blynk.virtualWrite(VIRTUAL_ENABLE_VALUE, 0);
    //Serial.println("Enable variablY");
    digitalWrite(blockPin, LOW);  // Set block pin as LOW
  }
}
String getValue(String data, char separator, int index) {
  int found = 0;
  int strIndex[] = { 0, -1 };
  int maxIndex = data.length() - 1;

  for (int i = 0; i <= maxIndex && found <= index; i++) {
    if (data.charAt(i) == separator || i == maxIndex) {
      found++;
      strIndex[0] = strIndex[1] + 1;
      strIndex[1] = (i == maxIndex) ? i + 1 : i;
    }
  }
  return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

Following is the Serial monitor Output.

06:17:04.842 -> [18343] WAIT_CONFIG => CONFIGURING
06:17:04.842 -> [18343] Sending board info...
06:17:13.047 -> [26557] Applying configuration...
06:17:13.047 -> [26557] WiFi SSID: Internet Pass: 285xxxx
06:17:13.047 -> [26557] Blynk cloud: l12b-Cyjq5HeM5XFn-fvzMl_3FF4zra- @ blynk.cloud:443
06:17:13.047 -> [26570] CONFIGURING => SWITCH_TO_STA
06:17:13.105 -> [26575] Switching to STA...
06:17:14.081 -> CORRUPT HEAP: Bad tail at 0x3ffafcdc. Expected 0xbaad5678 got 0x00000000
06:17:14.081 -> 
06:17:14.081 -> assert failed: multi_heap_free multi_heap_poisoning.c:259 (head != NULL)
06:17:14.081 -> 
06:17:14.081 -> 
06:17:14.081 -> Backtrace: 0x40083f01:0x3ffcc2c0 0x4008e14d:0x3ffcc2e0 0x40093871:0x3ffcc300 0x40093469:0x3ffcc430 0x40084471:0x3ffcc450 0x400938a1:0x3ffcc470 0x401412c2:0x3ffcc490 0x40148d6d:0x3ffcc4b0 0x401471e4:0x3ffcc4d0 0x4018051d:0x3ffcc4f0
06:17:14.116 -> 
06:17:14.116 -> 
06:17:14.116 -> 
06:17:14.116 -> 
06:17:14.116 -> ELF file SHA256: 6114ebfdf1df462e
06:17:14.116 -> 
06:17:14.397 -> Rebooting...

@PeteKnight please take a look and suggest a solution for this.

I have added some DEBUBG_PRINT in this function:

void enterSwitchToSTA() {
  BlynkState::set(MODE_SWITCH_TO_STA);

  DEBUG_PRINT("Switching to STA...");

  delay(1000);
  DEBUG_PRINT("1");

  WiFi.mode(WIFI_OFF);
  DEBUG_PRINT("2");
  delay(100);
  DEBUG_PRINT("3");
  WiFi.mode(WIFI_STA);

  DEBUG_PRINT("4");
  BlynkState::set(MODE_CONNECTING_NET);
  DEBUG_PRINT("5");
}

and this is the result of serial monitor:

06:58:07.749 -> [156241] Applying configuration...
06:58:07.749 -> [156241] WiFi SSID: Internet Pass: 285xxxx
06:58:07.749 -> [156241] Blynk cloud: yxaQ5SuJa0m7HtTEuYUIYfQX8rdXizTs @ blynk.cloud:443
06:58:07.749 -> [156254] CONFIGURING => SWITCH_TO_STA
06:58:07.749 -> [156257] Switching to STA...
06:58:08.765 -> [157257] 1
06:58:08.765 -> CORRUPT HEAP: Bad tail at 0x3ffafcdc. Expected 0xbaad5678 got 0x00000000
06:58:08.765 -> 
06:58:08.765 -> assert failed: multi_heap_free multi_heap_poisoning.c:259 (head != NULL)
06:58:08.765 -> 
06:58:08.765 -> 
06:58:08.765 -> Backtrace: 0x40083f01:0x3ffcc2c0 0x4008e14d:0x3ffcc2e0 0x40093871:0x3ffcc300 0x40093469:0x3ffcc430 0x40084471:0x3ffcc450 0x400938a1:0x3ffcc470 0x401413e6:0x3ffcc490 0x40148e91:0x3ffcc4b0 0x40147308:0x3ffcc4d0 0x40180641:0x3ffcc4f0
06:58:08.798 -> 
06:58:08.798 -> 

Difficult to know what’s happening here, because your code is such a mess.

You’re using Legacy commands for RTC…

You need to read the RTC section of the Blynk IoT documentation to understand how RTC now works.

You’re trying to do a Blynk.syncVirtual() in void setup when it needs to be in BLYNK_CONNECTED()

You’re doing some weird stuff with serial ports too. You probably ought to be using one of the ESP32’s other UARTs for receiving whatever data is being read via requestVariableValue().

In this situation you’d be better commenting-out sections of your own code to try to identify the cause of the problem.
It would also be worth using a stack decoder on your backtrack data to narrow-down the area of code that’s causing the crash.

Pete.

Hi @PeteKnight ,
Thanks for the reply. I’m connecting esp32 with an Arduino board and I’m using Serial communication to receive a few variables from Arduino and send them to the Blynk cloud.
I have removed the other extra part for now and added the Serial communication part. I’ve used Serial2 on esp32 for communication. But still the same issue the heap get’s corrupted when trying to connect with WiFi after it change from AP mode.

#define BLYNK_TEMPLATE_ID "TMPL2"
#define BLYNK_TEMPLATE_NAME "Test"

#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_ESP32_DEV_MODULE

#include "BlynkEdgent.h"

BlynkTimer timer;
// Blynk virtual pin assignments

#define VIRTUAL_variableX_COUNT V2  // variableX count
#define VIRTUAL_variableY_COUNT V3   // variableY count
#define VIRTUAL_variableZ_COUNT V4    // variableZ count
#define VIRTUAL_variableW_COUNT V7    // variableW count
#define VIRTUAL_variableZ_FLAG V8     // variableZ flag
#define VIRTUAL_BUTTON_TIME V9    // variableZ flag
#define VIRTUAL_BUTTON_HOURS V10  // variableZ flag
#define VIRTUAL_BUTTON_MINS V11   // variableZ flag
#define VIRTUAL_BUTTON_SEC V12    // variableZ flag


#define RXp2 16
#define TXp2 17

int variableXCount = 0;  // Variable to hold variableX count
int variableYCount = 0;   // variable to hold variableY count
int variableZCount = 0;    // variable to hold variableZ count
int variableWCount = 0;    // variable to hold variableW count
int variableZFlag = 0;     // variable to hold variableZ flag

String getValue(String data, char separator, int index) {
  int found = 0;
  int strIndex[] = { 0, -1 };
  int maxIndex = data.length() - 1;

  for (int i = 0; i <= maxIndex && found <= index; i++) {
    if (data.charAt(i) == separator || i == maxIndex) {
      found++;
      strIndex[0] = strIndex[1] + 1;
      strIndex[1] = (i == maxIndex) ? i + 1 : i;
    }
  }
  return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
void requestVariableValue() {
  if (Serial2.available() > 0) {
    String inc = Serial2.readStringUntil('x');
    inc.trim();  // Trim new line characters

    if (inc.startsWith("s,")) {                      // Check if incoming data starts's with 's'
      variableXCount = getValue(inc, ',', 1).toInt();  // get variableX count
      variableYCount = getValue(inc, ',', 2).toInt();   // get variableY count
      variableZCount = getValue(inc, ',', 3).toInt();    // get variableZ count

      Blynk.virtualWrite(VIRTUAL_variableX_COUNT, variableXCount);  // update values on blynk
      Blynk.virtualWrite(VIRTUAL_variableY_COUNT, variableYCount);    // update values on blynk
      Blynk.virtualWrite(VIRTUAL_variableZ_COUNT, variableZCount);      // update values on blynk
    } else if (inc.startsWith("e,")) {                          // Check if incoming data starts's with 'e'
      variableWCount = getValue(inc, ',', 1).toInt();               // get variableX count
      variableZFlag = getValue(inc, ',', 2).toInt();                // get variableY count

      Blynk.virtualWrite(VIRTUAL_variableW_COUNT, variableWCount);  // update values on blynk
      Blynk.virtualWrite(VIRTUAL_variableZ_FLAG, variableZFlag);    // update values on blynk
    } else if (inc.startsWith("b,")) {                      // Check if incoming data starts's with 'b' take it as button press
      String currentTime = String(random(24)) + ":" + String(random(60)) + ":" + String(random(60));
      // Send time to the App
      Blynk.virtualWrite(VIRTUAL_BUTTON_TIME, currentTime);
      Blynk.virtualWrite(VIRTUAL_BUTTON_HOURS, int(random(24)));
      Blynk.virtualWrite(VIRTUAL_BUTTON_MINS, int(random(60)));
      Blynk.virtualWrite(VIRTUAL_BUTTON_SEC, int(random(60)));
    }
  }
}
void setup() {
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, RXp2, TXp2);
  delay(100);

  BlynkEdgent.begin();
  timer.setInterval(1000L, requestVariableValue);  // Get clock after every 1 seconds
}

void loop() {
  BlynkEdgent.run();
  timer.run();
}

This is Serial communication output.

17:03:03.609 -> >[285] INIT => WAIT_CONFIG
17:03:06.211 -> [2907] AP URL:  blynk.setup
17:03:32.190 -> [28880] WAIT_CONFIG => CONFIGURING
17:03:32.190 -> [28880] Sending board info...
17:03:50.694 -> [47390] Applying configuration...
17:03:50.694 -> [47390] WiFi SSID: Internet Pass: 285xxxx
17:03:50.752 -> [47390] Blynk cloud: YwZKi6vTAgsycvgCA1PGdfoaf08Og7Zm @ blynk.cloud:443
17:03:50.752 -> [47403] CONFIGURING => SWITCH_TO_STA
17:03:50.752 -> 
17:03:50.752 -> ***ERROR*** A stack overflow in task loopTask has been detected.
17:03:50.752 -> 
17:03:50.752 -> 
17:03:50.752 -> Backtrace: 0x40083f21:0x3ffafa20 0x4008e231:0x3ffafa40 0x4009190d:0x3ffafa60 0x4008fde7:0x3ffafae0 0x4008e340:0x3ffafb10 0x4008e2f0:0x00000000 |<-CORRUPTED

Pete.

Hi Pete,
Thanks for the advice. I was able to figure out the issue. As I’m receiving values in form of string separated with delimiter I have used the getValue function to slice the data. This was causing the heap issue after I removed it, which fixed my code issue when connecting with WiFi.

1 Like