Blynk connection fails, packet to big

Hi all,
need some help, I’m struggling with Fishino-Blynk connection. Basically the project is simple, writing-reading virtual PINs to get from the APP to switch on/off items and related timer interval.
Typically I get a recurring Connecting to blynk-cloud.com:80 with some errors Packet too big: 55309 and Bad hdr len: 5 with no chance to have “blynk connected”.

• Hardware model + communication type. Fishino UNO (like Arduino UNO+WiFi)
• Smartphone: Android
• Blynk server: Cloud
• Blynk Library version: 0.6.1
• Tryed WIFI and Mobile Hot Spot … same awful result.

Any suggestion?

Thanks a lot!

=======

Here is the sketch code:


  /*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
 *************************************************************/

// Debugging switches and macros
#define DEBUG 1 // Switch debug output 1=on, 0=off

#if DEBUG

#define PRINTS(s)           { Serial.print(F(s)); }
#define PRINTSLN(s)         { Serial.print(F(s));  Serial.print("\n"); }
#define PRINTV(v)           { Serial.print(v); }
#define PRINTVLN(v)         { Serial.print(v);     Serial.print("\n"); }
#define PRINTSV(s,v)        { Serial.print(F(s));  Serial.print(v); }
#define PRINTSVLN(s,v)      { Serial.print(F(s));  Serial.print(v);    Serial.print("\n");  }
#define BLYNK_PRINT Serial  /* Comment this out to disable prints and save space */
#define BLYNK_DEBUG
#define BLYNK_NO_BUILTIN   // Disable built-in analog & digital pin operations
#define BLYNK_NO_FLOAT     // Disable float on blynk
#else

#define PRINTS(s)
#define PRINTSLN(s)
#define PRINTV(v)
#define PRINTVLN(v)
#define PRINTSV(s,v)
#define PRINTSVLN(s,v)
#define BLYNK_NO_BUILTIN   // Disable built-in analog & digital pin operations
#define BLYNK_NO_FLOAT     // Disable float on blynk

#endif

//DEFINES REPLACEMENTS ==============================
#define BAUD_RATE 9600 


//INCLUDE ==========================================
#include <SPI.h>                  //required by Blynk
#include <Fishino.h>              //requred by Fishino HAL
#include <BlynkSimpleFishino.h>   //blynk
#include <WidgetRTC.h>            //time server blynk
#include <RTClib.h>               //Fishino RTC clock

//WIFI MODULE PARAMETERS ===========================
char MY_SSID[] = "****";
char MY_PASS[] = "*****";


//BLINK VALUES PARAMETERS ===========================
char BLINK_TOKEN[] ="*****";

//RTC DEF ==========================================
//RTC_DS1307 rtc;
char sDtLong[]="2000-12-31 12:12:12";
char sDtShort_DD_MMM_HH_MM[]="01-Gen 12:12";
WidgetRTC rtcServer;  

//BLINK TIMER DEF ===========================
BlynkTimer timer;
boolean isFirstConnect = true;

//EVENT MANAGEMENT
// This function Get Env Data from sensors and sends Arduino's data to Blink.

void FireEvent_GetEnvData_Temperature()
{

    if (1 == 0) {  //commented 
      PRINTSLN("** Temp sensors not connected! **");
      Blynk.virtualWrite(V5, "Temp sensors not connected!");
      Blynk.notify("Temp sensors not connected!");
    } else {
      //read temp
      Blynk.virtualWrite(V0, "temp_water");
      Blynk.virtualWrite(V1, "temp_out");
    }
    

}

void FireEvent_GetEnvData_PH()
{
    //read PH
    double  flPH=6.5;
    PRINTSVLN(" PH  : ",flPH);
    Blynk.virtualWrite(V6, String(flPH));
}

#define INTERVAL_VALUE_LENGTH 14

int iLCDBacklightOnOff = 0;

int iLightsMainEnabled = 0;
int iLightsMainOnOff   = 0;
String sLightsMainOnPeriod;

int  iLightsSecEnabled = 0;
int  iLightsSecOnOff   = 0;
String sLightsSecOnPeriod;

int  iCO2Enabled       = 0;
int  iCO2OnOff         = 0;
String sCO2OnPeriod;

int  iO2Enabled        = 0;
int  iO2OnOff          = 0;
String sO2OnPeriod;

int  iDaysToMaint      = 14;
int  iMaintRefPer      = 14;

String SetTimeInput(TimeInputParam lParam,String sItemText, String sPinText) {

  char cOnPeriod[INTERVAL_VALUE_LENGTH] ;
  if (lParam.hasStartTime() && lParam.hasStopTime())
  {
    sprintf(cOnPeriod, "%02d:%02d - %02d:%02d", lParam.getStartHour(), lParam.getStartMinute(), lParam.getStopHour(), lParam.getStopMinute() );
  }
  else
  {
    sprintf(cOnPeriod , "--:-- - --:--");
  }
  sPinText=String(sPinText+" APP value is: "+String(cOnPeriod));
  sItemText=String(sItemText+": interval set");
  PRINTVLN(sItemText);
  if (!isFirstConnect)
    Blynk.virtualWrite(V5, sItemText);
  return String(cOnPeriod);
}

int SetOnOff(int iSwitchOnOff,String sItemText, String sPinText, String sOptionaltext) {
  sPinText=String(sPinText+" APP value is: "+String(iSwitchOnOff));
  PRINTVLN(sPinText);
  if (iSwitchOnOff==0) {
    sItemText=String(sItemText+": "+sOptionaltext+" off");
  }
  else {
    sItemText=String(sItemText+": "+sOptionaltext+" on");
  }
  Blynk.virtualWrite(V5, sItemText);

}

BLYNK_WRITE(V9)
{

iLCDBacklightOnOff = SetOnOff(param.asInt(),"Luce LCD","V9",""); 
  if (iLCDBacklightOnOff==0) {
    //lcd.backlight();
  }
  else {
    //lcd.noBacklight();
  }
}

BLYNK_WRITE(V10)
{
  iLightsMainOnOff = SetOnOff(param.asInt(),"Main lights","V10",""); 
}

BLYNK_WRITE(V11)
{
  sLightsMainOnPeriod = SetTimeInput(param,"Main lights", "V11");
}

BLYNK_WRITE(V12)
{
  iLightsMainEnabled = SetOnOff(param.asInt(),"Main lights","V12","timer "); 
}

BLYNK_WRITE(V13)
{
  iLightsSecOnOff = SetOnOff(param.asInt(),"Secondary Lights","V13",""); 
}

BLYNK_WRITE(V14)
{
  sLightsSecOnPeriod = SetTimeInput(param,"Secondary Lights", "V14");
}

BLYNK_WRITE(V15)
{
  iLightsSecEnabled  = SetOnOff(param.asInt(),"Secondary Lights","V15","timer "); 
}

BLYNK_WRITE(V16)
{
  iCO2OnOff = SetOnOff(param.asInt(),"C02","V16",""); 
}

BLYNK_WRITE(V17)
{
  sCO2OnPeriod = SetTimeInput(param,"C02", "V17");
}

BLYNK_WRITE(V18)
{
  iCO2Enabled  = SetOnOff(param.asInt(),"C02","V18","timer "); 
}

BLYNK_WRITE(V19)
{
  iO2OnOff = SetOnOff(param.asInt(),"Air","V19",""); 
}

BLYNK_WRITE(V20)
{
  sO2OnPeriod = SetTimeInput(param,"Air", "V20");
}

BLYNK_WRITE(V21)
{
  iO2Enabled  = SetOnOff(param.asInt(),"Air","V21","timer "); 
}

BLYNK_CONNECTED() {
  if (isFirstConnect) {
    Blynk.virtualWrite(V5, "Get settings!");
    delay(1000*DEBUG);
    Blynk.syncAll();
  isFirstConnect = false;
  }
  Blynk.virtualWrite(V5, "Resync completed!");
  delay(1000*DEBUG);

}

// SETUP FUNCTION ==========================================================================================================================================================================
boolean ReconnectWiFiBlynk() {

  // test conncection status
  uint8_t stat = Fishino.status();
  if(stat != WL_CONNECTED) {
    uint32_t connecTime = millis();
    uint32_t iRetryTimeOut = 30 * 1000;
    while(millis() - connecTime  < iRetryTimeOut)
    {
      PRINTSLN("Fishino connecting WiFi...");
      if(Fishino.begin(MY_SSID, MY_PASS)) {
        PRINTSLN("Wifi connected, trying to connect blynk..."); 
        if (ReconnectBlynk()) {
          PRINTSLN("Blynk connected!");
        } else {
          PRINTSLN("Blynk not connected, will retry later!");  
        }
        break;
      } else { 
        PRINTS("."); 
      }
    }
  }
}

boolean ReconnectBlynk() {

  if(!Blynk.connected()) {
    uint32_t connecTime = millis();
    uint32_t iRetryTimeOut = 30 * 1000;
    PRINTSLN("Blynk trying to connect...");
    Blynk.disconnect();
    Blynk.config(BLINK_TOKEN);
    while(millis() - connecTime  < iRetryTimeOut)
    {
      while (Blynk.connect() == false) { PRINTS("."); };
      if(Blynk.connected()) {
        PRINTSLN("Blynk connected!"); 
        return(true);
        break;
      } else { 
        PRINTS("."); 
      }
    }
  }
}

void setup()
{

// Debug console ******************************************************
#if DEBUG
  Serial.begin(BAUD_RATE);
  PRINTSVLN("\nDEBUG on serial @",BAUD_RATE);

// Fishino's data ******************************************************
  PRINTSLN("Starting Fishino...");
  PRINTSVLN(" - Firmware version : ",Fishino.firmwareVersionStr());
  PRINTSVLN(" - Free RAM: ",Fishino.freeRam());
#endif

  //initialize WIFI and BLINK ***************************************************
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  if(Fishino.reset()) {
    PRINTSLN("Fishino WiFi reset ok");
  } else {
    PRINTSLN("Fishino WiFi reset failed");
   }
  
  //connect wifi and blyink
  if (ReconnectWiFiBlynk()) {
      Blynk.virtualWrite(V5, "AQUABlynk connected!");
      delay(500+1000*DEBUG);
  }
  else
  {
    PRINTSLN("Connection failed, will retry later!");
  }
  timer.setInterval(60000L, ReconnectWiFiBlynk);  // check every minute if still connected to server

  //initialize RTC ******************************************************
  PRINTSLN("RTC...");
  // Time widgetRTC synch interval with Blynk server
  setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)
  //fishino RTC start
  //rtc.begin();
  //if (!rtc.isrunning())
  //  rtc.adjust(DateTime(year(), month(), day(), hour(), minute(), second())); // <----------------------SET TIME AND DATE: YYYY,MM,DD,HH,MM,SS , year,month, ... get from widgetRTC

  sprintf(sDtLong, "[%04d-%02d-%02d %02d:%02d:%02d]", year(),month(),day(),hour(),minute(),second());
#if DEBUG
  PRINTSV    (" - ",sDtLong);
  PRINTSLN  (" OK!");
#endif 
  Blynk.virtualWrite(V5, "RTC: " + String(sDtLong));
  delay(1000*DEBUG);
  //initialize sensors *******************************************************

  timer.setInterval(  10000L, FireEvent_GetEnvData_Temperature);    //10sec dev
  timer.setInterval(  10000L, FireEvent_GetEnvData_PH);             //10sec dev
  Blynk.virtualWrite(V5, "Timer impostati!");
  delay(1000*DEBUG);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}
    

Debug output:

22:06:41.774 -> DEBUG on serial @9600
22:06:41.774 -> Starting Fishino...
22:06:41.806 ->  - Firmware version : 7.5.2
22:06:41.840 ->  - Free RAM: 405
22:06:42.215 -> Fishino WiFi reset ok
22:06:42.215 -> Fishino connecting WiFi...
22:06:42.521 -> Wifi connected, trying to connect blynk...
22:06:42.556 -> Blynk trying to connect...
22:06:42.590 -> [753] Disconnected
22:06:42.590 -> [774] 
22:06:42.623 ->     ___  __          __
22:06:42.623 ->    / _ )/ /_ _____  / /__
22:06:42.658 ->   / _  / / // / _ \/  '_/
22:06:42.693 ->  /____/_/\_, /_//_/_/\_\
22:06:42.726 ->         /___/ v0.6.1 on Arduino Uno
22:06:42.761 -> 
22:06:42.761 -> [932] **Connecting to blynk-cloud.com:80**
22:06:49.092 -> [7329] **Connecting to blynk-cloud.com:80**
22:06:56.104 -> .[14329] **Connecting to blynk-cloud.com:80**
22:06:57.188 -> [15406] <[1D|00|01|00] 
22:06:57.188 -> [15408] <**TOKEN**
22:06:57.289 -> [15522] >[00|00|01|00|C8]
22:06:57.289 -> [15523] Ready (ping: 58ms).
22:06:57.323 -> [15523] Free RAM: 316
22:06:57.357 -> [15547] >[CA|14]c[D8|0D]
22:06:57.391 -> [15565] Packet too big: 55309
22:06:57.425 -> [15597] <[11|00|02|00]f
22:06:57.459 -> [15624] <ver[00]0.6.1[00]h-beat[00]10[00]buff-in[00]256[00]dev[00]Arduino Uno[00]cpu[00]ATmega328P[00]con[00]Fishino[00]build[00]May  3 2020 19:19:25[00]
22:06:57.594 -> [15784] Sent 0/107
22:07:02.312 -> [20524] **Connecting to blynk-cloud.com:80**
22:07:02.414 -> [20631] <[1D|00|01|00] 
22:07:02.414 -> [20632] <**TOKEN**
22:07:02.515 -> [20732] >[00|00|01|00|C8]
22:07:02.515 -> [20732] Ready (ping: 53ms).
22:07:02.550 -> [20733] Free RAM: 288
22:07:02.583 -> [20799] <[11|00|02|00]f
22:07:02.617 -> [20801] <ver[00]0.6.1[00]h-beat[00]10[00]buff-in[00]256[00]dev[00]Arduino Uno[00]cpu[00]ATmega328P[00]con[00]Fishino[00]build[00]May  3 2020 19:19:25[00]
22:07:02.753 -> [20935] Sent 0/107
22:07:05.092 -> .[25733] **Connecting to blynk-cloud.com:80**
22:07:07.604 -> [25823] <[1D|00|01|00] 
22:07:07.604 -> [25824] <**TOKEN**
22:07:07.775 -> [25996] >[00|00|01|00|C8]
22:07:07.775 -> [25996] Ready (ping: 71ms).
22:07:07.809 -> [25997] Free RAM: 260
22:07:07.842 -> [26012] >0[00|00|11|00]
22:07:07.875 -> [26037] Bad hdr len: 5
22:07:07.908 -> [26063] <[11|00|02|00]f
22:07:07.908 -> [26088] <ver[00]0.6.1[00]h-beat[00]10[00]buff-in[00]256[00]dev[00]Arduino Uno[00]cpu[00]ATmega328P[00]con[00]Fishino[00]build[00]May  3 2020 19:19:25[00]
22:07:08.080 -> [26249] Sent 0/107
22:07:12.850 -> [31062] **Connecting to blynk-cloud.com:80**
22:07:12.917 -> [31149] <[1D|00|01|00] 
22:07:12.917 -> [31151] <**TOKEN**

I’ve solved correcting the connect functions

boolean ReconnectWiFiBlynk() {

  // controlla se connesso
  uint8_t stat = Fishino.status();
  // se non connesso, tenta la riconnessione
  if(stat != WL_CONNECTED) {
    uint32_t connecTime = millis();
    uint32_t iRetryTimeOut = 30 * 1000;
    PRINTS("Fishino connecting WiFi...");
    while(millis() - connecTime  < iRetryTimeOut)
    {
      PRINTSLN(".");
      if(Fishino.begin((char*)MY_SSID, (char*)MY_PASS)) {
        PRINTSLN("Wifi connected, trying to connect blynk..."); 
        if (ReconnectBlynk()) {
          PRINTSLN("Blynk connected!");
          return(true);
        } else {
          PRINTSLN("Blynk not connected, will retry later!");  
        }
      } else { 
        PRINTSLN("+"); 
      }
    }
  } else {
    if (ReconnectBlynk()) {
      PRINTSLN("Blynk already connected!");
      return(true);
    } else {
      PRINTSLN("Blynk lost connection, will retry later!");  
    }

  }
  return(false);
}

boolean ReconnectBlynk() {

  if(!Blynk.connected()) {
    uint32_t connecTime = millis();
    uint32_t iRetryTimeOut = 30 * 1000;
    PRINTSLN("Blynk reset...");
    Blynk.disconnect();
    PRINTSLN("Blynk configure...");
    Blynk.config((char*)BLINK_TOKEN);
    PRINTSLN("Blynk connect...");
    while(millis() - connecTime  < iRetryTimeOut)
    {
      while (!Blynk.connect()) { PRINTS("@"); };
      if(Blynk.connected()) {
        return(true);
      } else { 
        PRINTS("#"); 
      }
    }
    return(false);
  } else {
    return(true);
  }
}

Now it’s stable. I’ve added a timer to check the blynk connection

 timer.setInterval(  10000L, ReconnectWiFiBlynk);                    // check every minute if still connected to server

Seldom I got this error: Timeout (3001 mSec) – sending out-of-sync to slave

.....omissis......
22:35:27.889 -> V12 APP value is: 0
22:35:30.973 -> ERROR:Timeout (3001 mSec) -- sending out-of-sync to slave
22:35:30.973 -> ERROR:Sending out of sync to slave
22:35:31.007 -> ERROR:write16() error
22:35:37.937 -> [845811] Connecting to blynk-cloud.com:80
22:35:37.971 -> Blynk reset...
22:35:38.006 -> [845892] Disconnected
22:35:38.006 -> Blynk configure...
22:35:38.039 -> [845893] 
22:35:38.039 ->     ___  __          __
22:35:38.073 ->    / _ )/ /_ _____  / /__
22:35:38.117 ->   / _  / / // / _ \/  '_/
22:35:38.143 ->  /____/_/\_, /_//_/_/\_\
22:35:38.143 ->         /___/ v0.6.1 on Arduino Uno
22:35:38.212 -> 
22:35:38.212 -> Blynk connect...
22:35:38.212 -> [846048] Connecting to blynk-cloud.com:80
22:35:38.313 -> [846187] Ready (ping: 50ms).
22:35:39.545 -> Blynk already connected!

Suggestions?

Thanks