Infinite loop trying to connect to wifi network

Hi,

I'm triying to connect to my wifi, but I don't know why, sometimes the arduino could not connect (meanwhile all the devices that I have at home can)

The problem is that the arduino enters in an infinite loop the discharge the battery.

Does anybody has the same problem? did you solve the problem by code? doing something like a counter that try 20 times if not go to sleep and try later?

Thank's for your help

   // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  // you're connected now, so print out the data:
  Serial.print("You're connected to the network");
      Serial.print("Posting data");
    Serial.println("");
    root.printTo(Serial);
    postToTBD(root);
    delay(5000);




  delay(rebootTime);

Hi ecabanas,

So I'm fairly new to the MKR1000 + WiFi connectivity myself, but one thing I found helped was modifying the sketch to output a little more diagnostic info over the serial line.

I'd look to modify this:

while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

... to output some more meaningful information, which may at least help point you in a different direction from a diagnostics point-of-view:

while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);

    // output some diagnostic info
    Serial.println("Status = " + status);


  }

Here's what the status codes mean: WiFi101 - Arduino Reference

A little tip (apologies if you already know this!), I found that the SSID is case sensitive - if you get that wrong, you won't be able to connect to your access point.

Hope this helps!

Hi @ecabanas, i try to test the connection and recconection with a MKR1000 , actually it have reached 1268
conenction without problems, could you check which version of the firmware is present on the module? you could check it with the sketch CheckWifi101FirmwareVersion?

HI all

Let's go by parts :wink:

1º I know the case sensitive and there is no problem there.
2º The firmware is 1.0.0
3º I put the status :
Serial.println(WiFi.status());

and when not connects returns code 3 and when is connected code 6

...is very strange

...and not connecting most of times

thank's guys

@ecabanas Ok i have switch on a MKR1010, in order to be aligned with you, can you share the sketch that you use?
the status results in your case inverted 3 = WL_CONNECTED and 6 = WL_DISCONNECTED, in my actual test the board print the correct value of the status.

@ecabanas

Unsure how you got Firmware 1.0.0 as the latest is 19.5.4.

Could you explain how you reached that version number as it makes no sense.
The firmware checking test would have also reported that you were not running the latest firmware.

See this post for basic instructions to upgrade.

Or a quick video on You Tube

@ballscrewbob seems that his board is a mkr1010

upss sorry yes it is, it's a mkrwifi1010

Hi @ecabanas for the MKR1010 was released a new library version could you try it? , actually i follow in my test it stil reconnect ever

Yes I'm using wifina, but the issue is if the AP for example is busy or down the mk tries to reconnect forever, the problem is the battery and after some minutes the battery goes down

ok, in this case what you suggest about wait and reconnect after a interval of time could be done, in the following sketch i have modified the connection in the setup (), by adding:

 LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, NULL, 0); 


if (recon > 2 && status != WL_CONNECTED) {
     // Serial.println("deepsleep");
      digitalWrite(NINA_RESETN, HIGH);

      delay(1000);
      LowPower.deepSleep(20000);

      //delay(1000);
      digitalWrite(NINA_RESETN, LOW);
       //Serial.println("wakeup");
      recon=0;
    }

in the example in order to make the wifi1010 in deepsleep mode for 20 seconds, you need to use
LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, NULL, 0); for wake up the board when the deepsleep time is elapsed, the code example is the following:

/*

  This example connects to a encrypted WiFi network (WPA/WPA2).
  Then it prints the  MAC address of the WiFi module,
  the IP address obtained, and other network details.
  Then it continuously pings given host specified by IP Address or name.

  Circuit:
   WiFi shield attached / MKR1000

  created 13 July 2010
  by dlf (Metodo2 srl)
  modified 09 June 2016
  by Petar Georgiev
*/

#include <ArduinoLowPower.h>  //library needed for lowpower
#include <SPI.h>
#include <WiFiNINA.h>

#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;     // the WiFi radio's status

// Specify IP address or hostname
String hostName = "www.google.com";
int pingResult,recon=0;

void setup() {
  // Initialize serial and wait for port to open:
 


 LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, NULL, 0); 

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network:
  while ( status != WL_CONNECTED) {

   // Serial.print("Attempting to connect to WPA SSID: ");
  //  Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 5 seconds for connection:
    delay(5000);
    recon++;
    if (recon > 2 && status != WL_CONNECTED) {
     // Serial.println("deepsleep");
      digitalWrite(NINA_RESETN, HIGH);

      delay(1000);
      LowPower.deepSleep(20000);

      //delay(1000);
      digitalWrite(NINA_RESETN, LOW);
       //Serial.println("wakeup");
      recon=0;
    }
  }

   Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
 String fv = WiFi.firmwareVersion();
  if (fv != "1.0.0") {
    Serial.println("Please upgrade the firmware");
  }
  // you're connected now, so print out the data:
  Serial.println("You're connected to the network");
  printCurrentNet();
  printWiFiData();
}

void loop() {
  Serial.print("Pinging ");
  Serial.print(hostName);
  Serial.print(": ");

  pingResult = WiFi.ping(hostName);

  if (pingResult >= 0) {
    Serial.print("SUCCESS! RTT = ");
    Serial.print(pingResult);
    Serial.println(" ms");
  } else {
    Serial.print("FAILED! Error code: ");
    Serial.println(pingResult);
  }

  delay(5000);
}

void printWiFiData() {
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP address : ");
  Serial.println(ip);

  Serial.print("Subnet mask: ");
  Serial.println((IPAddress)WiFi.subnetMask());

  Serial.print("Gateway IP : ");
  Serial.println((IPAddress)WiFi.gatewayIP());

  // print your MAC address:
  byte mac[6];
  WiFi.macAddress(mac);
  Serial.print("MAC address: ");
  Serial.print(mac[5], HEX);
  Serial.print(":");
  Serial.print(mac[4], HEX);
  Serial.print(":");
  Serial.print(mac[3], HEX);
  Serial.print(":");
  Serial.print(mac[2], HEX);
  Serial.print(":");
  Serial.print(mac[1], HEX);
  Serial.print(":");
  Serial.println(mac[0], HEX);
  Serial.println();
}

void printCurrentNet() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print the MAC address of the router you're attached to:
  byte bssid[6];
  WiFi.BSSID(bssid);
  Serial.print("BSSID: ");
  Serial.print(bssid[5], HEX);
  Serial.print(":");
  Serial.print(bssid[4], HEX);
  Serial.print(":");
  Serial.print(bssid[3], HEX);
  Serial.print(":");
  Serial.print(bssid[2], HEX);
  Serial.print(":");
  Serial.print(bssid[1], HEX);
  Serial.print(":");
  Serial.println(bssid[0], HEX);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI): ");
  Serial.println(rssi);

  // print the encryption type:
  byte encryption = WiFi.encryptionType();
  Serial.print("Encryption Type: ");
  Serial.println(encryption, HEX);
  Serial.println();
}

consider that with 5 V in input the lowest current value reachable is 9.7 mA, with the battery pack is 3/4mA more or less, this should allow you to reduce the consumption in connection phase, in the image the red one is the results with deepsleep mode the green represent the classic connection

Riccardo_Rizzo:
ok, in this case what you suggest about wait and reconnect after a interval of time could be done, in the following sketch i have modified the connection in the setup (), by adding:

 LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, NULL, 0); 

if (recon > 2 && status != WL_CONNECTED) {
    // Serial.println("deepsleep");
      digitalWrite(NINA_RESETN, HIGH);

delay(1000);
      LowPower.deepSleep(20000);

//delay(1000);
      digitalWrite(NINA_RESETN, LOW);
      //Serial.println("wakeup");
      recon=0;
    }




in the example in order to make the wifi1010 in deepsleep mode for 20 seconds, you need to use 
**LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, NULL, 0);** for wake up the board when the deepsleep time is elapsed, the code example is the following:



/*

This example connects to a encrypted WiFi network (WPA/WPA2).
  Then it prints the  MAC address of the WiFi module,
  the IP address obtained, and other network details.
  Then it continuously pings given host specified by IP Address or name.

Circuit:
  WiFi shield attached / MKR1000

created 13 July 2010
  by dlf (Metodo2 srl)
  modified 09 June 2016
  by Petar Georgiev
*/

#include <ArduinoLowPower.h>  //library needed for lowpower
#include <SPI.h>
#include <WiFiNINA.h>

#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;    // the WiFi radio's status

// Specify IP address or hostname
String hostName = "www.google.com";
int pingResult,recon=0;

void setup() {
  // Initialize serial and wait for port to open:

LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, NULL, 0);

// check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

// attempt to connect to WiFi network:
  while ( status != WL_CONNECTED) {

// Serial.print("Attempting to connect to WPA SSID: ");
  //  Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

// wait 5 seconds for connection:
    delay(5000);
    recon++;
    if (recon > 2 && status != WL_CONNECTED) {
    // Serial.println("deepsleep");
      digitalWrite(NINA_RESETN, HIGH);

delay(1000);
      LowPower.deepSleep(20000);

//delay(1000);
      digitalWrite(NINA_RESETN, LOW);
      //Serial.println("wakeup");
      recon=0;
    }
  }

Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
String fv = WiFi.firmwareVersion();
  if (fv != "1.0.0") {
    Serial.println("Please upgrade the firmware");
  }
  // you're connected now, so print out the data:
  Serial.println("You're connected to the network");
  printCurrentNet();
  printWiFiData();
}

void loop() {
  Serial.print("Pinging ");
  Serial.print(hostName);
  Serial.print(": ");

pingResult = WiFi.ping(hostName);

if (pingResult >= 0) {
    Serial.print("SUCCESS! RTT = ");
    Serial.print(pingResult);
    Serial.println(" ms");
  } else {
    Serial.print("FAILED! Error code: ");
    Serial.println(pingResult);
  }

delay(5000);
}

void printWiFiData() {
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP address : ");
  Serial.println(ip);

Serial.print("Subnet mask: ");
  Serial.println((IPAddress)WiFi.subnetMask());

Serial.print("Gateway IP : ");
  Serial.println((IPAddress)WiFi.gatewayIP());

// print your MAC address:
  byte mac[6];
  WiFi.macAddress(mac);
  Serial.print("MAC address: ");
  Serial.print(mac[5], HEX);
  Serial.print(":");
  Serial.print(mac[4], HEX);
  Serial.print(":");
  Serial.print(mac[3], HEX);
  Serial.print(":");
  Serial.print(mac[2], HEX);
  Serial.print(":");
  Serial.print(mac[1], HEX);
  Serial.print(":");
  Serial.println(mac[0], HEX);
  Serial.println();
}

void printCurrentNet() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

// print the MAC address of the router you're attached to:
  byte bssid[6];
  WiFi.BSSID(bssid);
  Serial.print("BSSID: ");
  Serial.print(bssid[5], HEX);
  Serial.print(":");
  Serial.print(bssid[4], HEX);
  Serial.print(":");
  Serial.print(bssid[3], HEX);
  Serial.print(":");
  Serial.print(bssid[2], HEX);
  Serial.print(":");
  Serial.print(bssid[1], HEX);
  Serial.print(":");
  Serial.println(bssid[0], HEX);

// print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI): ");
  Serial.println(rssi);

// print the encryption type:
  byte encryption = WiFi.encryptionType();
  Serial.print("Encryption Type: ");
  Serial.println(encryption, HEX);
  Serial.println();
}




consider that with 5 V in input the lowest current value reachable is 9.7 mA, with the battery pack is 3/4mA more or less, this should allow you to reduce the consumption in connection phase, in the image the red one is the results with deepsleep mode the green represent the classic connection

Hi Ricardo,

First of all thank you very much for your help, I'm triying your code but I found a problem

error: 'NINA_RESETN' was not declared in this scope

digitalWrite(NINA_RESETN, HIGH);

what does it mean? what is NINA_RESETN?

Thank you very much

NINA_RESETN is declared in the wifi1010 core, check that you have the last samd core through the board manager, that you have selected the correct board and that you have in your libraries the library WiFiNINA.h though the library manager

NINA_RESETN is a define that represent the reset pin for reset the nina module , writing low or high, you can respectively turn on and off the nina module of the board, in this case i use it explicitly using the digtalWrite:

  • digitalWrite(NINA_RESETN, HIGH);: you say to the nina module on the board to turn off, reversal if you call

  • digitalWrite(NINA_RESETN, LOW);: you turn on the module.

in the code what happens is:

  • i tell to the module to turn off;

digitalWrite(NINA_RESETN, HIGH);

  • make the sand in low power mode for 20 s;
    LowPower.deepSleep(20000)

  • when the sleep time is elapsed i turn on the nina module

digitalWrite(NINA_RESETN, LOW);

Hi Ricardo,

Sorry about the delay but I was ill last week end.

I'm triying to use the NINA_RESET with my code but when I wake up, the connection did not restart.

What do you suggest to me? how could I do it whit my code?
1º Power board
2º READ SENSORS
3º Prepare json
4º Send via WIFI
5º Power off

///////////////////////////////////////////////////////////////Libraries definition//////////////////////////////////////////////////////
#include <ArduinoLowPower.h>
#include <ArduinoHttpClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "Wire.h"
#include <DFRobot_BME280.h>
#include <ArduinoJson.h>
#include <SPI.h>
#include <WiFiNINA.h>

#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)


int status = WL_IDLE_STATUS;
WiFiClient client;


#define BME_CS 10

DFRobot_BME280 mySensor; //I2C

//BME280 mySensor; //Global sensor object


///////////////////////////////////////////////////////////////Constants definition//////////////////////////////////////////////////////
#define UINT16_t_MAX    65536
#define INT16_t_MAX     UINT16_t_MAX/2
#define UINT8_t_MAX     256
#define INT8_t_MAX      UINT8_t_MAX/2

#define MAX_TEMP        60
#define MIN_TEMP        -60

#define MAX_CAP_TEMP    60
#define MIN_CAP_TEMP    -60

#define MAX_AIR_HUM     100
#define MIN_AIR_HUM     0

#define MAX_SOIL_HUM    900
#define MIN_SOIL_HUM    300

#define MAX_PRESS        1085
#define MIN_PRESS        870

#define MAX_RAIN        50
#define MIN_RAIN        0

#define MAX_VANE        359
#define MIN_VANE        0

#define MAX_WIND        150
#define MIN_WIND        0

//windgust
#define UINT_MAX 65535

int rebootTime = 3 * 60000;
float BatteryLevel = 0;
String vdot = "wifi001";


///////////////////////////////////////////////////////////////API parameters///////////////////////////////////////////////////////////////
char server[] = "********.io";
char path[] = "/*****/gprs";
int port = ****;
const char* device_secret_key = "*****************";
///////////////////////////////////////////////////////////////Thebluedots Json definition///////////////////////////////////////////////////////////////
StaticJsonBuffer<300> jsonBuffer;
HttpClient httpClient = HttpClient(client, server, port);
JsonObject& root = jsonBuffer.createObject();
//String response;
int statusCode = 0;
String dataStr;



void setup() {

  pinMode(LED_BUILTIN, OUTPUT);
  LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);
  Serial.begin(9600);

}
void loop() {

  digitalWrite(LED_BUILTIN, HIGH);
  ///////////////////////////////////////////////////////////////Power ON Lines//////////////////////////////////////////////////////

  digitalWrite(7, HIGH);
  Serial.begin(9600);
  delay(3000);

  ///////////////////////////////////////////////////////////////Initzializating libraries//////////////////////////////////////////////////////
  //**************BME280**************
  mySensor.begin(0x77);
  //  mySensor.beginI2C();
  delay(1000);

  //**************Dallas sensors**************

  dallas1.begin();   //Se inicia el sensor temperatura tierra 1
  delay(500);

  //**************Wire**************

  Wire.begin();

  delay(500);


///////////////////////////////////////////////////////READING SENSORS////////////////////////////////////////////////////////////



  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////JSON CRREATION ROUTINE///////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  StaticJsonBuffer<300> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["dot"] = vdot;//"gsm001";

  JsonObject& data = root.createNestedObject("data");
  data.set("5", shttemp);
  data.set("6", vpress);
  data.set("7", shthum);
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////WIFI SENDING ROUTINE///////////////////////////////////////////////////////////////
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.println("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
    // output some diagnostic info

    Serial.println(WiFi.status());
  }

  // you're connected now, so print out the data:
  Serial.print("You're connected to the network");
  Serial.print("Posting data");
  Serial.println("");
  root.printTo(Serial);
  postToTBD(root);
  delay(5000);


 

  digitalWrite(LED_BUILTIN, LOW);
  ///////////////////////////////////////////////////////////////POWER OFF////////////////////////////////////////////////////////////////////////////////////
  digitalWrite(7, LOW);


  delay(500);
 LowPower.sleep(rebootTime);
  //delay(rebootTime);


}
void dummy() {
  volatile int aaa = 0;
}

Hi @ecabanas , really don't worry, i have modifies your sketch as follow:

///////////////////////////////////////////////////////////////Libraries definition//////////////////////////////////////////////////////
#include <ArduinoLowPower.h>
#include <ArduinoHttpClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "Wire.h"
#include <DFRobot_BME280.h>
#include <ArduinoJson.h>
#include <SPI.h>
#include <WiFiNINA.h>

#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)


int status = WL_IDLE_STATUS;
WiFiClient client;


#define BME_CS 10

DFRobot_BME280 mySensor; //I2C

BME280 mySensor; //Global sensor object


///////////////////////////////////////////////////////////////Constants definition//////////////////////////////////////////////////////
#define UINT16_t_MAX    65536
#define INT16_t_MAX     UINT16_t_MAX/2
#define UINT8_t_MAX     256
#define INT8_t_MAX      UINT8_t_MAX/2

#define MAX_TEMP        60
#define MIN_TEMP        -60

#define MAX_CAP_TEMP    60
#define MIN_CAP_TEMP    -60

#define MAX_AIR_HUM     100
#define MIN_AIR_HUM     0

#define MAX_SOIL_HUM    900
#define MIN_SOIL_HUM    300

#define MAX_PRESS        1085
#define MIN_PRESS        870

#define MAX_RAIN        50
#define MIN_RAIN        0

#define MAX_VANE        359
#define MIN_VANE        0

#define MAX_WIND        150
#define MIN_WIND        0

//windgust
#define UINT_MAX 65535

int rebootTime = 3000;/// * 60000;
float BatteryLevel = 0;
String vdot = "wifi001";


///////////////////////////////////////////////////////////////API parameters///////////////////////////////////////////////////////////////
char server[] = "********.io";
char path[] = "/*****/gprs";
int port = ****;
const char* device_secret_key = "*****************";
///////////////////////////////////////////////////////////////Thebluedots Json definition///////////////////////////////////////////////////////////////
StaticJsonBuffer<300> jsonBuffer;
HttpClient httpClient = HttpClient(client, server, port);
JsonObject& root = jsonBuffer.createObject();
String response;
int statusCode = 0;
String dataStr;



void setup() {

 pinMode(9, OUTPUT);
 LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);
 // Serial.begin(115200);
 digitalWrite(9, HIGH);

}
void loop() {


 ///////////////////////////////////////////////////////////////Power ON Lines//////////////////////////////////////////////////////
 /*
   when you use the low power is suggests to not use the serial depends on the operating system his reinitialization could not
   be sufficient to show again message on the serial monitor in this sketch i use the LED 9

 */
 //call again here the begin is useless this part could be removed
 //digitalWrite(7, HIGH);
 //Serial.begin(115200);
 //delay(3000);

 ///////////////////////////////////////////////////////////////Initzializating libraries//////////////////////////////////////////////////////
 //**************BME280**************
 mySensor.begin(0x77);
 mySensor.beginI2C();
 delay(1000);

 //**************Dallas sensors**************

 dallas1.begin();   //Se inicia el sensor temperatura tierra 1
 delay(500);

 //**************Wire**************

 Wire.begin();

 delay(500);


 ///////////////////////////////////////////////////////READING SENSORS////////////////////////////////////////////////////////////



 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////JSON CRREATION ROUTINE///////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 StaticJsonBuffer<300> jsonBuffer;
 JsonObject& root = jsonBuffer.createObject();
 root["dot"] = vdot;//"gsm001";

 JsonObject& data = root.createNestedObject("data");
 data.set("5", shttemp);
 data.set("6", vpress);
 data.set("7", shthum);
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////WIFI SENDING ROUTINE///////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 // check for the WiFi module:
 if (WiFi.status() == WL_NO_MODULE) {
   //Serial.println("Communication with WiFi module failed!");
   // don't continue
   while (true);
 }

 // attempt to connect to Wifi network:

 /*
   the problem here is: that if you call the power off out of the following while, if the network is not able to connect to the network
   it will loop for ever and discharge your battery, like how you asked i have modified here adding a counter that after 3 fail break the while and goes in lowpower mode
 */
 int counter = 0;
 while (status != WL_CONNECTED && counter  < 3) {
   //Serial.println("Attempting to connect to WPA SSID: ");
   //Serial.println(ssid);
   // Connect to WPA/WPA2 network:
   status = WiFi.begin(ssid, pass);

   // wait 10 seconds for connection:
   delay(10000);
   // output some diagnostic info

   //Serial.println(WiFi.status());
   counter++;
 }
 /*
   Send only if the WiFi is connected and after to turn down disconnect from the network
 */
 if (status == WL_CONNECTED) {
   // you're connected now, so print out the data:
   // Serial.print("You're connected to the network");
   //Serial.print("Posting data");
   //Serial.println("");
     root.printTo(Serial);
     postToTBD(root);
   WiFi.disconnect();
   status = WL_IDLE_STATUS;
   delay(5000);
 }

 ///////////////////////////////////////////////////////////////POWER OFF////////////////////////////////////////////////////////////////////////////////////
 /*
     the NINA_RESETN should be used only here, how i have modified following, i suggest to use the macro name, if they are not recognized mean that there is something wrong and you have to check the libraries
     Pay attention that NINA_RESETN is a negated value, the "N"at the end of the name means "negate", the correct use is the following
 */
 digitalWrite(9, LOW);

 digitalWrite(NINA_RESETN, HIGH);

 delay(500);
 LowPower.sleep(rebootTime);
 //delay(rebootTime);

 digitalWrite(NINA_RESETN, LOW);
 digitalWrite(9, HIGH);

}
void dummy() {
 volatile int aaa = 0;
}

i had try to modify your sketch in accord with all that we have said previously, i have add some comment read it very careful, for show if the board is alive with the lowpower library, is better use led blinking because the monitor could not turn on after the calling of the low power, for test the sketch i have commented all the part that regard the sensor, let me now if it work,

WOWWWWWWWWWWWWW my total RESPECT!!!

it works perfect Last code consumed the battery in 60 cycle, now is in 280 and still working

Thank youuuuuuuuuuuuuuuuuuuuuu

hi @ecabanas, welcome :wink:

The battery died after................................414 cycles!!!

more or less 4 days without either one minute of sunlight....I only need 15mins to fully recharge the battery

thank's again