MKR1400 hangs up after hours

Hello there,
As a school project I am building and coding a weather station. For this I have an Arduino MKR1400 connected to a DHT22 (Pin 8), a BMP280 (SCL, SDA) and a DS1280 (Pin 2). The MKR1400 is powered over a micro USB cable from a power manager Board. This manager is connected to a 5V 1A solar panel and 3 18650 3000 mA 3.7V batteries. The manager has an output of constant 5V for the Arduino. The MKR1400 perfectly connects to the Internet and sends the data to ThingSpeak. Unfortunately it stopps working after a day or a few hours (seen as no data is sent to thingspeak anymore) altough it has battery left. The code is:

#include <DHT.h> 
#include <OneWire.h> 
#include <DallasTemperature.h> 
#include <Wire.h> 
#include <SPI.h> 
#include <Adafruit_BMP280.h>
#include <MKRGSM.h>
#include <ArduinoLowPower.h>
#include "secrets.h"
#include <ThingSpeak.h> 

#define DHTPIN 8 
#define DHTTYPE DHT22 
#define ONE_WIRE_BUS 2 

const char PINNUMBER[]     = SECRET_PIN;
const char GPRS_APN[]      = SECRET_GPRS_APN;
const char GPRS_LOGIN[]    = SECRET_GPRS_LOGIN;
const char GPRS_PASSWORD[] = SECRET_GPRS_PASS;

float airtemperature; 
float humidity;
float watertemperature;
float airpressure;

GSMClient client;
GPRS gprs;
GSM gsmAccess;
DHT dht(DHTPIN, DHTTYPE); 
OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire); 
Adafruit_BMP280 bmp; 

unsigned long myChannelNumber = SECRET_CH_ID; 
const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 

void setup() {
  pinMode(2, INPUT);
  pinMode(8, INPUT);
  pinMode(11, INPUT);
  pinMode(12, INPUT);
  dht.begin(); 
  sensors.begin(); 
  bmp.begin(); 
    boolean connected = false; //https://www.arduino.cc/en/Tutorial/MKRGSMExamplesWebClient
    while (!connected) {
      if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&
          (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
        connected = true;
        delay(1000);
        }
    ThingSpeak.begin(client);
    }
}


void loop() {
    airtemperature = dht.readTemperature();
    //float number1 = temperature;

    humidity = dht.readHumidity();
    //float number2 = humidity;

    sensors.requestTemperatures();
    watertemperature = sensors.getTempCByIndex(0);
    //float number3 = temp_water;

    airpressure = bmp.readPressure();
    //float number4 = pressure_air;
    
  ThingSpeak.setField(1, airtemperature);
  ThingSpeak.setField(2, humidity);
  ThingSpeak.setField(3, watertemperature);
  ThingSpeak.setField(4, airpressure);
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); //https://github.com/mathworks/thingspeak-arduino
  LowPower.deepSleep(10000); //https://www.arduino.cc/en/Reference/LowPowerDeepSleep
}

Thank you for your help:)

@lukasandcode, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project :wink:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.