unalbe to close the sketch with battery

Hi all,
I’m using a very simple sketch base on the Andrei Florian’s one (here). I’m using the MKR1000 and DHT22.

the DHT22 read temperature and Humidity every 30 minutes and the data should be uploaded on google sheet by wifi and api.

If I use the USB everything goes well. When I use the battery the sketch run but the data aren’t upload on google sheet.
I inserted in the code some blinking as a “spy” to see if the code is running and also in battery only mode all the blinks run.

I’m using a 3.7v LiPo with 1200 mha and another with 1800mha. The battery are charged.

Do you have some advices?
Thnak you

#include “ArduinoLowPower.h”
#include <WiFi101.h>
#include “DHT.h”
#define DHTPIN 2 // what pin we’re connected to, pin1 is 5th pin from end

#define DHTTYPE DHT22 // DHT 22

DHT dht(DHTPIN,DHTTYPE);

const char WEBSITE = “api.pushingbox.com”; //pushingbox API server
const String devid = “xxxxxxxxxxxx”; //device ID on Pushingbox for our Scenario

const char* MY_SSID = “Txxxxxxxxx”;
const char* MY_PWD = “xxxxxxxxxxxxx”;

int status = WL_IDLE_STATUS;
// if you don’t want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(7xxxxxxxxxxxxx); // numeric IP for Google (no DNS)

void setup() {
pinMode(LED_BUILTIN, OUTPUT);

/*
dht.begin();
{
; // wait for serial port to connect. Needed for native USB port only
}
status = WiFi.begin(MY_SSID, MY_PWD);

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

void loop() {

//inizio parte spostata da setup() a loop()
WiFi.begin();
dht.begin();
status = WiFi.begin(MY_SSID, MY_PWD);

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

// fine parte spostata da setup() a loop()

digitalWrite(LED_BUILTIN, HIGH);
// Wait between measurements.
//delay(1800000);

// Reading temperature and humidity
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
// if (isnan(h) || isnan(t) || isnan(f)) {
// Serial.println(“Failed to read from DHT sensor!”);
// return;

digitalWrite(LED_BUILTIN, LOW);
delay(200);
// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, h);
WiFiClient client; //Instantiate WiFi object, can scope from here or Globally
digitalWrite(LED_BUILTIN, HIGH);
delay(200);
//API service using WiFi Client through PushingBox then relayed to Google
//if (
client.connect(WEBSITE, 80);
//) // commentata per test soluzione batteria
{
client.print(“GET /pushingbox?devid=” + devid

  • “&humidityData=” + (String) h
  • “&celData=” + (String) t
  • “&fehrData=” + (String) f
  • “&hicData=” + (String) hi
    );

// HTTP 1.1 provides a persistent connection, allowing batched requests
// or pipelined to an output buffer
client.println(" HTTP/1.1");
client.print(“Host: “);
client.println(WEBSITE);
client.println(“User-Agent: MKR1000/1.0”);
//for MKR1000, unlike esp8266, do not close connection
client.println();
/*Serial.println(”\nData Sent”); */
client.stop();}

delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(200);
digitalWrite(LED_BUILTIN, HIGH);
delay(5000);
digitalWrite(LED_BUILTIN, LOW);
delay(2000);
WiFi.end();
LowPower.deepSleep(30601000); // stop il processore 1790000
}

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

void dummy() {
// This function will be called once on device wakeup
// You can do some little operations here (like changing variables which will be used in the loop)
// Remember to avoid calling delay() and long running functions since this functions executes in interrupt context
}