Hello
excuse me, I want to ask, my program used to run smoothly for more than 3 months, but suddenly since yesterday my device restarts every 5 minutes, what is the problem?
and this is the program code that I use.
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL68iyqeC_q"
#define BLYNK_TEMPLATE_NAME "Screen Om Sus"
#define BLYNK_AUTH_TOKEN "qDYEamYnerb_27aauqPPKV8FiKjzJDwx"
//pinout relay (diganti dulu kalau mau upload ulang)
#define pupuk 13
#define valve 1
#define air 5
#define pompa 4
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "time.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
int tmh1, tmm1, tms1, tmh2, tmm2, tms2;
int tsh1, tsm1, tss1, tsh2, tsm2, tss2;
int y;
// set the LCD number of columns and rows
int lcdColumns = 20;
int lcdRows = 4;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;
// Set password to "" for open networks.
char ssid[] = "BPP WI & SPI";
char pass[] = "";
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 6*3600;
const int daylightOffset_sec = 3600;
//BME820
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
// Onewire temperature
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float readTemperature() {
//add your code here to get the temperature from your temperature sensor
sensors.requestTemperatures();
return sensors.getTempCByIndex(0);
}
#define SoilPin 36
const int AirValue = 3780; // 3310,3400,3620 you need to replace this value with Value_1 3443
const int WaterValue = 90; // 1666,1400,1680you need to replace this value with Value_2
int intervals = (AirValue - WaterValue) / 3;
int soilMoistureValue = 0;
int soilmoisturepercent;
void ESP_Restart() {
unsigned long restartclue = 0;
const long RestartDalam = 5000;
Serial.println(millis());
if ((millis() - restartclue) >= RestartDalam) {
ESP.restart();
}
}
void Auto_Reconnect_5dtk() {
ESP_Restart();
}
// BLYNK_WRITE(V7){
// jeda_waktu = param.asInt();
// }
BLYNK_WRITE(V4) {
TimeInputParam t(param);
if (t.hasStartTime()) {
Serial.println(String("Start: ") +
t.getStartHour() + ":" +
t.getStartMinute() + ":" +
t.getStartSecond());
tmh1 = t.getStartHour();
tmm1 = t.getStartMinute();
tms1 = t.getStartSecond();
}
else if (t.isStartSunrise()) {
Serial.println("Start at sunrise");
}
else if (t.isStartSunset()) {
Serial.println("Start at sunset");
}
if (t.hasStopTime()) {
Serial.println(String("Stop: ") +
t.getStopHour() + ":" +
t.getStopMinute() + ":" +
t.getStopSecond());
tsh1 = t.getStopHour();
tsm1 = t.getStopMinute();
tss1 = t.getStopSecond();
}
else if (t.isStopSunrise()) {
Serial.println("Stop at sunrise");
}
else if (t.isStopSunset()) {
Serial.println("Stop at sunset");
}
Serial.println(String("Time zone: ") + t.getTZ());
Serial.println(String("Time zone offset: ") + t.getTZ_Offset());
for (int i = 1; i <= 7; i++) {
if (t.isWeekdaySelected(i)) {
Serial.println(String("Day ") + i + " is selected");
}
}
Serial.println();
}
BLYNK_WRITE(V5) {
TimeInputParam t(param);
if (t.hasStartTime()) {
Serial.println(String("Start: ") +
t.getStartHour() + ":" +
t.getStartMinute() + ":" +
t.getStartSecond());
tmh2 = t.getStartHour();
tmm2 = t.getStartMinute();
tms2 = t.getStartSecond();
}
else if (t.isStartSunrise()) {
Serial.println("Start at sunrise");
}
else if (t.isStartSunset()) {
Serial.println("Start at sunset");
}
if (t.hasStopTime()) {
Serial.println(String("Stop: ") +
t.getStopHour() + ":" +
t.getStopMinute() + ":" +
t.getStopSecond());
tsh2 = t.getStopHour();
tsm2 = t.getStopMinute();
tss2 = t.getStopSecond();
}
else if (t.isStopSunrise()) {
Serial.println("Stop at sunrise");
}
else if (t.isStopSunset()) {
Serial.println("Stop at sunset");
}
Serial.println(String("Time zone: ") + t.getTZ());
Serial.println(String("Time zone offset: ") + t.getTZ_Offset());
for (int i = 1; i <= 7; i++) {
if (t.isWeekdaySelected(i)) {
Serial.println(String("Day ") + i + " is selected");
}
}
Serial.println();
}
BLYNK_CONNECTED() {
Blynk.syncVirtual(V4, V5);
}
void setup() {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(pupuk, OUTPUT);
pinMode(air, OUTPUT);
pinMode(pompa, OUTPUT);
pinMode(valve, OUTPUT);
pinMode(pupuk, HIGH);
pinMode(air, HIGH);
pinMode(pompa, HIGH);
pinMode(valve, HIGH);
sensors.begin();
lcd.begin();
lcd.backlight();
Serial.println(F("OneWire begin"));
pinMode(SoilPin, INPUT);
Serial.println(F("Soil Sensor begin"));
bool status;// default settings
status = bme.begin(0x76);
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}Serial.println("-- Default Test --");
delay(1000);
Serial.println();
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
}
void loop (){
if (Blynk.connected()) {
Blynk.run();
//One Wire
float temperature = readTemperature(); // read your temperature sensor to execute temperature compensation
Serial.print("temperature:");
Serial.print(temperature);
Serial.println("°C");
Blynk.virtualWrite(V0, temperature);
//Soil Moisture
soilMoistureValue = analogRead(SoilPin);
Serial.println(soilMoistureValue);
String stat = "";
Serial.print("Analog Tanah:");
Serial.println(soilMoistureValue);
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
Serial.println(soilmoisturepercent);
Blynk.virtualWrite(V1, soilmoisturepercent);
float t = bme.readTemperature();
float h = bme.readHumidity();
float alt = bme.readAltitude(SEALEVELPRESSURE_HPA);
float press = bme.readPressure() / 100.0F;
String stat2 = "";
Serial.print("Temperature:");
Serial.print(t);
Serial.println("°C");
Blynk.virtualWrite (V2,t);
Serial.print("Humidity:");
Serial.print(h);
Serial.println("%");
Blynk.virtualWrite (V3,h);
Serial.print("Pressure: ");
Serial.print(t);
Serial.println("hPa");
Serial.print("Altitude: ");
Serial.print(h);
Serial.println("m");
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
Serial.println(&timeinfo, "%A, %d %B %Y %H:%M:%S");
char second[3];
strftime(second,3, "%S", &timeinfo);
Serial.println(second);
String s = String(second);
int d = s.toInt();
char minute[3];
strftime(minute,3, "%M", &timeinfo);
Serial.println(minute);
String mt = String(minute);
int m = mt.toInt();
char hour[3];
strftime(hour,3, "%H", &timeinfo);
//Serial.println(hour);
String jam = String(hour);
int j = jam.toInt();
char day[9];
strftime(day,9, "%A", &timeinfo);
String hari = String(day);
Serial.println(hari);
int x;
if(hari == "Monday" ){ x = 1; }
if(hari == "Tuesday" ){ x = 2; }
if(hari == "Wednesday"){ x = 3; }
if(hari == "Thursday" ){ x = 4; }
if(hari == "Friday" ){ x = 5; }
if(hari == "Saturday" ){ x = 6; }
if(hari == "Sunday" ){ x = 7; }
Serial.println(y);
Serial.println(x);
if(d==1||d==21||d==41){
Serial.println("hallo");
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Soil Temp & Humd");
lcd.setCursor(0, 1);
lcd.print("Soil Temp: " + String(temperature) + " C");
lcd.setCursor(0, 2);
lcd.print("Soil Humd: " + String(soilmoisturepercent) + " %");
lcd.setCursor(2, 3);
lcd.print("Polbangtan YOMA");
// lcd.print(" jam : " + String(j) +":"+ String(m) +":"+ String(d) );
}
if(d==6||d==26||d==46){
Serial.println("hai");
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Air Temp & Humd");
lcd.setCursor(0, 1);
lcd.print("Air Temp: " + String(t) + " C");
lcd.setCursor(0, 2);
lcd.print("Air Humd: " + String(h) + " %");
lcd.setCursor(2, 3);
lcd.print("Lahan Open Field");
}
if(d==11||d==31||d==51){
Serial.println("hai");
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Press & Altitude");
lcd.setCursor(0, 1);
lcd.print("Pressure: " + String(press) + " hPa");
lcd.setCursor(0, 2);
lcd.print("Altitude: " + String(alt) + " m");
lcd.setCursor(1, 3);
lcd.print("Kampus Yogyakarta");
}
if(d==16||d==36||d==56){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("---Smart Farming---");
lcd.setCursor(0, 1);
lcd.print("Polbangtan YOMA");
lcd.setCursor(9, 2);
lcd.print("X");
lcd.setCursor(4, 3);
lcd.print("Bapeltan Lampung");
}
if(j == tmh1 && m == tmm1){
Serial.println("========START ON========");
digitalWrite(air, LOW);
digitalWrite(pompa, LOW);
digitalWrite(valve, LOW);
}
if(j == tmm1 && m == tmm1 ){
digitalWrite(air, HIGH);
digitalWrite(pompa, HIGH);
digitalWrite(valve, HIGH);
}
if(j == tmh2 && m == tmm2){
Serial.println("========START ON========");
digitalWrite(air, LOW);
digitalWrite(pompa, LOW);
digitalWrite(valve, HIGH);
}
if(j == tmh2 + 2 && m == tmm2){
digitalWrite(air, HIGH);
digitalWrite(pompa, HIGH);
digitalWrite(valve, HIGH);
}
}
}
mohon bantuannya