My blynk keep restart after around 2 hours

Currently i using ESP-01 WiFi Serial Transceiver Module (ESP8266) + Arduino UNO to make my project, I am not using the AT firmware for esp but i do write the code inside. And communicate with Arduino UNO via serial communication. Blynk is work, I send signal to esp every second and esp does the virtualWrite but after around 1 hour or 2 hours, it stack. I tried many way to solve but no luck. I need help. Thanks

Panic core_esp8266_main.cpp:215 loop_task

stack>>>

ctx: sys
sp: 3fffeee0 end: 3fffffb0 offset: 0000
3fffeee0: 00000000 5293929a 40238adb 3ffe9434
3fffeef0: 000000fe 00000000 00000000 00000000
3fffef00: 00000000 00000000 00000000 3ffef15c
3fffef10: 80000000 3fffd9d0 3ffee7f0 3ffef114
3fffef20: 3fffdad0 00000000 3ffe85e0 40208c26
3fffef30: 4023dade 3fffdab0 00000000 40208c93
3fffef40: 00000000 3fffdad0 3ffef114 402085d0
3fffef50: 40000f49 40000f49 3fffdab0 40000f49
3fffef60: 40000e19 0004c0dd 00000000 00000005
3fffef70: 60000600 aa55aa55 000000f5 40105749
3fffef80: 4010574f 00000000 00000005 40100a00
3fffef90: 4010000d a929af98 0004c0dd 401000ac
3fffefa0: 4022de18 3fffef3c 4022ddd1 3ffff3e8
3fffefb0: 00000005 00000000 00000020 4010018c
3fffefc0: 00000005 00000000 000000j⸮ł⸮j4˫⸮’HYY⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮2⸮⸮⸮⸮88 401023b4
3fffefe0: 40102f3b 3ffed088 3ffed0b0 000000fc
3fffeff0: 00000051 083f3452 3ffed9a4 40103118
3ffff000: 3ffe9ec4 00000000 00000000 4010018c
3ffff010: 00000051 083f3452 401035d2 00000100
3ffff020: 3ffe9ec4 7fffffff 00002200 00000001
3ffff030: 00000001 00000080 00000020 4010018c
3ffff040: 3ffe9ec4 f5babe31 00000005 083f3452
3ffff050: 3ffe9edc 2c9f0300 4000050c 3fffc278
3ffff060: 401032f4 3fffc200 00000022 00000100
3ffff070: 402113c5 00000030 00000020 ffffffff
3ffff080: 40211c82 3ffe8368 00000001 00000000
3ffff090: 40310000 3ffff1c0 3ffff1c4 49002e29
3ffff0a0: 00000090 00000007 3ffff363 3ffe8368
3ffff0b0: 00000001 3ffeffac 3ffe8368 00000030
3ffff0c0: 40210a23 00000030 0000001f ffffffff
3ffff0d0: 40210a0d 00000002 3ffff2c8 3ffff260
3ffff0e0: 3fdffffe 00000001 00000001 001ffffe
3ffff0f0:

The main is shown below, *it is not the entire code


void loop()
{
  unsigned short usBaudRate = 9600;
  short sVirtual_Pin = -1;
  short sByte=0;
  char szData[200];
  short usSize = sizeof(szData);
  short sIsDone = 0;

  Blynk.run();

  if(!Blynk.connected())
  {
    Serial.println("NC");  
  }

  memset(szData, '\0', sizeof(szData));

  /*if(Serial.available()) //ok punya
  {
    szData[sByte] = Serial.read();  
    //sByte++;
    //delay(2);
  }*/

  //Read Serial Data
  if(Serial.available())
  {
    gultimeout = millis();

    if(gusSerialByteIndex < usSize)
    {
      gszSerialData[gusSerialByteIndex] = Serial.read();
      gusSerialByteIndex++; 
    }
    else
    {
      Serial.read();
    }
  }
  else
  {
    if(gusSerialByteIndex > 0)
    {
      if((millis() - gultimeout) >= SERIAL_READ_TIME) //if over time, reset
      {
        sByte = gusSerialByteIndex;
        gusSerialByteIndex = 0;
        sIsDone = 1;
  
        strcpy(szData, gszSerialData);
         
        memset(gszSerialData, '\0', sizeof(gszSerialData));
      }
    }
  }
  
  //sByte = sRead_Serial_Data(szData, sizeof(szData));

  if(sByte>0)
  {
    delay(10);
//    Serial.print("sByte: ");
//    Serial.print(sByte);
//    Serial.print(", szData: ");
//    Serial.println(szData);
    
    if(strncmp(szData, "!SW-",4) == 0)
    { 
      char szVData1[30];
      char szVData2[30];
      char szVData3[30];
      char szVData4[30];
      
      memset(szVData1, '\0', sizeof(szVData1));
      memset(szVData2, '\0', sizeof(szVData2));
      memset(szVData3, '\0', sizeof(szVData3));
      memset(szVData4, '\0', sizeof(szVData4));
       
      if(sGet_VirtualWrite_StringData(szData, sVirtual_Pin, szVData1, szVData2, szVData3, szVData4) == OK)
      {
//        Serial.print("sVirtual_Pin: ");
//        Serial.print(sVirtual_Pin);
//        Serial.print(", szVData1: ");
//        Serial.print(szVData1);
//        Serial.print(", szVData2: ");
//        Serial.print(szVData2);
//        Serial.print(", szVData3: ");
//        Serial.print(szVData3);
//        Serial.print(", szVData4: ");
//        Serial.println(szVData4);

        if((sVirtual_Pin >= 0) && (szVData1[0] != '\0'))
        {
          if(szVData4[0] != '\0')
          {
            Blynk.virtualWrite(sVirtual_Pin, szVData1, szVData2, szVData3, szVData4);
          }
          else if(szVData3[0] != '\0')
          {
            Blynk.virtualWrite(sVirtual_Pin, szVData1, szVData2, szVData3);
          }
          else if(szVData2[0] != '\0')
          {
            Blynk.virtualWrite(sVirtual_Pin, szVData1, szVData2);
          }
          else if(szVData1[0] != '\0')
          {
            Blynk.virtualWrite(sVirtual_Pin, szVData1);
          }
        }
                
        Serial.println("OK");
      }
      else
      {
        Serial.println("NOK"); 
      }
    }  
    else if(strncmp(szData, "!DW-",4) == 0)
    { 
      double dValue1 = -9999.99;
      double dValue2 = -9999.99;
      double dValue3 = -9999.99;
      double dValue4 = -9999.99;
       
      if(sGet_VirtualWrite_DoubleData(szData, sVirtual_Pin, dValue1, dValue2, dValue3, dValue4) == OK)
      {
//        Serial.print("sVirtual_Pin: ");
//        Serial.print(sVirtual_Pin);
//        Serial.print(", dValue1: ");
//        Serial.print(dValue1);
//        Serial.print(", dValue2: ");
//        Serial.print(dValue2);
//        Serial.print(", dValue3: ");
//        Serial.print(dValue3);
//        Serial.print(", dValue4: ");
//        Serial.println(dValue4);

        if((sVirtual_Pin >= 0) && (dValue1 != -9999.99))
        {
          if(dValue4 != -9999.99)
          {
            Blynk.virtualWrite(sVirtual_Pin, dValue1, dValue2, dValue3, dValue4);
          }
          else if(dValue3 != -9999.99)
          {
            Blynk.virtualWrite(sVirtual_Pin, dValue1, dValue2, dValue3);
          }
          else if(dValue2 != -9999.99)
          {
            Blynk.virtualWrite(sVirtual_Pin, dValue1, dValue2);
          }
          else if(dValue1 != -9999.99)
          {
            Blynk.virtualWrite(sVirtual_Pin, dValue1);
          }
          delay(100);
          ESP.wdtFeed();
        }
      }
    } 
}

short sGet_VirtualWrite_DoubleData(char *szData, short &sVirtual_Pin, double &dValue1, double &dValue2, double &dValue3, double &dValue4)
{
  short sStatus = NOK;
  char szDummyData[30];
  unsigned short usExit = 0;
  short k=0;
  short i=4;
  short sNumData = 0;

  memset(szDummyData, '\0', sizeof(szDummyData));

  do
  {    
    if(*(szData+i) == '\0')
    {
      usExit = 1;
    }
    else if(*(szData+i) == ',')
    {
      if(sNumData == 0)
      {
        sVirtual_Pin = atoi(szDummyData);
        k=0;
        sNumData++;
        memset(szDummyData, '\0', sizeof(szDummyData));
      }
      else if(sNumData == 1)
      {
        dValue1 = atof(szDummyData);
        k=0;
        sNumData++; 
        memset(szDummyData, '\0', sizeof(szDummyData));       
      }
      else if(sNumData == 2)
      {
        dValue2 = atof(szDummyData);
        k=0;
        sNumData++; 
        memset(szDummyData, '\0', sizeof(szDummyData));       
      }
      else if(sNumData == 3)
      {
        dValue3 = atof(szDummyData);
        k=0;
        sNumData++; 
        memset(szDummyData, '\0', sizeof(szDummyData));       
      }
      else if(sNumData == 4) 
      {
        dValue4 = atof(szDummyData);
        k=0;
        sNumData++; 
        memset(szDummyData, '\0', sizeof(szDummyData));
        usExit = 1;       
      }
    }
    else
    {
      szDummyData[k] = *(szData+i);
      k++;
    }
    
    i++;
    ESP.wdtFeed();
    
  }while(usExit == 0);
 
  if(sVirtual_Pin > -1 && sVirtual_Pin < 128)
  {
    sStatus = OK;
  }

  return sStatus;
}

My advice would be to abandon this hardware setup if you want to work effectively with Blynk.
A NodeMCU or ESP32 would be your best bet, but it depends on what you have attached to your Uno.
If you have to use this hardware combination then go for the AT firmware on the ESP option.

Either way, you should read this…

https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

Pete.

Hi, if using NodeMcu or esp32, some of the sensor library is not stable as esp run the background code for internet. So i wish to use UNO to read sensor and past the value to esp. At firmware is too heavy, so i wish to write my own one.

Thanks for document, but I am not using delay in my code still same problem. And the esp is stack after calling virtualWrite. The system able to run around 1 2 hours then stack.

is there serial read and virtualWrite use together make problem, any things need to take care? I am sure code run without using delay

Okay, you clearly know best.

Pete.

He doesn’t need any help :stuck_out_tongue_winking_eye:

1 Like