Arduino MKR1000 Lost signal after some hours

Hi guys, i’m still here to complete my big tranfer on blynk.cloud platform
Have a problem with my MKR1000, sketch looks correct, but after some hours (I do not know exactly) led orange on board blink and i lost signal, below my sketch:

#define BLYNK_TEMPLATE_ID "xxxxxxxxxxxxxxx"
#define BLYNK_DEVICE_NAME "xxxxxxx"
#define BLYNK_AUTH_TOKEN "xxxxxxxxxxxxxxxxxxxxxxxx"
#define BLYNK_PRINT SerialUSB
char auth[] = BLYNK_AUTH_TOKEN;

#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleWiFiShield101.h>
#include <TimeLib.h>
BlynkTimer timer;

char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxxxx";
int ledPin = 14;                // LED
int pirPin = 4;                 // PIR Movimento
int pirStat = 0;                   // PIR status
int statePir = LOW;
int pinSensore = 6;      //PIN A1 luminosità
int pinRele1 = 0;         //Relè accensione luce
int pinRele2 = 1;         //Relè accensione apertura box
int pinRele3 = 2;         //Relè accensione apertura cancello garage
int pinRele4 = 3;         //Relè disponibile
int sensorLight, var, varLight, pirSensor, varBox;
float duration, distance;
bool movimento = false;

const int sensorValue = 350;
#define TRIGPIN 8
#define ECHOPIN 7
unsigned long startMillis, currentMillis;

void setup()
{
  SerialUSB.begin(9600);
  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
  startMillis = millis();
  pinMode(ledPin, OUTPUT);
  pinMode(pinRele1, OUTPUT);
  pinMode(pinRele2, OUTPUT);
  pinMode(pinRele3, OUTPUT);
  pinMode(pinRele4, OUTPUT);
  digitalWrite(pinRele1, HIGH);
  digitalWrite(pinRele2, HIGH);
  digitalWrite(pinRele3, HIGH);
  digitalWrite(pinRele4, HIGH);
  digitalWrite(ledPin, HIGH);
  pinMode(pirPin, INPUT);
  pinMode(pinSensore, INPUT);
  timer.setInterval(1000L, controlli);
  //timer.setInterval(1000L, checkLight);
  //timer.setInterval(1000L, distanza);
}

void distanza() {
  digitalWrite(TRIGPIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIGPIN, HIGH);
  delayMicroseconds(20);
  digitalWrite(TRIGPIN, LOW);
  duration = pulseIn(ECHOPIN, HIGH);
  distance = (duration / 2) * 0.0343;
  Serial.print("DISTANZA: ");
  Serial.println(distance);
  //if (digitalRead(pirPin) == HIGH )
  //Serial.println("MOVIMENTO RILEVATO ");

}

void controlli() {
  // *****************AREA SENSORI*******************
  sensorLight = digitalRead(pinSensore); // verifica lo stato della luce
  Serial.print("Sensore: ");
  if (sensorLight == 1)
    Serial.println("LUCE SPENTA");
  else
    Serial.println("LUCE ACCESA");

  distanza();
  if (distance < 15 && distance >= 7) {
    //Serial.println("BOX IN APERTURA");
    varBox = 0;
  }
  if (distance < 7) {
    varBox = 1;
    Serial.println("BOX APERTO");
    if (sensorLight == 1) {
      digitalWrite(ledPin, LOW);
      luce();
    }
  }
}

//**************************************************************


void checkLight() { //***********RILEVAZIONE MOVIMENTO LUCE ACCESA A BOX****************
  if (sensorLight ==  0 && distance > 15 && varLight == 0) {  //rilevamento luce accesa e box chiuso
    if (movimento == false) {
      startMillis = millis();
      currentMillis = millis();
    }
    if (digitalRead(pirPin) == HIGH ) {
      startMillis = millis();
    }
    currentMillis = millis();      //aggiorna tempo corrente
    Serial.print("Tempo rimanente: ");
    Serial.println(10000 - (currentMillis - startMillis));
    if ((currentMillis - startMillis) > 10000)
    {
      digitalWrite(ledPin, HIGH);
      luce();
      movimento = false;
      varBox = 0;
    }
    movimento = true;
  }
  else movimento = false;
}

void checkBox() {

  if (distance < 7) {
    Serial.print("Checkbox");
    if (movimento == false) {
      startMillis = millis();
      currentMillis = millis();
    }
    if (digitalRead(pirPin) == HIGH ) {        //se viene rilevato un movimento
      Serial.print("Movimento rilevato");
      startMillis = millis();      // allinea il tempo corrente al tempo start
    }
    currentMillis = millis();      //aggiorna tempo corrente
    if ((currentMillis - startMillis) > 30000)  //test whether the period has elapsed
    {
      luce();
      digitalWrite(ledPin, HIGH);

      box129();
      movimento = false;
    }
    movimento = true;
  }
  else movimento = false;
}



// VOID PER ILLUMINAZIONE

void luce() {

  digitalWrite(pinRele1, LOW);
  timer.setTimeout(500L, []() {
    digitalWrite(pinRele1, HIGH);
  });
}

void lightOn() { // accensione luce quando il box si apre
  if (distance < 50 && sensorLight == 1) {
  }
}

// ***************VOID PER CANCELLI ******************

void box129() {
  digitalWrite(pinRele2, LOW);
  timer.setTimeout(1500L, []() {
    digitalWrite(pinRele2, HIGH);
  });
  Serial.println("BOX IN MOVIMENTO");
}

void garage() {
  Serial.println("CANCELLO IN MOVIMENTO");
  digitalWrite(pinRele3, LOW);
  timer.setTimeout(3000L, []() {
    digitalWrite(pinRele3, HIGH);
  });
  Serial.println("COMANDO APERTURA GARAGE");
}

//************ CONTROLLO BOX  ************************

void openBox() {
  if (distance > 15)
    box129();
  else Serial.println("OSTACOLO PRESENTE!");
}

void garBox() {
  garage();
  Serial.print("Tempo: ");
  currentMillis = millis();
  Serial.println(currentMillis);
  if ((currentMillis - startMillis) >= 5000) {
    openBox();
    startMillis = currentMillis;
  }
}


//*********** PULSANTI *****************************************
BLYNK_WRITE(V0) { // CANCELLO

  var = param.asInt();
  if (var == 0) garBox();
}

BLYNK_WRITE(V1) {   //BOX
  var = param.asInt();
  if (var == 1) openBox();
}

BLYNK_WRITE(V2) { // LUCE FISSA
  var = param.asInt();
  if (var == 1) {
    Serial.println("LUCE FISSA ATTIVA");
    varLight = 1;
    if (sensorLight ==  1) luce();
  }
  else {
    varLight = 0;
    Serial.println("LUCE FISSA DISATTIVA");
    luce();
  }
}

BLYNK_WRITE(V4) {   //BOX
  var = param.asInt();
  if (var == 0) digitalWrite(ledPin, LOW);
  else digitalWrite(ledPin, HIGH);
}

void loop() {
  Blynk.run();
  timer.run();
}

What Blynk library version are you using?
Why are you specifying the server url and port in your Blynk begin command?

Pete.

Blynk version is the last, i have 3 other board configured and work correctly.
ok now I edit Blynk.begin without ddns and port, could it depend on that?

A version number would be useful.

Pete.

Blynk Version 1.1.0

No, but seeing that in a sketch and not being provided with any information on Blynk library version number (despite it being one of the things that’s requested when you start a new “need help…” topic rings alarm bells.
If the old version of the library were being used then it would always try to connect to the Legacy cloud server. Specifying the new cloud server in the Blynk.begin command is a way around this, but can create other issues because the latest library version isn’t being used.

Now that you’ve confirmed that the latest version of the library is being used, that has eliminated that as a possible issue - assuming of course that you don’t have multiple versions of the library installed and the old one is being used by the compiler, but you’d see this in the compiler output as well as in the serial monitor as part of the Blynk logo.

I’m not familiar with the MKR hardware, so I’m out of ideas, other than suggesting that you ensure that your WiFi101 library is also up to date.

Pete.

the blinking yellow LED is unrelated to the problem. it is the battery mangement chip indicator saying there in no battery.

What do you mean by missing the battery? Before it was connected to blynk 1.0 and it worked. Mkr1000 has no battery

It has a battery connector…

so based on @Juraj’s comment I assume that the yellow flashing LED means that there is no battery connected to the Li-Po Battery connector.

Pete.

Ok, does this disconnect blynk cloud? Tomorrow I try to connect a battery

Pete.

The specifically orange LED flashes when disconnected from the cloud. I doubt it depends on the battery. Anyway I try

Battery purchased, installed, the orange light no longer lights up, but the disconnection remains! :confused:

Pete, do you propose me to change hardware? I need at least 9 pins, 8 digital and 1 analog. Is NodeMCU v.3 enough?

No. You’d need an ESP32 for that many useable pins.

I’ve never gone down the route of using the newest generation of Arduino boards.
I use the NodeMCU and ESP32 Dev Boards and they meet all of my needs. They also have the advantage of being cheap, popular with other Blynk users, and widely supported by software developers.
On paper the latest Arduino boards have significant advantages over the NodeMCU and ESP32 architectures, so I’d never say that people shouldn’t use them if that’s their preference.

As you can see though, it seems that there are very few people on this forum who actually understand the se boards in any detail. @Juraj is the obvious exception though.

I’m not saying either that switching to an ESP32 will fix your connection issues, because the problem may be caused by something that we aren’t aware of. However, fault-finding and isolating that problem may be easier with a larger pol of people who are familiar with your hardware.

Also, you need to listen to the advice that you’re given. You seemed to have hoped that buying a battery and adding it to your board would solve the connection problem, when it had been stated several times that this wasn’t relevant to your issue. I provided some suggestions that you’ve not fed-back on, so I have no idea if you’ve looked into and actioned.

Pete.

I repeat I have 3 other boards configured on the same pc and they have never had interruptions, this makes me think that my configuration is optimal, sorry but I missed some suggestions to which I have not answered. What are you referring to?

It was about ensuring that your library and board firmware is up to date.

Pete.