Good Day!
I am working on a Remote Start/Stop System for a Generator using a Wemos D1 Mini Pro.
It works great, however occassionally when I press vPin V1 or V9, the board crashes and reboots. I have simplified my code as far as possible and have no idea why it occurs occasitionally.
When I look at the serial monitor, the error decodes to something involving watchdog, I have no idea what that is and read that feeding the watchdog is a fix, but it still happens.
Again this doesnt happen all the time, its just random. This doesnt happen to any of the other vPins such as V10.
Also when i look at the device timeline, the board goes offline and reconnects at random times when I don’t interact with the app, please see attached screenshot.
I am using the latest blynk library (1.01) and my internet connection is stable.
I would really like to make my project as reliable as possible and I look forward for some advice on how to solve this.
Thanks in advance.
/*
* Remote Generator Start/Stop System (BLYNK 2.0)
* Developed By AL
*/
#define BLYNK_TEMPLATE_ID "TMPL_vJdFuLm"
#define BLYNK_DEVICE_NAME "Yamaha EF5500EFW"
#define BLYNK_PRINT Serial
#define BLYNK_FIRMWARE_VERSION "0.3.1"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#include <SoftwareSerial.h>
#include <RCSwitch.h>
#define BLYNK_GREEN "#23C48E"
#define BLYNK_RED "#D3435C"
#define USE_NODE_MCU_BOARD
#include "BlynkEdgent.h"
RCSwitch mySwitch = RCSwitch();
unsigned long previousMillis = 0;
unsigned long interval = 30000;
int CEBsensor = 0;
int CEBstate = 0;
int Vsensor = A0; // 0-25v voltage sensor is connected with the analog pin A0 of the arduino
//For 0-25v voltage sensor
float correctionfactor = 7.40;
float vout = 0.0;
float vin = 0.0;
// two resistors 30K and 7.5k ohm on Voltage Sensor
float R1 = 30000; //
float R2 = 7500; //
int value = 0;
BlynkTimer timer;
int newTimer = 1;
String myString; // complete message from arduino, which consistors of snesors data
char rdata; // received charactors
int firstVal, secondVal,thirdVal; // sensors
void setup()
{
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
pinMode(Vsensor, INPUT); //Voltage Sensor
mySwitch.enableTransmit(D5); //RF Transmitter
pinMode(D6, OUTPUT); //UPS Relay
pinMode(D1, INPUT); //CEB LDR Sensor
timer.setInterval(1000L,sensorvalue1);
}
void loop() {
BlynkEdgent.run();
timer.run(); // Initiates BlynkTimer
ESP.wdtFeed();
CEBsensor = digitalRead(D1); //LDR Sensor
//If Coil ON and CEBsensor LOW, Send Alert
if(CEBsensor == LOW && CEBstate == HIGH){
WidgetLED led13(V13);
led13.on(); //Shutoff Indicator ON
} else {
WidgetLED led13(V13);
led13.off(); //Shutoff Indicator OFF
}
//CEB Status LED
if(CEBsensor == HIGH){
WidgetLED led14(V14);
led14.on(); //CEB Status (ON) Green
Blynk.setProperty(V14, "color", "#D3435C");
} else {
WidgetLED led14(V14); //CEB Status (OFF) RED
Blynk.setProperty(V14, "color", "#23C48E");
}
ESP.wdtFeed();
}
BLYNK_CONNECTED() {
Blynk.syncVirtual(V1, V9, V3, V7);
}
void sensorvalue1()
//Run every second
{
int sdata = 0;
// read the value at analog input
value = analogRead(Vsensor);
vout = (value * 5.0) / 1024.0; // see text
vin = vout / (R2/(R1+R2));
vin = vin - correctionfactor;
Blynk.virtualWrite(V5, vin);
Blynk.virtualWrite(V11, WiFi.localIP().toString());
Blynk.virtualWrite(V8, map(WiFi.RSSI(), -110, -30, 30, 100));
Blynk.virtualWrite(V12, CEBsensor);
}
BLYNK_WRITE(V9)
//attach Button on virtual V9,
//This will control the Fuel
{
if (param.asInt() == 1){
ESP.wdtFeed();
mySwitch.send(4617746, 24); //FUEL
WidgetLED led2(V7);
led2.on();
}
if (param.asInt() == 0){
ESP.wdtFeed();
mySwitch.send(4617746, 24); //FUEL
WidgetLED led2(V7);
led2.off();
}
}
BLYNK_WRITE(V1)
//attach Button on virtual V1,
//it will control the Coil
{
if (param.asInt() == 1){
ESP.wdtFeed();
mySwitch.send(4617745, 24); //COIL
WidgetLED led1(V3);
led1.on();
CEBstate = 1;
}
if (param.asInt() == 0){
ESP.wdtFeed();
mySwitch.send(4617745, 24); //COIL
WidgetLED led1(V3);
led1.off();
CEBstate = 0;
}
}
BLYNK_WRITE(V2)
//attach Button on virtual V2,
//it will control the Starter
{
if(param.asInt()){
// button pressed for >2Sec
newTimer = timer.setTimeout(2000,Starter);
}
else {
timer.disable(newTimer);
}
}
void Starter()
{
Serial.println("System Authorized Start");
WidgetLED led3(V4);
led3.on();
mySwitch.send(15425809, 24);
mySwitch.send(15425809, 24);
mySwitch.send(15425809, 24);
led3.off();
}
BLYNK_WRITE(V10)
//attach Button on virtual V10,
//it will control the UPS Relay
{
if (param.asInt() == 1){
digitalWrite(D6,HIGH); //relay on
}
if (param.asInt() == 0){
digitalWrite(D6,LOW); //relay off
}
}