ESP8266 Stack when write String value to VirturalPin

Hi guys. I have a problem with writing String value to VirturalPin the problem is when I send request to BLYNK_WRITE(V15) to write the value to Virturalpin 27 ESP8266 get Stack and reboot. how can I fix this ?

BLYNK_WRITE(V15) {
  int pinValue8 = param.asInt();
  if (pinValue8 == 1) {
    Checkout = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " EXIT");
    Blynk.virtualWrite(V27, Checkout);
}
}

the Stack error:

>>>stack>>>

ctx: sys
sp: 3fffff40 end: 3fffffb0 offset: 0000
3fffff40:  00000000 00053bd2 11a9fbe7 3fff1524  
3fffff50:  00000000 00053bd2 1020c49b 3fffefd0  
3fffff60:  3fffdad0 000000fd 00000000 00000000  
3fffff70:  00000000 00000000 00000000 00000000  
3fffff80:  00000000 00053bd2 2a3d70a3 3fff04b0  
3fffff90:  3fffdad0 00000000 3fff0484 4021d77c  
3fffffa0:  3fffdad0 00000000 3fff0484 401006bf  
<<<stack<<<

same problem with this code:

BLYNK_WRITE(V15) {
  char* Checkout = (char*)malloc(50 * sizeof(char));
  int pinValue8 = param.asInt();
  if (pinValue8 == 1) {
    if (Checkout != NULL) {
      snprintf(Checkout, 50, "%02d,%02d,%02d,%04d,%02d,%02d,%s EXIT", hour(), minute(), second(), year(), month(), day(), roomnum);
      Blynk.virtualWrite(V27, Checkout);

      free(Checkout);
    } else {
      Serial.println("Error: failed to allocate memory for Checkout");

    }

  }

}

Without seeing your complete sketch, to understand the values assigned to some of the other variables you’re used when building this strings it’s impossible to form an opinion.
In addition, the stack dump can’t be decided without the full sketch that created it.

Personally though, I’d start by adding some serial prints to print the value of your assembled string before trying to send it to Blynk.

Pete.

1 Like

Thanks for reply. here the full code: :man_facepalming:

[Unformatted code removed by moderator]

@ErfanDL you’ve been around the forum long enough that you shouldn’t need reminding about triple backticks.

Pete.

1 Like

Oh i’m sorry.

#include <FS.h>

#include <Ticker.h>

#include <Arduino.h>

#include <TimeLib.h>

#include <DNSServer.h>

#include <CountDown.h>

#include <WiFiClient.h>

#include <WiFiManager.h>

#include <ESP8266WiFi.h>

#include <ArduinoJson.h>

#include <ESPNtpClient.h>

#include <SoftwareSerial.h>

#include <ESP8266WebServer.h>

#include <ESP8266httpUpdate.h>

#include <ESP8266HTTPClient.h>

#include <BlynkSimpleEsp8266.h>

#define TRIGGER_PIN 0

#define NFC_PIN 12

#define CurrentVersion 1.01

#define BLYNK_Green "#23C48E"

#define BLYNK_Red "#D3435C"

ESP8266WebServer serverh(800);

const char* www_username = "admin";

const char* www_password = "esp8266";

CountDown CD;

Ticker ticker;

WiFiManager wifiManager;

char server[15] = "";

int port2 = 8080;

char blynk_token[34] = "";

char comma = ':';

char comma2 = '-';

char comma3 = '/';

String StringValue;

String StringValue1;

String StringValue2;

String StringValue3;

String StringValue4;

String StringValue5;

String StringValue6;

String StringValue7;

String StringValue8;

String StringValue9;

String StringValue10;

String StringValue11;

String StringValue12;

String StringValue13;

String StringValue14;

String Checkin;

String Checkout;

unsigned long int lastr;

int daycount;

int Hourcount;

unsigned long int saat;

unsigned long int daqiqe;

unsigned long int sanie;

unsigned long int rooz;

int nimcharge = 43200;

unsigned long int nimcharged;

bool wm_nonblocking = false;

bool shouldSaveConfig = false;

char ntpServer[16] = "";

char roomnum[4] = "";

char floornum[3] = "";

char mystr[6] = "nodeo";

char mystrz[2] = "0";

char mystrgu[7] = "gueacc";

char mystrgu2[8] = "gueaccn";

char mystrgu3[7] = "eprclr";

char mystrgu4[6] = "motoo";

char mystrgu5[6] = "motoc";

SoftwareSerial nfcdata(5, 2);

SoftwareSerial eepdata(15, 13);

WidgetLED ROOMLED(V10);

BLYNK_WRITE(V0) {

  int pinValue = param.asInt();

  if (pinValue == 1) {

    Blynk.virtualWrite(V1, "system active");

    digitalWrite(NFC_PIN, LOW);

  }

  if (pinValue == 0) {

    Blynk.virtualWrite(V1, "system deactive");

    digitalWrite(NFC_PIN, HIGH);

  }

}

BLYNK_WRITE(V2) {

  int pinValue1 = param.asInt();

  if (pinValue1 == 1) {

    Blynk.virtualWrite(V1, "door opened");

    nfcdata.write(mystr, 6);

    StringValue10 = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " Master entered");

    File file = SPIFFS.open("/log.txt", "a");

    file.println(StringValue10);

    file.close();

  }

  if (pinValue1 == 0) {

    nfcdata.write(mystrz, 2);

    Serial.flush();

    delay(2000);

    Blynk.virtualWrite(V1, "------");

    Serial.flush();

  }

}

BLYNK_WRITE(V4) {

  int pinValue2 = param.asInt();

  if (pinValue2 == 1) {

    Blynk.virtualWrite(V1, "Guest lock");

    nfcdata.write(mystrgu, 7);

    Serial.flush();

  }

  if (pinValue2 == 0) {

    nfcdata.write(mystrgu2, 8);

    delay(2000);

    Blynk.virtualWrite(V1, "------");

    Serial.flush();

  }

}

BLYNK_WRITE(V6) {

  String pinValue3 = param.asStr();

  for (int i = 0; i < pinValue3.length(); i++)

    eepdata.write(pinValue3[i]);

  Serial.flush();

  delay(5000);

  Blynk.virtualWrite(V6, "------");

}

BLYNK_WRITE(V7) {

  int pinValue4 = param.asInt();

  if (pinValue4 == 1) {

    Blynk.virtualWrite(V1, "Emergency lock");

    nfcdata.write(mystrgu4, 6);

    Serial.flush();

  }

  if (pinValue4 == 0) {

    nfcdata.write(mystrgu5, 6);

    delay(2000);

    Blynk.virtualWrite(V1, "------");

    Serial.flush();

  }

}

BLYNK_WRITE(V8) {

  int pinValue5 = param.asInt();

  daycount = pinValue5;

  CD.stop();

  CD.start(0, 0, 0, 0);

  CD.stop();

  CD.start(daycount, 0, 0, 0);

  StringValue12 = String(daycount) + " day";

  Blynk.virtualWrite(V11, StringValue12);

  Blynk.virtualWrite(V1, "------");

  Checkin = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " Enter");

  delay(1000);

  Blynk.virtualWrite(V27, "------");

  Blynk.virtualWrite(V26, Checkin);

  Blynk.virtualWrite(V4, 0);

  Blynk.virtualWrite(V8, "------");

}

BLYNK_WRITE(V11) {

  int pinValue6 = param.asInt();

}

BLYNK_WRITE(V15) {

  int pinValue8 = param.asInt();

  if (pinValue8 == 1) {

    Checkout = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " Exit");

    Blynk.virtualWrite(V27, Checkout);

    CD.stop();

    CD.start(0, 0, 0, 0);

    CD.stop();

  }

}

BLYNK_WRITE(V17) {

  int pinValue9 = param.asInt();

  lastr = pinValue9;

}

BLYNK_WRITE(V18) {

  int pinValue10 = param.asInt();

  if (pinValue10 == 1) {

    CD.stop();

    CD.start(0, 0, 0, nimcharge + nimcharged);

    Blynk.virtualWrite(V4, 0);

  }

}

BLYNK_WRITE(V19) {

  int pinValue11 = param.asInt();

  int fw = 1236547890;

  if (pinValue11 == fw) {

    wifiManager.setConfigPortalTimeout(120);

    ticker.attach(0.1, tick);

    Blynk.virtualWrite(V19, "------");

    if (!wifiManager.startConfigPortal("ReConfig NFC", "12345678")) {

    }

  }

  if (pinValue11 == 100000) {

    Blynk.virtualWrite(V19, "------");

    delay(2000);

    ESP.reset();

  }

  if (pinValue11 == 700000) {

    Blynk.virtualWrite(V19, "------");

    delay(2000);

    wifiManager.resetSettings();

    SPIFFS.format();

    ESP.restart();

  }

}

BLYNK_WRITE(V20) {

  int pinValue12 = param.asInt();

  if (pinValue12 == 1) {

    check_for_updates();

  }

}

BLYNK_WRITE(V25) {

  int pinValue13 = param.asInt();

  Hourcount = pinValue13;

  CD.stop();

  CD.start(0, Hourcount, 0, 0);

  StringValue11 = String(Hourcount) + " clock";

  Blynk.virtualWrite(V11, StringValue11);

  Blynk.virtualWrite(V1, "------");

  Checkin = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " Enter");

  delay(1000);

  Blynk.virtualWrite(V27, "------");

  Blynk.virtualWrite(V26, Checkin);

  Blynk.virtualWrite(V4, 0);

  Blynk.virtualWrite(V25, "------");

}

BLYNK_WRITE(V26) {

  String pinValue14 = param.asStr();

  StringValue13 = pinValue14;

}

BLYNK_WRITE(V27) {

  String pinValue15 = param.asStr();

  StringValue14 = pinValue15;

}

void handleRootPath() {

  if (serverh.method() == HTTP_GET && serverh.uri() == "/") {

    String path = "/log.txt";

    if (SPIFFS.exists(path)) {

      if (!serverh.authenticate(www_username, www_password)) {

        return serverh.requestAuthentication();

      }

      File file = SPIFFS.open(path, "r");

      size_t sent = serverh.streamFile(file, "application/octet-stream");

      file.close();

    } else {

      serverh.send(404, "text/plain", "404: Not Found");

    }

  }

}

void setup() {

  Serial.begin(19200);

  nfcdata.begin(19200);

  eepdata.begin(19200);

  pinMode(BUILTIN_LED, OUTPUT);

  pinMode(NFC_PIN, OUTPUT);

  pinMode(TRIGGER_PIN, INPUT);

  digitalWrite(NFC_PIN, LOW);

  ticker.attach(0.6, tick);

  wifiManager.setClass("invert");

  Serial.println("Mounting FS...");

  if (SPIFFS.begin()) {

    Serial.println("Mounted file system");

    if (SPIFFS.exists("/config.json")) {

      Serial.println("Reading config file");

      File configFile = SPIFFS.open("/config.json", "r");

      if (configFile) {

        Serial.println("Opened config file");

        size_t size = configFile.size();

        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);

        DynamicJsonDocument json(1024);

        auto deserializeError = deserializeJson(json, buf.get());

        serializeJson(json, Serial);

        if (!deserializeError) {

          Serial.println("\nparsed json");

          strcpy(server, json["server"]);

          strcpy(blynk_token, json["blynk_token"]);

          strcpy(ntpServer, json["ntpServer"]);

          strcpy(roomnum, json["roomnum"]);

          strcpy(floornum, json["floornum"]);

        } else {

          Serial.println("Failed to load json config");

        }

      }

    }

  } else {

    Serial.println("Failed to mount FS");

  }

  wifiManager.setSaveConfigCallback(saveConfigCallback);

  WiFiManagerParameter custom_server("server", "Server", server, 15);

  WiFiManagerParameter custom_blynk_token("blynk", "token", blynk_token, 33);

  WiFiManagerParameter custom_nserver("ntpServer", "NTP IP", ntpServer, 16);

  WiFiManagerParameter custom_roomnum("roomnum", "ROMM NUM", roomnum, 4);

  WiFiManagerParameter custom_floornum("floornum", "Floor", floornum, 3);

  Serial.println(blynk_token);

  wifiManager.addParameter(&custom_server);

  wifiManager.addParameter(&custom_blynk_token);

  wifiManager.addParameter(&custom_nserver);

  wifiManager.addParameter(&custom_roomnum);

  wifiManager.addParameter(&custom_floornum);

  wifiManager.setTimeout(180);

  if (!wifiManager.autoConnect("NFC Access Config", "12345678")) {

    Serial.println("Failed to connect and hit timeout");

    delay(3000);

    ESP.reset();

    delay(5000);

  }

  Serial.println("Motasel shod :)");

  ticker.detach();

  strcpy(server, custom_server.getValue());

  strcpy(blynk_token, custom_blynk_token.getValue());

  strcpy(ntpServer, custom_nserver.getValue());

  strcpy(roomnum, custom_roomnum.getValue());

  strcpy(floornum, custom_floornum.getValue());

  if (shouldSaveConfig) {

    Serial.println("saving config");

    DynamicJsonDocument json(1024);

    //auto deserializeError = deserializeJson(json, buf.get());

    json["server"] = server;

    json["blynk_token"] = blynk_token;

    json["ntpServer"] = ntpServer;

    json["roomnum"] = roomnum;

    json["floornum"] = floornum;

    WiFi.hostname(roomnum);

    ticker.detach();

    flr();

    File configFile = SPIFFS.open("/config.json", "w");

    if (!configFile) {

      Serial.println("Failed to open config file for writing");

    }

    serializeJson(json, Serial);

    serializeJson(json, configFile);

    configFile.close();

  }

  Serial.println("local ip");

  Serial.println(WiFi.localIP());

  WiFi.hostname(roomnum);

  Blynk.config(blynk_token, server, port2);

  Blynk.connect();

  Blynk.syncVirtual(V4);

  Blynk.syncVirtual(V0);

  Blynk.syncVirtual(V17);

  Blynk.syncVirtual(V11);

  Blynk.syncVirtual(V26);

  Blynk.syncVirtual(V27);

  Blynk.virtualWrite(V6, "------");

  Blynk.virtualWrite(V8, "------");

  NTP.setTimeZone(TZ_Asia_Tehran);

  NTP.begin(ntpServer);

  NTP.onNTPSyncEvent(ntpEventHandler);

  serverh.on("/", handleRootPath);

  serverh.begin();

  check_for_updates();

  CD.stop();

  CD.start(0, 0, 0, lastr);

  Serial.flush();

}

void ntphhh() {

  Blynk.virtualWrite(V13, WiFi.localIP().toString());

  Blynk.virtualWrite(V16, map(WiFi.RSSI(), -105, -40, 0, 100));

}

void flr() {

  eepdata.write("w,20,");

  eepdata.write(floornum);

}

void tick() {

  int state = digitalRead(BUILTIN_LED);

  digitalWrite(BUILTIN_LED, !state);

}

void saveConfigCallback() {

  Serial.println("Should save config");

  shouldSaveConfig = true;

  ticker.attach(0.2, tick);

}

void checkButton() {

  if (digitalRead(TRIGGER_PIN) == LOW) {

    delay(50);

    if (digitalRead(TRIGGER_PIN) == LOW) {

      Serial.println("Button Pressed");

      delay(5000);

      if (digitalRead(TRIGGER_PIN) == LOW) {

        Serial.println("Button Held");

        Serial.println("Erasing Config, restarting");

        wifiManager.resetSettings();

        SPIFFS.format();

        ESP.restart();

      }

      Serial.println("Starting config portal");

      wifiManager.setConfigPortalTimeout(120);

      ticker.attach(0.1, tick);

      if (!wifiManager.startConfigPortal("ReConfig NFC", "12345678")) {

        Serial.println("failed to connect or hit timeout");

        Serial.flush();

        ESP.restart();

        delay(5000);

      } else {

        Serial.println("connected...yeey :)");

        Serial.flush();

      }

    }

  }

}

void ntpEventHandler(NTPEvent_t e) {

  if (e.event == timeSyncd || e.event == partlySync) {  // && NTP.millis() % 1000

    time_t utcTime = time(NULL);

    tm* currentTime = localtime(&utcTime);

    //Serial.printf("Hour: %d\n", currentTime->tm_hour);

    //Serial.printf("Minute: %d\n", currentTime->tm_min);

    //Serial.printf("Second: %d\n", currentTime->tm_sec);

    setTime(currentTime->tm_hour, currentTime->tm_min, currentTime->tm_sec + 1, currentTime->tm_mday, currentTime->tm_mon + 1, currentTime->tm_year + 1900);

  }

  if (timeStatus() == timeSet) {

  } else {

  }

}

void nfcreaddata() {

  if (nfcdata.available() > 0) {

    Serial.flush();

    StringValue = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " G1");

    StringValue1 = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " G2");

    StringValue2 = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " G3");

    StringValue3 = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " G4");

    StringValue4 = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " G5");

    StringValue5 = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " G6");

    StringValue6 = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " G7");

    StringValue7 = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " G8");

    StringValue8 = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " G9");

    String teststr = nfcdata.readString();

    teststr.trim();

    Serial.println(teststr);

    if (teststr == "open") {

      Blynk.virtualWrite(V5, "door opened");

      Blynk.virtualWrite(V3, StringValue);

      Serial.println("DOOR OPENED");

      Serial.flush();

      delay(2000);

      Blynk.virtualWrite(V5, "------");

      File file = SPIFFS.open("/log.txt", "a");

      file.println(StringValue);

      file.close();

    }

    if (teststr == "error") {

      Blynk.virtualWrite(V5, "admin entered");

      Blynk.virtualWrite(V3, StringValue4);

      Serial.println("DOOR NOT OPENED");

      Serial.flush();

      delay(2000);

      Blynk.virtualWrite(V5, "------");

      File file = SPIFFS.open("/log.txt", "a");

      file.println(StringValue4);

      file.close();

    }

    if (teststr == "admin") {

      Blynk.virtualWrite(V5, "admin entered");

      Serial.flush();

      delay(2000);

      Blynk.virtualWrite(V5, "------");

    }

    if (teststr == "noadmin") {

      Blynk.virtualWrite(V5, "admin exit");

      Serial.flush();

      delay(2000);

      Blynk.virtualWrite(V5, "------");

    }

    if (teststr == "add") {

      Blynk.virtualWrite(V5, "NFC added");

      Serial.flush();

      delay(2000);

      Blynk.virtualWrite(V5, "------");

    }

    if (teststr == "remove") {

      Blynk.virtualWrite(V5, "NFC removed");

      Serial.flush();

      delay(2000);

      Blynk.virtualWrite(V5, "------");

    }

    if (teststr == "wifi") {

      Serial.flush();

      delay(2000);

      wifiManager.resetSettings();

      SPIFFS.format();

      ESP.restart();

    }

    if (teststr == "khane") {

      Blynk.virtualWrite(V5, "door opened");

      Blynk.virtualWrite(V3, StringValue1);

      Serial.println("DOOR OPENED");

      Serial.flush();

      delay(2000);

      Blynk.virtualWrite(V5, "------");

      File file = SPIFFS.open("/log.txt", "a");

      file.println(StringValue1);

      file.close();

    }

    if (teststr == "tasisat") {

      Blynk.virtualWrite(V5, "door opened");

      Blynk.virtualWrite(V3, StringValue2);

      Serial.println("DOOR OPENED");

      Serial.flush();

      delay(2000);

      Blynk.virtualWrite(V5, "------");

      File file = SPIFFS.open("/log.txt", "a");

      file.println(StringValue2);

      file.close();

    }

    if (teststr == "master") {

      Blynk.virtualWrite(V5, "door opened");

      Blynk.virtualWrite(V3, StringValue3);

      Serial.println("DOOR OPENED");

      Serial.flush();

      delay(2000);

      Blynk.virtualWrite(V5, "------");

      File file = SPIFFS.open("/log.txt", "a");

      file.println(StringValue3);

      file.close();

    }

    if (teststr == "bellboy") {

      Blynk.virtualWrite(V5, "door opened");

      Blynk.virtualWrite(V3, StringValue5);

      Serial.println("DOOR OPENED");

      Serial.flush();

      delay(2000);

      Blynk.virtualWrite(V5, "------");

      File file = SPIFFS.open("/log.txt", "a");

      file.println(StringValue5);

      file.close();

    }

    if (teststr == "bellboyno") {

      Blynk.virtualWrite(V3, StringValue6);

      Serial.flush();

      delay(2000);

      File file = SPIFFS.open("/log.txt", "a");

      file.println(StringValue6);

      file.close();

    }

    if (teststr == "tasisatno") {

      Blynk.virtualWrite(V3, StringValue7);

      Serial.flush();

      delay(2000);

      File file = SPIFFS.open("/log.txt", "a");

      file.println(StringValue7);

      file.close();

    }

    if (teststr == "khaneno") {

      Blynk.virtualWrite(V3, StringValue8);

      Serial.flush();

      delay(2000);

      File file = SPIFFS.open("/log.txt", "a");

      file.println(StringValue8);

      file.close();

    }

  }

}

void connectionstatus() {

  if ((WiFi.status() != WL_CONNECTED)) {

    ESP.restart();

  } else {

  }

  if (!Blynk.connected()) {

    Blynk.connect();

  } else {

  }

}

void countday() {

  static uint32_t last_remaining = 0;

  if (last_remaining != CD.remaining() || CD.remaining() == 0) {

    last_remaining = CD.remaining();

    nimcharged = CD.remaining();

  }

  rooz = saat / 24;

  saat = last_remaining / 3600L;                     //  in integer arithmetics

  daqiqe = (last_remaining - 3600UL * saat) / 60UL;  // in integer arithmetics

  sanie = last_remaining - 3600UL * saat - 60UL * daqiqe;

  StringValue9 = (String(rooz) + " " + "Day" + " " + comma2 + " " + "و" + " " + String(saat) + comma + String(daqiqe));

  Blynk.virtualWrite(V9, StringValue9);

  Blynk.virtualWrite(V17, last_remaining);

  if (CD.remaining() > 0) {

    ROOMLED.on();

    ROOMLED.setColor(BLYNK_Red);

  }

  if (CD.remaining() == 0) {

    Blynk.virtualWrite(V4, 1);

    CD.start(0, 0, 0, 0);

    CD.stop();

    Blynk.virtualWrite(V9, "End");

    ROOMLED.on();

    ROOMLED.setColor(BLYNK_Green);

  }

}

void update_started() {

  Blynk.virtualWrite(V21, "Updating");

}

void otaUpdate(String url) {

  WiFiClient client;

  HTTPClient http;

  ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);

  ESPhttpUpdate.onStart(update_started);

  t_httpUpdate_return ret = ESPhttpUpdate.update(client, url);

  switch (ret) {

    case HTTP_UPDATE_FAILED:

      Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());

      break;

    case HTTP_UPDATE_NO_UPDATES:

      Serial.println("HTTP_UPDATE_NO_UPDATES");

      break;

    case HTTP_UPDATE_OK:

      Serial.println("HTTP_UPDATE_OK");

      break;

  }

}

void check_for_updates() {

  WiFiClient client;

  HTTPClient http;

  http.begin(client, "http://10.5.51.5/updates/firmware.json");

  int httpCode = http.GET();

  String payload = "";

  if (httpCode > 0) {

    payload = http.getString();

  }

  http.end();  //Close connection

  String json = "";

  DynamicJsonDocument doc(1024);

  json = payload.c_str();

  DeserializationError error = deserializeJson(doc, json);

  if (error) {

  }

  if (doc["ver"] > CurrentVersion && doc["ver"] != CurrentVersion) {

    Blynk.virtualWrite(V21, "Downloading");

    delay(3000);

    otaUpdate(doc["link"]);

  } else {

    Blynk.virtualWrite(V21, "Latest is installed");

  }

}

void loop() {

  if (wm_nonblocking) wifiManager.process();

  checkButton();

  serverh.handleClient();

  Blynk.run();

  nfcreaddata();

  static unsigned long ntphhh_timer = millis();

  if (millis() - ntphhh_timer >= 10000) {

    ntphhh();

    ntphhh_timer = millis();

  }

  // Run 'connectionstatus' every 1 minute

  static unsigned long connectionstatus_timer = millis();

  if (millis() - connectionstatus_timer >= 60000) {

    connectionstatus();

    connectionstatus_timer = millis();

  }

  // Run 'check_for_updates' every 30 minutes

  static unsigned long check_for_updates_timer = millis();

  if (millis() - check_for_updates_timer >= 1800000) {

    check_for_updates();

    check_for_updates_timer = millis();

  }

  // Run 'countday' every 2 seconds

  static unsigned long countday_timer = millis();

  if (millis() - countday_timer >= 2000) {

    countday();

    countday_timer = millis();

  }

}

So, did you take my advice about…

Pete.

1 Like

yes and it’s printed correctly.

So do you want to share the code change and serial monitor output?

Pete.

1 Like

here what I changed in code:

BLYNK_WRITE(V15) {
  int pinValue8 = param.asInt();
  if (pinValue8 == 1) {
    Checkout = (String(hour()) + comma + String(minute()) + comma + String(second()) + comma2 + String(year()) + comma3 + String(month()) + comma3 + String(day()) + comma2 + roomnum + " Exit");
    Serial.println(Checkout);
    Blynk.virtualWrite(V27, Checkout);
    CD.stop();
    CD.start(0, 0, 0, 0);
    CD.stop();
  }
}

Serial output:

20:28:2-2023/3/2- Exit

So you no longer get the crash dump problem?

Pete.

1 Like

When I run V15 several times, the same stack problem occurs.

And if you comment-out this line it works fine?…

Pete.

1 Like

yes. did you think problem with Blynk library ? I installed the latest version also tested with 0.6.1 library but nothing changed.

Are you using Blynk Legacy and a local server, or Blynk IoT?

Pete.

1 Like

yes, using legacy and local server.

Don’t you think it would have been a good idea to start your first post in this topic with “I’m using Blynk legacy version xx.x on a yyy machine and running Android/iOS app version zzz” and using Blynk C++ library version n.n.n” ?

Pete.

1 Like

sorry about that :frowning: legacy version 0.41.17 on a Debian 11 machine and running Android app version 2.27.34 and using Blynk C++ library version 1.2.0” ?

@PeteKnight
I asked ChatGPT about this problem and She/He/… suggested Checkout.reserve(0); after Write to virtual pin. and now the problem is solved.