Blynk reconnection fail using MKR NB 1500 (with hologram SIM)

Hi Guys,
I am experiencing troobles with reconnection using Blynk on my device.
Everything works fine on first powering up but if connection is lost, device never succeed again to connect with server (for example i tried with a metal box to block RF)
→ in this case, serial debugs shows “Connecting to lon1.blynk.cloud:80” but stay like this forever
Can you help please ?
Best


• MKRNB 1500 + GPS, Hologram SIM CARD
• Blynk server region : EUROPE (France, Paris)
• Blynk Library version 1.3.2

:warning: If you don’t format your code, your topic can be deleted by moderators.

Here is a correct example of code formatting:

#include <Arduino_MKRGPS.h>
#include <MKRNB.h>

#define BLYNK_PRINT               Serial
#define BLYNK_TEMPLATE_ID        BLABLA
#define BLYNK_TEMPLATE_NAME       BLABLA
#define BLYNK_AUTH_TOKEN         BLABLA
#define ANALOG_UPDATE             10000      
#define GNSS_TIMEOUT              30000
#define BUTTON                    0 
#define DEBOUNCE_SHORT            100

#include <BlynkSimpleMKRNB.h> 
#include <TimeLib.h>
#include <WidgetRTC.h>

NBClient client;
GPRS gprs;
NB nbAccess;
BlynkTimer timer;
WidgetRTC rtc;
 
// Your SIM credential
// Leave empty, if missing pin
char            pin[]  = "";
const int       buttonPin     = 0;  // the number of the pushbutton pin
int             buttonState   = 0;  // variable for reading the pushbutton status
double          latitude      = 48.866667; // default value is Paris, France position
double          longitude     = 2.333333;  // default value is Paris, France position
double          altitude      = 0;
double          speed         = 0;
int             satellites    = 0;
unsigned long   uTimeCur      = 0;  // Variable for Periodick actions
unsigned long   uTimeGnss     = 0;  // Variable for Periodick actions
float           fVbat         = 0;
float           fVusb         = 0;
int             iBQpwr        = 0;
int             iBQchg        = 0;
long            t             = 0;
int             iGnss         = 0;
int             iTotDoses     = 0;
int             iMinDoses     = 0;   
unsigned long   SWTime        = 0;  // the last time the output pin was toggled
bool            SWstate       = false;  // the previous reading from the input pin
int             SWdebounce    = 0;  // the previous reading from the input pin
int             SWstateLast   = 1;  // the previous reading from the input pin    
//////////////////////////////////////////////////////////////////////////////////////

void clockDisplay()
  {
  Serial.print(" Gnss Stat: ");
  Serial.print(iGnss); 
  bool result = Blynk.connected();
  if(result == true) 
    {
    Serial.println(" blynk server over LTE com connected");
    }
  else               
    {
    Serial.println(" blynk server over LTE com disconnected");
    }
  //
  Blynk.virtualWrite(V1, longitude, latitude);
  Blynk.virtualWrite(V2, iBQpwr);
  Blynk.virtualWrite(V3, fVbat);
  Blynk.virtualWrite(V4, iGnss);
  Blynk.virtualWrite(V5, iTotDoses);
  Blynk.virtualWrite(V6, iMinDoses);
  iMinDoses = 0;
  }

BLYNK_CONNECTED() 
  {
  rtc.begin();
  }


//////////////////////////////////////////////////////////////////////////////////////

void setup()
  {
  // Debug console
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(BUTTON, INPUT);
  pinMode(A4, INPUT);
  // If you are using the MKR GPS as shield, change the next line to pass
  // the GPS_MODE_SHIELD parameter to the GPS.begin(...)
  if (!GPS.begin()) 
    {
    Serial.println("GNSS_Stat=FAILED"); 
    iGnss = -1;
    while (1);
    }
  Blynk.begin(BLYNK_AUTH_TOKEN, nbAccess, gprs, client, pin, "lon1.blynk.cloud", 80);
   // Setup a function to be called every second
  timer.setInterval(10000L, clockDisplay);
  Serial.println("Gnss initialized");   
  iGnss = 0;
  uTimeCur  = millis();
  SWTime    = millis();
  }

//////////////////////////////////////////////////////////////////////////////////////
void loop() {
  // check if there is new GPS data available
  int SW = digitalRead(BUTTON);
  IsButtonPressed(SW);

  if (GPS.available()) 
    {
    iGnss = 1;
    uTimeGnss = millis();
    latitude   = GPS.latitude();
    longitude  = GPS.longitude();
    altitude   = GPS.altitude();
    speed      = GPS.speed();
    satellites = GPS.satellites();
    }
  else if((millis() - uTimeGnss) > GNSS_TIMEOUT)
    {
    iGnss = 0; 
    }
  else{}

  // refresh HMI
  if((millis() - uTimeCur) > ANALOG_UPDATE)
    {
    uTimeCur = millis();
    fVbat = (analogRead(A2)) * (3.3 / 1023.0) * 2;
    fVusb = (analogRead(A0)) * (3.3 / 1023.0) * 2;
    if (digitalRead(A4) == HIGH)    {iBQchg = 1;}
    else                            {iBQchg = 0;}    
    if(fVusb > 4.5)                 {iBQpwr = 1;}
    else                            {iBQpwr = 0;}
    }

Blynk.run();
timer.run(); // Initiates BlynkTimer
}

void IsButtonPressed(int SW)                                                                   // Debounce function for left button
    {
    if((SW == 1) && ((millis() - SWTime) > DEBOUNCE_SHORT))
        {
        if(SWstateLast == 1) // In case you just pressed the button
          {
          SWstateLast = 0;
          iTotDoses++;
          iMinDoses++;   
          Serial.print("iTotDoses: ");
          Serial.print(iTotDoses);
          Serial.print(" , iMinDoses: ");
          Serial.println(iMinDoses);  
          }
        else {}
        }
      else
        {
        if(SWstateLast == 0) // In case you just released the button
          {
          SWstateLast = 1; 
          if (SWstate == false)    SWstate = true;
          else                      SWstate = false;
          SWTime = millis();
          }
        else {}
        }
    return;
    }

Is your server Fra1 (Frankfurt) or Lon1 (London) ?
You can see this info in the About section of the app, or bottom right hand corner of the web console.

There’s quite a bit of weird/inappropriate stuff in your sketch, but not necessarily anything that will affect reconnection.

Pete.

HI Pete,

Thanks for you help it is : lon1

Best