[ESP8266- Arduino Mega2560 Problems] Cmd error , Cmd Skipped:20

Hello,

I use Atmega2560 + ESP8266(12E) Combination, Before explain what I said here.

I spend 6months to solve this problem, I read relates article who face problem like me.

  1. Different Source Volatge ( Mega 5v , ESP8266 3.3v)
  2. Set the Logic Level converter between Mega2560 and ESP8266
  3. Using HardwareSerial (Mega use Serial1)
  4. Using cleary in loop()
    5.Using BlynkTimer to check connection and if disconnection in now i inser tried code to reconnection

Sometimtimees It is works well, But I face to problem which after 2days or 5days or 6hours, after random times. Mega2560 and ESP8266 not works.(Even I set the Blynk timer with softwarereset with 1 hour interval- this blynktimer “timeout” function not works. I think Something infinite loop running in Blynk functions).

I inspect with “#define BLYNK_DEBUG_ALL Serial”, I can find the problem. I can montoring this problem from serial monitor. Some blynk function hangs with inifite loop.

1.Serial monitor print first “Cmd error”. And they print “Cmd Skipped:20”.
2.Finally they print some characters infinitely.
3. this infinite printing hangs Atmega2560+ESP8266. I Monitoring this serial monitor, this print not ends.

My solution is,

  1. Find “Cmd error” parts in BlynkProtocol.h
  2. insert “wdt_enable(WDTO_60MS);”- software reset functions. I intend If Atmega2560 suffer any “Cmd error” problem, Reset MCU.

I think it is not best practice, but It looks seem like working well.
But I want not reset MCU. I want if I take “Cmd error”, I want disconnection and reconnection to blynk server. Does any people have a best practice?

Instead of trying to band aid a fix after an error message… why not prevent the error in the first place?

Just like many other shield users, your code is most likely trying to send too much, too fast, and/or overloading the Arduino (buffer memory?), thus causing the error.

Find the source and fix it.

1 Like

Yes, I inspect 2 origins which problem makes.

  1. Absolutley this problem caused when I push On/Off in my blynk app on smart phones.(Very fasts.)
  2. Seconds Even I not push On/Off buttons, Sometimes Hangs this parts.(After 2days, 4days, randomly.)

As you mentioned, I will trying solve to problem first caused. But I need best practice to solve problem hangs. Do you have any solution to Disconnection/Reconnection Blynk when suffer “Cmd error”, “Cmd skipped” without software reset?

Don’t press so fast :stuck_out_tongue_winking_eye: … or use virtual pins and code that prevents overly rapid action.

Arduinos are not as “robust” for IoT use, less memory is a particular issue and combined with the “translation” of the Serial to WiFi adapter is probably part of your longevity issue.

Use Blynk’s existing Connection Management commands as best able with “Arduino/ESP as shield” use and reconnect when able and reset as needed… And yes, resetting is probably your only response if the Arduino becomes overwhelmed.

As has been posted in other topics in this forum, i use this particular connection check re-connection method for my Mega w/ESP as shield. Works just fine and keeps background tasks running until a reconnection (or reset - I currently do not have that function anymore as it was unnecessary).

These are NOT drop in functions… they are requiring variable defines and basic understanding of how to write code. Read through them and test the commands with your own code and ideas as needed.

In setup…

  wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266
  Blynk.config(wifi, auth, server, port);
  if (Blynk.connectWiFi(ssid, pass)) {
    Blynk.connect();
  }

In loop…

void loop() {
  timer.run();  // Runs whether connected or not
  if (Blynk.connected()) {  // If connected run as normal
    Blynk.run();
  } else if (ReCnctFlag == 0) {  // If NOT connected and not already trying to reconnect, set timer to try to reconnect in 30 seconds
    ReCnctFlag = 1;  // Set reconnection Flag
    Serial.println("Starting reconnection timer in 30 seconds...");
    timer.setTimeout(30000L, []() {  // Lambda Reconnection Timer Function
      ReCnctFlag = 0;  // Reset reconnection Flag
      ReCnctCount++;  // Increment reconnection Counter
      Serial.print("Attempting reconnection #");
      Serial.println(ReCnctCount);
      wifi.setDHCP(1, 1, 1); //Enable dhcp in station mode and save in flash of esp8266
      Blynk.config(wifi, auth, server, port);
      Blynk.connect();  // Try to reconnect to the server
      if (Blynk.connectWiFi(ssid, pass)) {
        Blynk.connect();
      }
    });  // END Timer Function
  }
}
1 Like