My nodemcu goes offline for a 1min and satays online for some time then it goes offline for some time again (fyi i am using a solar plane to power the whole thing
This how the nodemcu is powered
Code-
/* Fill-in your Template ID (only if using Blynk.Cloud) */
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <Blynk.h>
#include <BlynkSimpleEsp8266.h>
#include "DHT.h"
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "ssid"; // type your wifi name
char pass[] = "pass"; // type your wifi password
#define DHTPIN D4
#define moistureSensor D3
#define analogreading A0
#define motor D1
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
int moistureState = 0;
int lastmoisState = 0;
int MotorState = 0;
int soilMoistureValue = 0;
int percentage = 0;
int pumpState = 0;
bool drySoilNotified = false;
bool wetSoilNotified = false;
BLYNK_CONNECTED() {
Blynk.syncVirtual(V0);
}
BLYNK_WRITE(V0) {
MotorState = param.asInt();
if (MotorState == 1) {
digitalWrite(motor, HIGH);
Serial.println("Motor ON");
}
else {
digitalWrite(motor, LOW);
Serial.println("Motor OFF");
}
}
void Reading() {
float h = dht.readHumidity();
float t = dht.readTemperature();
moistureState = digitalRead(moistureSensor);
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V2, h); //V2 is for Humidity
Blynk.virtualWrite(V1, t); //V1 is for Temperature
int i = analogRead(analogreading);
i = 4095 - i;
i = map(i, 0, 4095, 0, 100);
Blynk.virtualWrite(V3, i);
if (moistureState == 1 && lastmoisState == 0) {
Serial.println("Blynk Notification, needs water, send notification");
Blynk.logEvent("WATER","Water your plants");
lastmoisState = 1;
delay(1000);
}
else if (moistureState == 1 && lastmoisState == 1) {
Serial.println("has not been watered yet");
}
else if (moistureState == 0 && lastmoisState == 1) {
Serial.println("Water is sufficient");
lastmoisState = 0;
}
}
void setup() {
pinMode(D0, OUTPUT);
Serial.begin(9600);
Serial.begin(115200);
Serial.println();
delay(2000);
Serial.println("Please wait.... DHT Sensor activation");
dht.begin();
delay(3000);
Serial.println("Please wait for Blynk Server connection");
pinMode(moistureSensor, INPUT);
pinMode(analogreading, INPUT);
pinMode(motor, OUTPUT);
Blynk.begin(auth, ssid, pass);
Blynk.virtualWrite(V0, MotorState);
timer.setInterval(1000L, Reading);
}
void loop() {
soilMoistureValue = analogRead(A0);
percentage = map(soilMoistureValue, 490, 1023, 100, 0);
Serial.println(percentage);
if (percentage < 50 && !drySoilNotified) {
Serial.println("Pump on");
pumpState = 1;
Blynk.virtualWrite(V4, pumpState); // Update widget on Blynk app
Blynk.logEvent("dry_soil", "Soil is dry, motor started");
digitalWrite(D1, LOW);
drySoilNotified = true;
wetSoilNotified = false; // Reset wet soil notification flag
}
if (percentage > 80 && !wetSoilNotified) {
Serial.println("Pump off");
pumpState = 0;
Blynk.virtualWrite(V4, pumpState); // Update widget on Blynk app
Blynk.logEvent("wet_soil", "Soil is wet, motor turned off");
digitalWrite(D1, HIGH);
wetSoilNotified = true;
drySoilNotified = false; // Reset dry soil notification flag
}
Blynk.run(); // Run Blynk
timer.run();
}