Cmd errors and reconnects Running blynk on Esp32 in a task (via GSM)

Hi,

I am just starting with Blynk and am implementing it in an existing project that uses a sim7000 GSM.
This project runs multiple tasks (all on core 1) and I have implemented Blynk to also to run in a task (on core 0) so all can run more or less in “parallel”.

The code is event based (like Blynk gets a notification when another object wants to send a message) but there are some processor time heavy components…

Problems I am having are cmd errors (and thus reconnects).

I am trying to play with the following defines to make sure other tasks also get processor time and blynk is not starved (but to be honest I am not exactly aware if these defines have the result I am looking for):

#define TINY_GSM_YIELD_MS 1
#define BLYNK_RUN_YIELD() { delay(1);}
#define BLYNK_SEND_CHUNK 64
#define BLYNK_SEND_THROTTLE 20

I first initialize blynk, then the task is started which runs the blynk.update and processes messages that need to be sent (which are queued).

Below the code parts I use related to blynk and some logs.

Hope anybody can point me in the right direction and help troubleshoot/tweak this.

thx!

void BlynkNodeSim7000::initialize() {
  restartModem();
  Blynk.begin(auth, *gsmGps, gprsApn, gprsUser, gprsPw, "blynk.cloud", 80);
  blynkQueue = xQueueCreate(10, sizeof(blynkMsg));

  blynkTask.resumeTask();

  esp_reset_reason_t reason = esp_reset_reason();
  queueVpinCharMsg(254, GetESPResetReason(reason).c_str());
  queueVpinIntMsg(255, reason);

  sensorActive = true;
}

bool BlynkNodeSim7000::restartModem() {
  
  //TODO what if init starts, then it will never come up
  if (!gsmGps->restart()) {
    if (!gsmGps->init()) {
      log_w("Failed to (re-)start an init modem");
      return 0;
    }
  }
  return 1;
}

void BlynkNodeSim7000::update() {
  Blynk.run();
}

void BlynkNodeSim7000::virtualWrite(uint8_t vPin, char* value) {
  Blynk.virtualWrite(vPin, value);
  // log_d("vw %s", value);
}

void BlynkNodeSim7000::notification(Sense::IObservable* obs) {
  Sense::INode* node = obs->getValueObject();
  blynkMsg msg;
  msg.vPin = obs->getId();
  node->getReadableValue(msg.value, 30);

  xQueueSend(blynkQueue, &msg, 100);
}

void BlynkNodeSim7000::queueVpinIntMsg(uint8_t vPin, uint8_t value) {
  blynkMsg msg;
  msg.vPin = vPin;
  sprintf(msg.value, "%d", value);
  xQueueSend(blynkQueue, &msg, 100);
}

void BlynkNodeSim7000::queueVpinFloatMsg(uint8_t vPin, float value) {
  blynkMsg msg;
  msg.vPin = vPin;
  sprintf(msg.value, "%f", value);
  xQueueSend(blynkQueue, &msg, 100);
}

void BlynkNodeSim7000::queueVpinCharMsg(uint8_t vPin, const char value[]) {
  blynkMsg msg;
  msg.vPin = vPin;
  memcpy(msg.value, value, 30);
  xQueueSend(blynkQueue, &msg, 100);
}

void blynkControllTask(void* pvParameters) {
  BlynkNodeSim7000* BlynkNodeSim7000Obj = reinterpret_cast<BlynkNodeSim7000*>(pvParameters);
  struct blynkMsg {
    uint16_t vPin = 0;
    char value[30];
  };
  blynkMsg msg;

  BlynkNodeSim7000Obj->update();

  if (Blynk.connected() && xQueueReceive(BlynkNodeSim7000Obj->blynkQueue, &msg, ( TickType_t ) 0 ) ) {
    BlynkNodeSim7000Obj->virtualWrite(msg.vPin, msg.value);
  }
  delay(10);
}

Logs:

[D][TaskUtils.cpp:26] internalTask(): Creating Task [blynkTask] (suspended)
[D][TaskUtils.cpp:42] internalTask(): Task [blynkTask] suspended
[11872] 
___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
    /___/ v1.0.1 on ESP32

[D][BlynkGsmClient.h:113] begin(): begin
[11977] Connecting to network...
[12023] Network: vodafone NL 1nce.net
[12023] Connecting to iot.1nce.net ...
[16224] Connected to GPRS
[16253] Connecting to blynk.cloud:80
[17004] <[1D|00|01|00] xxxxxxxxxxxxxxxxxxxxxxxx
[17427] >[00|00|01|00|C8]
[17427] Ready (ping: 374ms).
[17497] <[11|00|02|00]Rver[00]1.0.1[00]h-beat[00]60[00]buff-in[00]1024[00]dev[00]ESP32[00]con[00]TinyGSM[00]buil
[17548] <d[00]Dec  9 2021 14:49:48[00]
[D][TaskUtils.cpp:84] resumeTask(): Task [blynkTask] resumed
[17664] <[14|00|03|00|12]vw[00]254[00]ESP_RST_WDT
[17777] <[14|00|04|00|08]vw[00]255[00]7
[17898] >[00|00|02|00|C8]
[52789] <[14|00|05|00|09]vw[00]120[00]02
[62497] <[14|00|06|00|09]vw[00]120[00]32
[70008] <[14|00|07|00|09]vw[00]120[00]02
[77909] <[06|00|08|00|00]
[78169] >[00|00|08|00|C8]
[131302] <[14|00|09|00|09]vw[00]120[00]01
[138181] <[06|00|0A|00|00]
[138464] >[00|00|0A|00|C8]
[198274] <[06|00|0B|00|00]
[199302] Cmd error
[203294] Connecting to blynk.cloud:80
[203543] <[1D|00|01|00] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[203738] >[00|00|01|00|C8]
[203739] Ready (ping: 149ms).
[203807] <[11|00|02|00]Rver[00]1.0.1[00]h-beat[00]60[00]buff-in[00]1024[00]dev[00]ESP32[00]con[00]TinyGSM[00]buil
[203855] <d[00]Dec  9 2021 14:49:48[00]
[204115] >[00|00|02|00|C8]
[263952] <[06|00|03|00|00]
[264966] >[00|00|03|00|C8]
[324804] <[06|00|04|00|00]
[325715] >[00|00|04|00|C8]
[385553] <[06|00|05|00|00]
[386595] >[00|00|05|00|C8]
[446404] <[06|00|06|00|00]
[447319] >[00|00|06|00|C8]
[507157] <[06|00|07|00|00]
[508163] >[00|00|07|00|C8]
[508165] <[14|00|08|00|09]vw[00]120[00]02
[518329] <[14|00|09|00|09]vw[00]120[00]32
[535759] <[14|00|0A|00|09]vw[00]120[00]02
[536788] Cmd error
[539824] Connecting to blynk.cloud:80
[540581] <[1D|00|01|00] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[540872] >[00|00|01|00|C8]
[540873] Ready (ping: 246ms).
[540941] <[11|00|02|00]Rver[00]1.0.1[00]h-beat[00]60[00]buff-in[00]1024[00]dev[00]ESP32[00]con[00]TinyGSM[00]buil
[540989] <d[00]Dec  9 2021 14:49:48[00]
[541262] >[00|00|02|00|C8]
[597035] <[14|00|03|00|09]vw[00]120[00]01
[598064] Cmd error
[601098] Connecting to blynk.cloud:80
[602782] <[1D|00|01|00] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[603358] >[00|00|01|00|C8]
[603359] Ready (ping: 531ms).
[603427] <[11|00|02|00]Rver[00]1.0.1[00]h-beat[00]60[00]buff-in[00]1024[00]dev[00]ESP32[00]con[00]TinyGSM[00]buil
[603475] <d[00]Dec  9 2021 14:49:48[00]
[604265] >[00|00|02|00|C8]
[663527] <[06|00|03|00|00]
[664555] Cmd error
[668546] Connecting to blynk.cloud:80
[671644] <[1D|00|01|00] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[672112] >[00|00|01|00|C8]
[672113] Ready (ping: 423ms).
[672181] <[11|00|02|00]Rver[00]1.0.1[00]h-beat[00]60[00]buff-in[00]1024[00]dev[00]ESP32[00]con[00]TinyGSM[00]buil
[672229] <d[00]Dec  9 2021 14:49:48[00]
[672812] >[00|00|02|00|C8]
[732277] <[06|00|03|00|00]
[733346] >[00|00|03|00|C8]
[793029] <[06|00|04|00|00]
[794057] Cmd error
[798099] Connecting to blynk.cloud:80
[803752] <[1D|00|01|00] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[806162] >[00|00|01|00|C8]
[806163] Ready (ping: 2365ms).
[806291] <[11|00|02|00]Rver[00]1.0.1[00]h-beat[00]60[00]buff-in[00]1024[00]dev[00]ESP32[00]con[00]TinyGSM[00]buil
[806339] <d[00]Dec  9 2021 14:49:48[00]
[806949] >[00|00|02|00|C8]

as maybe a good addition for troubleshooting

when I get this cmd error logging:

[158113] <[14|00|04|00|09]vw[00]120[00]02
[159141] Cmd error
[162175] Connecting to blynk.cloud:80
[163408] <[1D|00|01|00] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[163727] >[00|00|01|00|C8]
[163727] Ready (ping: 273ms).
[163728] Waiting:65

I do see the data coming in on the dashboard so data seems to be sent successfully but there is no response? Should there be a response? Or is this automatically retried?

@i-connect
Check this thread as it will answer some of your quuestions
https://community.blynk.cc/t/server-success-response-to-field-device-upython/57966

You are writing to a virtual PIN, 120 in this case, have you checked that this is the correct one on the app / platform?

@SmsAlert yes this is the correct pin and I can see data coming in as well.

you appear to be doing a “virtual write”, so change the data stream type to a “virtual write” data stream.
image

image

ha, well spotted!

But it seems in view mode it does not show the “V”

this is the screen when I am in edit mode

this is in the main template screen

and in the individual pin view mode

You are correct… Maybe a suggestion moving forward on the Blynk Team side to keep the “applicated pins” with the correct value.

Thanks i-connect and SmsAlert !
Added this “Vpin/pin” bug to our bug tracker so we’ll fix it soon.

2 Likes

Perfect, thanks

Can we close this thread as “solved”

Is @i-connect‘a original reported issue actually resolved?

Pete.

Not sure, I had it running for a couple of days and had way less reconnects, maybe it is caused by a bad GPRS connection, I will do some further testing (also in other locations).

But if there are suggestions for the define values for running the setup like I do (running Blynk in a task in an environment with multiple tasks and via GPRS connection) they are very welcome.