Dear All,
Dear All,
After 3 months of running my ESP32 connected to a Wi-Fi router for my irrigation system, the ESP32 has started connecting and disconnecting frequently.
Please find below a screenshot showing the disconnection logs.
the DHT22 sensor was consistently sending all the data. However, starting from 01/06/2025, the data is no longer being sent. The DHT22 is in good condition and works very well. Maybe , It seems that the data storage is saturated. can you help mee to extract the old data and the new data wil be stored
here below the code :
/*
Sketch generated by the Arduino IoT Cloud Thing "Cloud Blink"
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudLight led;
CloudTemperatureSensor temperature;
CloudTemperatureSensor temperature_liquid;
int soil_moisture_1;
int toProduce_PWMsignal;
CloudRelativeHumidity humidity;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include "DHT.h"
#define MotorReceivesPWMWAVE 12
#define DHTPIN 15
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
int moisture_sol_1 ;
int sensor_analog ;
const int sensor_pin = A0;
const int ONE_WIRE_BUS = 17;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float Celsius = 0;
// ********************************************
// Function to calculate the time difference
unsigned long difTempoMillis(unsigned long tMillis, unsigned long tMillisAnt) {
/* Computes the time difference in milliseconds between the first and second argument
and takes into consideration the situation of overflow of the millis() function. */
if (tMillis >= tMillisAnt) return tMillis - tMillisAnt;
else return 0xFFFFFFFF - tMillisAnt + tMillis; // Case of overflow of millis()
}
// Timing variables
unsigned long timeMillis = millis();
static unsigned long timeMillisAntCon = timeMillis;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(115200);
pinMode(2, OUTPUT);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
dht.begin();
// Start the DS18B20 sensor
sensors.begin();
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
onTemperatureLiquid_read();
DHT_SENSOR_READ();
SOL_1_SENSOR_READ();
// Check if connected to Arduino Cloud
if (ArduinoCloud.connected()) {
// If connected, update the last connection time
timeMillisAntCon = timeMillis;
} else {
// If disconnected, check the elapsed time since last connection
if (difTempoMillis(millis(), timeMillisAntCon) > 120000) { // 2 minutes
Serial.println("No connection to Arduino Cloud. Restarting ESP32...");
ESP.restart(); // Restart ESP32 after 2 minutes of no connection
}
}
}
/*
Since Led is a READ_WRITE variable, onLedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLedChange() {
Serial.print("Led status changed:");
Serial.println(led);
if(led == 1) {
digitalWrite(2, HIGH);
}
else {
digitalWrite(2, LOW);
}
}
void DHT_SENSOR_READ() {
float h = dht.readHumidity();
// read temperature
float t = dht.readTemperature();
temperature = t;
humidity = h;
Serial.print("Temperature - ");
Serial.println(t); // Fixed typo from 'prinln' to 'println'
Serial.print("Humidity - ");
Serial.println(h);
}
void SOL_1_SENSOR_READ()
{
sensor_analog = analogRead(sensor_pin);
moisture_sol_1 = (100-(((sensor_analog/4095.00)*100)- 35));
soil_moisture_1 = moisture_sol_1;
Serial.print("Humidité du sol");
Serial.println(sensor_analog);
Serial.println(soil_moisture_1);
Serial.print("%");
delay(1000);
}
/*
Since ToProducePWMsignal is READ_WRITE variable, onToProducePWMsignalChange() is
executed every time a new value is received from IoT Cloud.
*/
void onToProducePWMsignalChange() {
analogWrite(MotorReceivesPWMWAVE, toProduce_PWMsignal);
}
/*
Since TemperatureLiquid is READ_WRITE variable, onTemperatureLiquidChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTemperatureLiquid_read() {
sensors.requestTemperatures();
Celsius = sensors.getTempCByIndex(0);
temperature_liquid = Celsius ;
Serial.print(Celsius);
Serial.print(" C ");
delay(1000);
}
What could be the cause, and what is the possible solution?
Thank you in advance for your support.