ESP8266 hangs on Blynk.virtualWrite

You are using the 15 month old core that has loads of bugs that have been fixed but I wouldn’t make the switch until we have seen a proper Serial Monitor output.

I can do that @Costas, but if you check the code, I have those lines before the If statement:

  for (i = 0; i < 4; i = i+1 )
  {
    Serial.print("Canal ");
    Serial.print(String(i+1));
    Serial.print(": ");
    Serial.print(String(potCanal[i]));
    if ( ( i == Luz_Luna - 2 ) && ( potCanal[i] <= 50 ) ) Serial.print(" Luna");
    Serial.println("");
  }
  Serial.println(F("-----------------"));
    if (Blynk.connected()==true) {
      Serial.println("*Blynk");
//      Blynk.virtualWrite(V10, potCanal[0]);
      delay(50);
      Serial.println("*Blynk1");   
//      Blynk.virtualWrite(V11, potCanal[1]);
      delay(50);
      Serial.println("*Blynk2");
//      Blynk.virtualWrite(V12, potCanal[2]);
      delay(50);
      Serial.println("*Blynk3");
//      Blynk.virtualWrite(V13, potCanal[3]);
      delay(50);
      Serial.println("Blynk*");
  }

and this is what is printing on the console right now:

16:45
Nubes Suaves
Canal 1: 99
Canal 2: 4997
Canal 3: 4518
Canal 4: 0
-----------------
*Blynk
*Blynk1
*Blynk2
*Blynk3
Blynk*
[1657925] <[06|00|9C|00|00]
[1658162] >[00|00|9C|00|C8]

Well, I’m sorry, is not exactly what you suggest, because I’m printing string convert. I’ll do what you suggest right away

Exactly and you might find Blynk needs the same.

Right, this is the code running now:

if (Blynk.connected()==true) {
  Serial.println(potCanal[0]);
  delay(50);
  Serial.println(potCanal[1]); 
  delay(50);
  Serial.println(potCanal[2]); 
  delay(50);
  Serial.println(potCanal[3]);
  delay(50); 
  }

and the output?

just a minute @Costas to let it run. It runs the funtion every 60 seconds

OK, first console outputs:

16:51
Nubes Suaves
Canal 1: 19
Canal 2: 4990
Canal 3: 4590
Canal 4: 0
-----------------
19
4990
4590
0
[114259] >[11|00|03|00|0E]
[114259] >rtc[00]1507222333
[114259] Time sync: OK
[114259] >[14|00|04|00|07]
[114259] >vw[00]26[00]3
[114266] <[13|00|04|00|09]0[00]max[00]100
[114562] <[13|00|04|00|09]1[00]max[00]100
[114766] <[13|00|04|00|09]2[00]max[00]100
[114971] <[13|00|04|00|09]3[00]max[00]100
[115188] >[14|00|04|00]*
[115188] >vw[00]18[00]46800[00]61200[00]America/Santiago[00|00]-10800
[115189] >[14|00|04|00]*
[115189] >vw[00]19[00]36000[00]68400[00]America/Santiago[00|00]-10800
[115257] >[14|00|04|00]*
[115285] >vw[00]20[00]28800[00]75600[00]America/Santiago[00|00]-10800
[115359] >[14|00|04|00|07]
[115388] >vw[00]0[00]30
[115414] >[14|00|04|00|08]
[115443] >vw[00]1[00]100
[115470] >[14|00|04|00|08]
[115499] >vw[00]2[00]100
[115526] >[14|00|04|00|18]
[115555] >vw[00]9[00]* Cambio  Suave *[0D|0A]
[115604] >[14|00|04|00|07]
[115633] >vw[00]27[00]1
[115660] >[14|00|04|00|07]
[115689] >vw[00]15[00]0
[115715] >[14|00|04|00]&
[115742] >vw[00]21[00]0[00]39600[00]America/Santiago[00|00]-10800
Start: 0:0:0
Stop: 11:0:0
[115841] >[14|00|04|00|08]
[115870] >vw[00]3[00]100
[115897] >[14|00|04|00|09]
[115926] >vw[00]14[00]756
[115954] >[14|00|04|00|0A]
[115983] >vw[00]12[00]3595
[116013] >[14|00|04|00|0A]
[116042] >vw[00]11[00]4100
[116071] >[14|00|04|00|0A]
[116100] >vw[00]10[00]1387
[116129] >[14|00|04|00|0B]
[116158] >vw[00]8[00]39.188
[116189] >[14|00|04|00|07]
[116218] >vw[00]13[00]0
[116244] >[00|00|04|00|C8]
[116273] >[00|00|04|00|C8]
[116302] >[00|00|04|00|C8]
[116331] >[00|00|04|00|C8]
[125178] <[06|00|06|00|00]
[125423] >[00|00|06|00|C8]
[135424] <[06|00|07|00|00]
[135656] >[00|00|07|00|C8]
[145657] <[06|00|08|00|00]
[145902] >[00|00|08|00|C8]
16:52
Nubes Suaves
Canal 1: 12
Canal 2: 4996
Canal 3: 4607
Canal 4: 0
-----------------
12
4996
4607
0
[155902] <[06|00|09|00|00]
[156136] >[00|00|09|00|C8]
[166137] <[06|00|0A|00|00]
[166386] >[00|00|0A|00|C8]
[176386] <[06|00|0B|00|00]
[176617] >[00|00|0B|00|C8]
[186618] <[06|00|0C|00|00]
[186858] >[00|00|0C|00|C8]
[196859] <[06|00|0D|00|00]
[197097] >[00|00|0D|00|C8]
[207098] <[06|00|0E|00|00]
[207338] >[00|00|0E|00|C8]
16:53
Nubes Suaves
Canal 1: 9
Canal 2: 4994
Canal 3: 4626
Canal 4: 0
-----------------
9
4994
4626
0
[217339] <[06|00|0F|00|00]
[217576] >[00|00|0F|00|C8]
[227577] <[06|00|10|00|00]
[227816] >[00|00|10|00|C8]
[237817] <[06|00|11|00|00]
[238056] >[00|00|11|00|C8]
[248057] <[06|00|12|00|00]
[248296] >[00|00|12|00|C8]
[258297] <[06|00|13|00|00]
[258537] >[00|00|13|00|C8]
[268538] <[06|00|14|00|00]
[268689] >[00|00|14|00|C8]
16:54
Nubes Suaves
Canal 1: 6
Canal 2: 4991
Canal 3: 4635
Canal 4: 0
-----------------
6
4991
4635
0
[278690] <[06|00|15|00|00]
[278914] >[00|00|15|00|C8]
[288915] <[06|00|16|00|00]
[289155] >[00|00|16|00|C8]
[299155] <[06|00|17|00|00]
[299395] >[00|00|17|00|C8]
[309395] <[06|00|18|00|00]
[309635] >[00|00|18|00|C8]
[319635] <[06|00|19|00|00]
[319888] >[00|00|19|00|C8]
[329889] <[06|00|1A|00|00]
[330121] >[00|00|1A|00|C8]
16:55
Nubes Suaves
Canal 1: 4
Canal 2: 4990
Canal 3: 4645
Canal 4: 0
-----------------
4
4990
4645
0
[340122] <[06|00|1B|00|00]
[340355] >[00|00|1B|00|C8]

It looks like it hanged again, more than 5 minutes without any additional output to the console:

17:10
Nubes Suaves
Canal 1: 0
Canal 2: 4882
Canal 3: 4808
Canal 4: 0
-----------------
0
4882
4808
0
[1233352] <[06|00]s[00|00]
[1233496] >[00|00]s[00|C8]
[1243497] <[06|00]t[00|00]
[1243735] >[00|00]t[00|C8]
[1253736] <[06|00]u[00|00]
[1253975] >[00|00]u[00|C8]
[1263976] <[06|00]v[00|00]
[1264209] >[00|00]v[00|C8]
[1274210] <[06|00]w[00|00]
[1274449] >[00|00]w[00|C8]
[1284450] <[06|00]x[00|00]
[1284689] >[00|00]x[00|C8]
17:11
Nubes Suaves
Canal 1: 0
Canal 2: 4871
Canal 3: 4815
Canal 4: 0
-----------------
0
4871
4815
0
[1294690] <[06|00]y[00|00]
[1294933] >[00|00]y[00|C8]
[1304934] <[06|00]z[00|00]
[1305220] >[00|00]z[00|C8]
[1315221] <[06|00]{[00|00]
[1315410] >[00|00]{[00|C8]
[1325411] <[06|00]|[00|00]
[1325649] >[00|00]|[00|C8]
[1335650] <[06|00]}[00|00]
[1335889] >[00|00]}[00|C8]
[1345890] <[06|00]~[00|00]
[1346130] >[00|00]~[00|C8]
17:12
Nubes Suaves
Canal 1: 0
Canal 2: 4859
Canal 3: 4822
Canal 4: 0
-----------------
0
4859
4822
0
[1356131] <[06|00|7F|00|00]
[1356369] >[00|00|7F|00|C8]
[1366370] <[06|00|80|00|00]
[1366616] >[00|00|80|00|C8]
[1376616] <[06|00|81|00|00]
[1376850] >[00|00|81|00|C8]
[1386851] <[06|00|82|00|00]
[1387089] >[00|00|82|00|C8]
[1397090] <[06|00|83|00|00]
[1397335] >[00|00|83|00|C8]
[1407336] <[06|00|84|00|00]
[1407479] >[00|00|84|00|C8]
[1412716] <[11|00|85|00|08]rtc[00]sync
17:13
Nubes Suaves
Canal 1: 0
Canal 2: 4853
Canal 3: 4835
Canal 4: 0
-----------------
0
4853
4835
0
[1413100] >[11|00|85|00|0E]
[1413101] >rtc[00]1507223632
[1413101] Time sync: OK
?)⸮⸮

Yes, it hanged again… is offline according to the blynk app.
This is very strange.

Can be some conflict with the way i’m handling the PWM outputs?

This way is a modified way that avoids the ugly flicks in low pwm duty cicles.

@lrossel in the IDE switch from NodeMCU to generic ESP and ensure you have the correct settings.

Then add the advanced ESP8266 debugging feature http://arduino-esp8266.readthedocs.io/en/latest/Troubleshooting/debugging.html.

I would suggest the stack tracer too but you are not getting to see the stack errors.

1 Like

HI @Costas, I’m trying to compile with your suggestions but it doesn’t:

   pinMode(D8, OUTPUT);

           ^

exit status 1
'D1' was not declared in this scope 

I just checked:

This is the latest (pre)release with the updates referred to.

You can find it here…

Releases · esp8266/Arduino · GitHub

You need to use GPIO references in your sketch not the Dx references. You could just define the pin mappings e.g.

#define Dx y

Upgrading to 2.40-rc1 or even the master will be a big improvement over 2.30 but I suspect you have something fundamentally wrong with your sketch / hardware.

You are multiplexing right?

Split the code into sections and just run each part to try and isolate the issue.

Thanks for your help Costas.

I did a little change on the code yesterday night and selected a different set of data to get de “PWM duty v/s time”. And for more than 8 hours, no problems at all.

Of course, this is not good to find the problem.

But I suspect is something related with the PWM duty changes when I set a different value to change de light. I will keep it running all day to see what happens.

I have two cloned ESP8266 boards running, one in my aquarium and other in a bread board, connected to my computer. It’s a good way to test because the fail happens in both at the same time. And how the boardd just act according to the parameters sent by Blynk, there isn’t any conflict.

To try, I just upgraded the core for the testing ESP on the bread board.

The changes on the code I did last night where:

  Serial.println(currentTime);
  Serial.println(Modo_txt[Modo-1]);
  terminal.println(currentTime);
  terminal.println(Modo_txt[Modo-1]);
  terminal.flush();
  for (i = 0; i < 4; i = i+1 )
  {
    Serial.print("Canal ");
    Serial.print(i+1);
    Serial.print(": ");
    Serial.print(potCanal[i]);
    terminal.print("Canal ");
    terminal.print(i+1);
    terminal.print(": ");
    terminal.print(potCanal[i]);
//    terminal.flush();
    Blynk.virtualWrite(Graph_Canal[i], potCanal[i]);
    if ( ( i == Luz_Luna - 2 ) && ( potCanal[i] <= 50 ) ) {
      Serial.print(" Luna");
      terminal.print(" Luna");
    }
    Serial.println("");
    terminal.println("");
    delay(10);
    terminal.flush();
  }
  Serial.println(F("-----------------"));
  terminal.println(F("-----------------"));
  terminal.flush();

I put again the Blynk.virtualWrite functions because these wasn’t the cause of the problem as we probed yesterday.

May be I have to edit the Topic.

I’m electronic engineer… I’m not doing multiplexing as we electronics understand. May be from a software point of view.

I’m doing a for loop to select the PWM Channel, and set the right duty cicle for each channel according to the parameters set on the blynk app. That’s why I’m ussing arrays.

For example. the following code in my sketch reads the memory where I have stored “curve values”. It get’s the right value depending of the time start and time end configured for each channel:

for (i = 0; i < 4; i = i + 1) 
{
  if ( (FotoPeriodo_Fin_Canal[i] - FotoPeriodo_Inicio_Canal[i]) != 0 )
  {
    Minuto_Ajustado = ( h*60 + m - FotoPeriodo_Inicio_Canal[i]) * 1020 / (FotoPeriodo_Fin_Canal[i] - FotoPeriodo_Inicio_Canal[i]);  
  }
  else
  {
    Minuto_Ajustado = ( h*60 + m - FotoPeriodo_Inicio_Canal[i]);
    Serial.println("Error de fotoperiodo");
  }
  if ( Minuto_Ajustado < 0 ) Minuto_Ajustado = 0;
  if ( Minuto_Ajustado > 1020) Minuto_Ajustado = 1020;
  posmem = (Modo-2)*2042 + (Minuto_Ajustado)*2;
  uint8_t byteval_1 = pgm_read_byte(curvas + posmem);
  posmem = posmem + 1;
  uint8_t byteval_2 = pgm_read_byte(curvas + posmem);
  if ( Luz[i] > 100) Luz[i] = 100;
  potCanal[i] = (byteval_1*256 + byteval_2)*Luz[i]/100;
  
  if ( (i == Luz_Luna - 2) && (potCanal[i] <= 10) ) potCanal[i] = 50;
  int x;
  x = luz_anterior[i] - potCanal[i];
  if ( abs(x) >= 500 )
  {
    deltaLuz[i] = ( potCanal[i] - luz_anterior[i] ) / 10;
    int Conteo_Segundos = 0;
    long millis_anterior = 0;
    long millis_actual = 0;
    terminal.println(F("-----------------"));
    terminal.println("* Cambio  Suave *");
    terminal.flush();
    Serial.println("* Cambio Suave *");
    Blynk.disconnect();
    while (Conteo_Segundos < 10)
    {
      millis_actual = millis();
      yield();
      if ( (millis_actual - millis_anterior) > 1000 )
      {
        millis_anterior = millis_actual;
        Conteo_Segundos = Conteo_Segundos + 1;
        potCanal[i] = luz_anterior[i] + deltaLuz[i];
        if ( ( i == Luz_Luna - 2 ) && ( potCanal[i] <= 50 ) && ( potCanal[i] <= luz_anterior[i] ) ) potCanal[i] = 50;
        pwm_set_duty(potCanal[i], i );
        pwm_start(); // commit
        luz_anterior[i] = potCanal[i];
        }
     }
     Blynk.connect();
   }
  pwm_set_duty(potCanal[i], i );
  pwm_start(); // commit 
  luz_anterior[i] = potCanal[i];  
}

To add more weird behavior. The ESP with the new core just stopped working. This is the serial console output:

9:15
Nubes Intensas
Canal 1: 0
Canal 2: 0
Canal 3: 16
Canal 4: 0
-----------------
9:16
Nubes Intensas
Canal 1: 0
Canal 2: 0
Canal 3: 18
Canal 4: 0
-----------------

 ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset

The clone ESP installed on my aquarium is still running ok.

it’s not just stopped working:

actually got reseted by watchdog! this means that somewhere somehow there is a function with very long or infinite cycle. this makes the watchdog angry. pour that reset message -without the date- into google and see what it means.

now theoretically you’re one step closer to the problem.

the clone esp which is still runing, has the old core?