The reason is because there seemed to be absolutely no improvements when using ““ESP8266_Standalone” and secondly since the device is in an enclosure and I am tinkering with the code, trial and error changes, to try and resolve this issue, Blynk Air is extremly useful.
Well it didnt take long for the device to go offline and the serial monitor output is interesting.
As suspected before the board isnt loosing connection with the router, nor is the board crashing. It simply looses looses connnection with Blynk’s server and continously tries to establish a connection to the sever and looses it again (as seen in the 3rd attached picture).
What can be causing this? I’ve read Blynk servers will disconnect a device if it recieves spam pings, but nothing in my code will cause that?!
Update-
The device is back only after 19 minutes.
Looking at the SM, the board doesnt crash or reboot, it just reconnects to the server after many failed
attempts
As I explained before, it’s very easy to add Blynk.Air to the standalone sketch by pasting the code in the example.
Edgent makes it extremely difficult to make any changes to the connection routines, so it’s a bad starting point for resolving this type of issue.
When you post serial output it’s far better if you copy the text and paste it with triple backticks, the same as when you post code.
The device can’t communicate with the Blynk server anymore. This is probably because daya packets that are intended for the Blynk server aren’t making it through, or your ISP is blocking them.
You could try using port 80 (far easier when you use the non-Edgent) examples) and possibly try turning-on Blynk debugging or Core Debugging (in the IDE).
Pete.
Understood, I will revert back to non edgent Blynk. I am not too keen about Blynk Air at the moment since the board is connected to my computer and as you mensioned earlier, I should focus fixing this before trying to incopperate Air to the code.
Thank you for the SM suggestion, I will keep that in mind
May I know how to change the port to 80 and turn on Blynk debugging for non-edgent sketches?
If you use the “Blynk simple” library files that don’t have “SSL” in their names the port 80 will be used.
Pete.
ESP_WiFi Sketch
/*************************************************************
Blynk is a platform with iOS and Android apps to control
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
You can easily build mobile and web interfaces for any
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: https://www.blynk.io
Sketch generator: https://examples.blynk.cc
Blynk community: https://community.blynk.cc
Follow us: https://www.fb.com/blynkapp
https://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example runs directly on ESP32 chip.
NOTE: This requires ESP32 support package:
https://github.com/espressif/arduino-esp32
Please be sure to select the right ESP32 module
in the Tools -> Board menu!
Change WiFi ssid, pass, and Blynk auth token to run :)
Feel free to apply it to any other example. It's simple!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
/* Fill in information from Blynk Device Info here */
//#define BLYNK_TEMPLATE_ID "TMPxxxxxx"
//#define BLYNK_TEMPLATE_NAME "Device"
//#define BLYNK_AUTH_TOKEN "YourAuthToken"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop()
{
Blynk.run();
}
Would this be an example I could you?
Yes.
Pete.
Pete isnt “ESP32_WiFi” similar and “ESP8266_Standalone” both using port 80?
If so then I already tried “ESP8266_Standalone” and it still seemed to go offline.
However I will anyways reupload the “ESP8266_Standalone” tonight and hopefully I will wake up and see that the device is still online
23:16:50.166 -> [134334] >[00|04|F6|00|C8]
23:16:50.213 -> [134354] <[13|04|F7|00|0F]23[00]isDisabled[00]1
23:16:50.260 -> [134400] >[00|04|F7|00|C8]
23:16:50.307 -> [134421] <[13|04|F8|00|0F]22[00]isDisabled[00]1
23:16:50.354 -> [134466] >[00|04|F8|00|C8]
23:16:50.354 -> [134488] <[13|04|F9|00|10]18[00]color[00]#ED9D00
23:16:50.402 -> [134533] >[00|04|F9|00|C8]
23:16:50.450 -> [134555] <[13|04|FA|00|10]10[00]color[00]#ED9D00
23:16:50.497 -> [134656] >[00|04|FA|00|C8]
23:16:50.543 -> [134656] <[13|04|FB|00|18]2[00]offLabel[00]Hold[20]to[20]Start
23:16:50.591 -> [134702] >[00|04|FB|00|C8]
23:16:50.638 -> [134724] <[13|04|FC|00|11]2[00]onLabel[00]Release
23:16:50.684 -> [134768] >[00|04|FC|00|C8]
23:16:50.732 -> [134791] <[14|04|FD|00|07]vw[00]20[00]0
23:16:51.013 -> [135152] <[14|04|FE|00|07]vw[00]12[00]0
23:16:51.061 -> [135220] <[14|04|FF|00|07]vw[00]13[00]0
23:16:51.153 -> [135287] <[13|05|00|00|10]14[00]color[00]#23C48E
23:16:51.200 -> [135331] >[00|05|00|00|C8]
23:16:51.200 -> [135354] <[13|05|01|00|0F]23[00]isDisabled[00]1
23:16:51.247 -> [135400] >[00|05|01|00|C8]
23:16:51.294 -> [135421] <[13|05|02|00|0F]22[00]isDisabled[00]1
23:16:51.342 -> [135468] >[00|05|02|00|C8]
23:16:51.387 -> [135488] <[13|05|03|00|10]18[00]color[00]#ED9D00
23:16:51.434 -> [135533] >[00|05|03|00|C8]
23:16:51.434 -> [135555] <[13|05|04|00|10]10[00]color[00]#ED9D00
23:16:51.529 -> [135656] >[00|05|04|00|C8]
23:16:51.529 -> [135656] <[13|05|05|00|18]2[00]offLabel[00]Hold[20]to[20]Start
23:16:51.624 -> [135701] >[00|05|05|00|C8]
23:16:51.624 -> [135724] <[13|05|06|00|11]2[00]onLabel[00]Release
23:16:51.671 -> [135769] >[00|05|06|00|C8]
23:16:51.719 -> [135791] <[14|05|07|00|07]vw[00]20[00]0
23:16:52.000 -> [136152] <[14|05|08|00|07]vw[00]12[00]0
23:16:52.046 -> [136220] <[14|05|09|00|07]vw[00]13[00]0
23:16:52.141 -> [136287] <[13|05|0A|00|10]14[00]color[00]#23C48E
23:16:52.188 -> [136331] >[00|05|0A|00|C8]
Uploaded and enable Blynk Debug,
This section is reoccuring in SM, would this be anything alarming?
(Included screenshot as well)
[Screenshot of serial output removed by moderator]
Please don’t post screenshots.
The serial monitor makes no sense without the sketch that goes with it.
Pete.
08:39:04.799 -> [33169831] Connecting to blynk.cloud:8080
08:39:04.799 -> [33175935] Connecting to blynk.cloud:80
08:39:04.799 -> [33181936] Connecting to blynk.cloud:8080
08:39:24.831 -> [33188041] Connecting to blynk.cloud:80
08:39:24.831 -> [33194042] Connecting to blynk.cloud:8080
08:39:24.831 -> [33200147] Connecting to blynk.cloud:80
08:39:44.864 -> [33206148] Connecting to blynk.cloud:8080
08:39:44.864 -> [33212252] Connecting to blynk.cloud:80
08:39:44.864 -> [33218254] Connecting to blynk.cloud:8080
08:40:04.896 -> [33224359] Connecting to blynk.cloud:80
08:40:04.896 -> [33230360] Connecting to blynk.cloud:8080
08:40:04.896 -> [33236464] Connecting to blynk.cloud:80
08:40:04.896 -> [33242466] Connecting to blynk.cloud:8080
08:40:24.929 -> [33248570] Connecting to blynk.cloud:80
08:40:24.929 -> [33254571] Connecting to blynk.cloud:8080
08:40:24.929 -> [33260675] Connecting to blynk.cloud:80
08:40:44.962 -> [33266677] Connecting to blynk.cloud:8080
08:40:44.962 -> [33272781] Connecting to blynk.cloud:80
08:40:44.962 -> [33278782] Connecting to blynk.cloud:8080
08:41:04.994 -> [33284886] Connecting to blynk.cloud:80
08:41:04.994 -> [33290888] Connecting to blynk.cloud:8080
08:41:04.994 -> [33296992] Connecting to blynk.cloud:80
08:41:25.027 -> [33302994] Connecting to blynk.cloud:8080
08:41:25.027 -> [33309098] Connecting to blynk.cloud:80
08:41:25.027 -> [33315099] Connecting to blynk.cloud:8080
08:41:25.027 -> [33321204] Connecting to blynk.cloud:80
08:41:45.059 -> [33327205] Connecting to blynk.cloud:8080
08:41:45.059 -> [33333309] Connecting to blynk.cloud:80
08:41:45.059 -> [33339311] Connecting to blynk.cloud:8080
08:42:05.092 -> [33345415] Connecting to blynk.cloud:80
08:42:05.092 -> [33351417] Connecting to blynk.cloud:8080
08:42:05.092 -> [33357521] Connecting to blynk.cloud:80
08:42:24.400 -> [33363523] Connecting to blynk.cloud:8080
08:42:24.400 -> [33369627] Connecting to blynk.cloud:80
08:42:24.400 -> [33375629] Connecting to blynk.cloud:8080
08:42:24.400 -> [33381734] Connecting to blynk.cloud:80
08:49:10.626 -> [33387737] Connecting to blynk.cloud:8080
08:49:10.626 -> [33393841] Connecting to blynk.cloud:80
08:49:10.626 -> [33399843] Connecting to blynk.cloud:8080
08:49:29.767 -> [33793345] Connecting to blynk.cloud:80
08:49:29.767 -> [33799346] Connecting to blynk.cloud:8080
08:49:29.767 -> [33805450] Connecting to blynk.cloud:80
08:49:49.799 -> [33811452] Connecting to blynk.cloud:8080
08:49:49.799 -> [33817556] Connecting to blynk.cloud:80
08:49:49.799 -> [33823558] Connecting to blynk.cloud:8080
09:09:51.224 -> [33829662] Connecting to blynk.cloud:80
09:09:51.224 -> [33835664] Connecting to blynk.cloud:8080
09:09:54.294 -> [35034172] Connecting to blynk.cloud:8080
09:10:00.400 -> [35040276] Connecting to blynk.cloud:80
09:10:06.421 -> [35046280] Connecting to blynk.cloud:8080
09:10:12.493 -> [35052384] Connecting to blynk.cloud:80
09:10:18.502 -> [35058386] Connecting to blynk.cloud:8080
09:10:24.609 -> [35064491] Connecting to blynk.cloud:80
09:10:30.601 -> [35070492] Connecting to blynk.cloud:8080
09:10:36.702 -> [35076597] Connecting to blynk.cloud:80
The board went offline last night and similar SM results
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#define BLYNK_TEMPLATE_ID "TMPL_vJdFuLm"
#define BLYNK_TEMPLATE_NAME "x"
#define BLYNK_AUTH_TOKEN "x"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "x";
char pass[] = "x";
#define BLYNK_GREEN "#23C48E"
#define BLYNK_RED "#D3435C"
#define BLYNK_YELLOW "#ED9D00"
int CEBsensor = 0;
int CEBstate = 0;
int Timerstate = 0;
int InvTimerstate = 0;
int inverterstate = 0;
//Voltage Sensor
int Vsensor = A0;
float correctionfactor = 7.40;
float vout = 0.0;
float vin = 0.0;
float fuelcon = 0.0;
float R1 = 30000;
float R2 = 7500;
int value = 0;
//Declare millis for timers
unsigned long msec = 0;
unsigned long msec2 = 0;
float times = 0.0;
float hourmeter = 0.0;
BlynkTimer timer;
//Blynk LED Widgets
WidgetLED led1(V3); //COIL LED
WidgetLED led2(V7); //FUEL LED
WidgetLED led3(V4); //STARTER LED
WidgetLED led13(V13); //GENERATOR SHUTOFF LED
WidgetLED led14(V14); //CEB STATUS LED
WidgetLED led15(V18); //INVERTER STATUS LED
WidgetLED led16(V20); //INVERTER SHUTOFF LED
WidgetLED led17(V24); //CHANGEOVER RELEASE INDICATOR
int newTimer = 1;
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(16, OUTPUT); //STARTER Relay D0
pinMode(14, OUTPUT); //FUEL Relay D5
pinMode(12, OUTPUT); //COIL Relay D6
pinMode(13, OUTPUT); //INVERTER Relay D7
pinMode(5, INPUT); //CEB LDR Sensor D1
pinMode(Vsensor, INPUT); //Voltage Sensor (A0)
{
//(To prevent self-trigger during initial boot)
digitalWrite(16,HIGH); //D0
digitalWrite(14,HIGH); //D5
digitalWrite(12,HIGH); //D6
}
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(5000L,CEBsensor1);
timer.setInterval(1000L,runtime);
timer.setInterval(1000L,invertertime);
timer.setInterval(10000L,Voltagesensor1);
}
void loop()
{
Blynk.run();
timer.run();
}
BLYNK_CONNECTED() {
Blynk.syncVirtual(V10,V18); //Works, Doesn't get triggered when not on
}
void invertertime()
{
if(CEBstate == LOW){
if(inverterstate == HIGH){
led15.on();
Blynk.setProperty(V10, "color", "#23C48E");
Blynk.setProperty(V18, "color", "#23C48E"); //Inverter Status (ON) GREEN
digitalWrite(13,HIGH); //INV RELAY ON D7
delay(100);
Blynk.setProperty(V2, "offLabel", "OFF Inverter Before Starting");
Blynk.setProperty(V2, "onLabel", "OFF Inverter!");
} else {
Blynk.setProperty(V18, "color", "#ED9D00"); //Inverter Status (OFF) Yellow
Blynk.setProperty(V10, "color", "#ED9D00");
digitalWrite(13,LOW); //INV RELAY OFF D7
delay(100);
Blynk.setProperty(V2, "offLabel", "Hold to Start");
Blynk.setProperty(V2, "onLabel", "Release");
}
} else {
}
if(inverterstate == HIGH && CEBsensor ==LOW){
led16.on(); //Inverter Shutoff Indicator ON
} else {
led16.off(); //Inverter Shutoff Indicator OFF
}
}
void runtime()
{
if(CEBstate == HIGH && Timerstate == HIGH){
times = ((millis() - msec));
Blynk.setProperty(V16, "label", "Current Generator Run Time");
Blynk.setProperty(V17, "label", "Current Fuel Consumption");
{
String readableTime;
getReadableTime(readableTime);
Blynk.virtualWrite(V16, readableTime);
Blynk.virtualWrite(V17, 1.7 * ((millis() - msec)/1000)/3600);
delay(100);
}
} else {
}
if(InvTimerstate == HIGH && CEBstate == LOW && Timerstate == LOW){
times = ((millis() - msec2));
Blynk.setProperty(V16, "label", "Inverter Run Time");
{
String readableTime;
getReadableTime(readableTime);
Blynk.virtualWrite(V16, readableTime);
}
delay(100);
} else {
}
}
void getReadableTime(String &readableTime) {
unsigned long currentMillis;
unsigned long seconds;
unsigned long minutes;
unsigned long hours;
unsigned long days;
currentMillis = times;
seconds = currentMillis / 1000;
minutes = seconds / 60;
hours = minutes / 60;
days = hours / 24;
currentMillis %= 1000;
seconds %= 60;
minutes %= 60;
hours %= 24;
if (days > 0) {
readableTime = String(days) + " ";
}
if (hours > 0) {
readableTime += String(hours) + "H:";
}
if (minutes < 10) {
readableTime += "0";
}
readableTime += String(minutes) + "m:";
if (seconds < 10) {
readableTime += "0";
}
readableTime += String(seconds) + "s";
}
BLYNK_WRITE(V1)
//attach Button on virtual V1,
//it will control the Coil
{
if (param.asInt() == 1){
delay(100);
digitalWrite(12,LOW); //COIL RELAY ON D6
delay(100);
led1.on();
msec = millis();
CEBstate = 1;
}
if (param.asInt() == 0){
digitalWrite(12,HIGH); //COIL RELAY OFF D6
led1.off();
CEBstate = 0;
Blynk.setProperty(V16, "label", "Previous Generator Run Time");
Blynk.setProperty(V17, "label", "Previous Fuel Consumption");
//Blynk.setProperty(V23, "isDisabled", true);
Blynk.logEvent("generator_off");
}
}
BLYNK_WRITE(V2)
//attach Button on virtual V2,
//it will control the Starter
{
if(param.asInt()){
newTimer = timer.setTimeout(2000,Starter); // button pressed for >2Sec
}
else {
timer.disable(newTimer);
}
}
void Starter()
{
if(inverterstate == LOW){
led3.on();
digitalWrite(16,LOW); //STARTER CRANK ON D0
delay(1200); //CRANK DURATION
digitalWrite(16,HIGH); //STARTER CRANK OFF D0
led3.off();
Blynk.logEvent("generator_on");
//Blynk.setProperty(V23, "isDisabled", true);
}else{
}
}
BLYNK_WRITE(V9)
//attach Button on virtual V9,
//This will control the Fuel
{
if (param.asInt() == 1){
digitalWrite(14,LOW); //FUEL RELAY ON D5
delay(100);
led2.on();
Timerstate = 1;
}
if (param.asInt() == 0){
digitalWrite(14,HIGH); //FUEL RELAY OFF D5
led2.off();
Timerstate = 0;
}
}
BLYNK_WRITE(V10)
//attach Button on virtual V10,
//it will control the Inverter Relay
{
if (param.asInt() == 1){
inverterstate = 1;
delay(100);
msec2 = millis();
InvTimerstate = 1;
Blynk.logEvent("inverter_on");
Blynk.setProperty(V22, "isDisabled", true);
Blynk.setProperty(V23, "isDisabled", false);
}
if (param.asInt() == 0){
inverterstate = 0;
InvTimerstate = 0;
delay(100);
Blynk.logEvent("inverter_off");
Blynk.setProperty(V22, "isDisabled", false);
}
}
BLYNK_WRITE(V15)
//attach Button on virtual V15,
//This will update System Status
{
if (param.asInt() == 1){
Blynk.virtualWrite(V8, map(WiFi.RSSI(), -110, -30, 30, 100));
}
}
BLYNK_WRITE(V19)
//attach Button on virtual V19,
//This will reset Coil/Fuel Status
{
if (param.asInt() == 1){
Blynk.virtualWrite(V1, 0);
led1.off();
Blynk.virtualWrite(V9, 0);
led2.off();
Blynk.setProperty(V16, "label", "Previous Run Time");
Blynk.setProperty(V17, "label", "Previous Fuel Consumption");
Blynk.logEvent("generator_off");
Timerstate = 0;
CEBstate = 0;
}
if (param.asInt() == 0){
}
}
void CEBsensor1()
//Run every 5 second
{
CEBsensor = digitalRead(5); //LDR Sensor D1
Blynk.virtualWrite(V12, CEBsensor);
//If COIL ON and CEBsensor LOW, Trigger "Grid Restored" Blynk Automation
if(CEBsensor == LOW && CEBstate == HIGH){
led13.on(); //Shutoff Indicator ON
} else {
led13.off(); //Shutoff Indicator OFF
}
//CEB STATUS LED
if(CEBsensor == HIGH){
led14.on();
Blynk.setProperty(V14, "color", "#D3435C"); //CEB Status (ON) RED
Blynk.logEvent("grid_failure");
Blynk.setProperty(V23, "isDisabled", false);
Blynk.setProperty(V22, "isDisabled", false);
} else {
Blynk.setProperty(V14, "color", "#23C48E"); //CEB Status (ON) GREEN
Blynk.setProperty(V23, "isDisabled", true);
Blynk.setProperty(V22, "isDisabled", true);
}
}
void Voltagesensor1()
//Run every 10 sec
{
int sdata = 0;
value = analogRead(Vsensor);
vout = (value * 5.0) / 1024.0;
vin = vout / (R2/(R1+R2));
vin = vin - correctionfactor;
Blynk.virtualWrite(V5, vin);
if(vin < 12.0){
Blynk.setProperty(V5, "color", "#D3435C"); //If UPS Voltage < 12.5v, Gauge RED
}else{
Blynk.setProperty(V5, "color", "#F7CE46"); //If UPS Voltage > 12.5v, Gauge ORANGE
}
}
//BETA
BLYNK_WRITE(V22)
//attach Button on virtual V22,
//it will control the GENtoINV
{
if(param.asInt()){
newTimer = timer.setTimeout(2000,GENtoINV); // button pressed for >2Sec
}
else {
timer.disable(newTimer);
}
}
void GENtoINV()
{
if(inverterstate == LOW){
{
led17.on();
//FUEL
Blynk.virtualWrite(V1, 0);
led1.off();
digitalWrite(12,HIGH); //COIL RELAY OFF D6
delay(100);
CEBstate = 0;
Blynk.setProperty(V16, "label", "Previous Generator Run Time");
Blynk.setProperty(V17, "label", "Previous Fuel Consumption");
Blynk.logEvent("generator_off");
}
delay(1500);
{
//COIL
Blynk.virtualWrite(V9, 0);
led2.off();
digitalWrite(14,HIGH); //FUEL RELAY OFF D5
Timerstate = 0;
}
delay(2000);
{
//INV Relay
Blynk.virtualWrite(V10, HIGH);
inverterstate = 1;
msec2 = millis();
InvTimerstate = 1;
Blynk.logEvent("inverter_on");
led17.off();
}
}else{
}
}
BLYNK_WRITE(V23)
//attach Button on virtual V23,
//it will control the INVtoGEN
{
if(param.asInt()){
newTimer = timer.setTimeout(2000,INVtoGEN); // button pressed for >2Sec
}
else {
timer.disable(newTimer);
}
}
void INVtoGEN()
{
{
//INV RELAY OFF
led17.on();
inverterstate = 0;
InvTimerstate = 0;
Blynk.logEvent("inverter_off");
{
Blynk.virtualWrite(V10, 0);
Blynk.setProperty(V10, "color", "#ED9D00");
Blynk.setProperty(V18, "color", "#ED9D00"); //Inverter Status (OFF) Yellow
digitalWrite(13,LOW); //INV RELAY OFF D7
delay(100);
Blynk.setProperty(V2, "offLabel", "Hold to Start");
Blynk.setProperty(V2, "onLabel", "Release");
}
Blynk.setProperty(V22, "isDisabled", false);
}
delay(3000);
{
//FUEL
Blynk.virtualWrite(V9, 1);
digitalWrite(14,LOW); //FUEL RELAY ON D5
led2.on();
Timerstate = 1;
}
delay(1500);
{
//COIL
Blynk.virtualWrite(V1, 1);
digitalWrite(12,LOW); //COIL RELAY ON D6
led1.on();
msec = millis();
Blynk.setProperty(V23, "isDisabled", true);
CEBstate = 1;
}
delay(2000);
{
//STARTER
if(inverterstate == LOW){
led3.on();
digitalWrite(5,LOW); //STARTER CRANK ON D0
delay(1200); //CRANK DURATION
digitalWrite(5,HIGH); //STARTER CRANK OFF D0
led3.off();
Blynk.logEvent("generator_on");
led17.off();
}
}
}
Update,
Tried another router from a different ISP, still goes offline.
Looking at your code and serial output with debug enabled, here’s what part of it means…
This part comes from void invertertime()…
Blynk.setProperty(V10, "color", "#23C48E"); << Your code
23:16:50.354 -> [134488] <[13|04|F9|00|10]18[00]color[00]#ED9D00 << Command sent to Blynk
23:16:50.402 -> [134533] >[00|04|F9|00|C8] << Response from Blynk
Blynk.setProperty(V18, "color", "#ED9D00"); //Inverter Status (OFF) Yellow
23:16:50.450 -> [134555] <[13|04|FA|00|10]10[00]color[00]#ED9D00
23:16:50.497 -> [134656] >[00|04|FA|00|C8]
Blynk.setProperty(V2, "offLabel", "Hold to Start");
23:16:50.543 -> [134656] <[13|04|FB|00|18]2[00]offLabel[00]Hold[20]to[20]Start
23:16:50.591 -> [134702] >[00|04|FB|00|C8]
Blynk.setProperty(V2, "onLabel", "Release");
23:16:50.638 -> [134724] <[13|04|FC|00|11]2[00]onLabel[00]Release
23:16:50.684 -> [134768] >[00|04|FC|00|C8]
led16.off(); //Inverter Shutoff Indicator OFF
23:16:50.732 -> [134791] <[14|04|FD|00|07]vw[00]20[00]0
*** From void CEBsensor1() …"
Blynk.virtualWrite(V12, CEBsensor);
23:16:51.013 -> [135152] <[14|04|FE|00|07]vw[00]12[00]0
led13.off(); //Shutoff Indicator OFF
23:16:51.061 -> [135220] <[14|04|FF|00|07]vw[00]13[00]0
The commands from void invertertime() repeat again 1 second after the first time…
23:16:51.153 -> [135287] <[13|05|00|00|10]14[00]color[00]#23C48E
23:16:51.200 -> [135331] >[00|05|00|00|C8]
23:16:51.200 -> [135354] <[13|05|01|00|0F]23[00]isDisabled[00]1
23:16:51.247 -> [135400] >[00|05|01|00|C8]
23:16:51.294 -> [135421] <[13|05|02|00|0F]22[00]isDisabled[00]1
23:16:51.342 -> [135468] >[00|05|02|00|C8]
23:16:51.387 -> [135488] <[13|05|03|00|10]18[00]color[00]#ED9D00
23:16:51.434 -> [135533] >[00|05|03|00|C8]
23:16:51.434 -> [135555] <[13|05|04|00|10]10[00]color[00]#ED9D00
23:16:51.529 -> [135656] >[00|05|04|00|C8]
23:16:51.529 -> [135656] <[13|05|05|00|18]2[00]offLabel[00]Hold[20]to[20]Start
23:16:51.624 -> [135701] >[00|05|05|00|C8]
23:16:51.624 -> [135724] <[13|05|06|00|11]2[00]onLabel[00]Release
23:16:51.671 -> [135769] >[00|05|06|00|C8]
23:16:51.719 -> [135791] <[14|05|07|00|07]vw[00]20[00]0
The commands from void CEBsensor1()) repeat again 1 second after the first time, even though your sketch has them on a 5 second timer…
23:16:52.000 -> [136152] <[14|05|08|00|07]vw[00]12[00]0
23:16:52.046 -> [136220] <[14|05|09|00|07]vw[00]13[00]0
23:16:52.141 -> [136287] <[13|05|0A|00|10]14[00]color[00]#23C48E
23:16:52.188 -> [136331] >[00|05|0A|00|C8]
I’m not sure why the void CEBsensor1())
code is being repeated every second instead of every 5 seconds - maybe you changed the code?
What is clear is that your code is very badly written, because you’re repeating the same commands to update the status and properties of your widgets, even if they are already displaying the correct information.
You also still have lots of delays scattered throughout your code, which doesn’t help when it comes to Blynk disconnections.
Taking a step back though, have you tried running a simple sketch which uses a timer to push millis()/1000
to a label widget?
This will prove if the issue is with your router/ISP or with your sketch.
Pete.
Also, I’d suggest that you change the way that you format your code when you use nested if
statements. This is almost impossible to read…
void invertertime()
{
if(CEBstate == LOW){
if(inverterstate == HIGH){
led15.on();
Blynk.setProperty(V10, "color", "#23C48E");
Blynk.setProperty(V18, "color", "#23C48E"); //Inverter Status (ON) GREEN
digitalWrite(13,HIGH); //INV RELAY ON D7
delay(100);
Blynk.setProperty(V2, "offLabel", "OFF Inverter Before Starting");
Blynk.setProperty(V2, "onLabel", "OFF Inverter!");
} else {
Blynk.setProperty(V18, "color", "#ED9D00"); //Inverter Status (OFF) Yellow
Blynk.setProperty(V10, "color", "#ED9D00");
digitalWrite(13,LOW); //INV RELAY OFF D7
delay(100);
Blynk.setProperty(V2, "offLabel", "Hold to Start");
Blynk.setProperty(V2, "onLabel", "Release");
}
} else {
}
if(inverterstate == HIGH && CEBsensor ==LOW){
led16.on(); //Inverter Shutoff Indicator ON
} else {
led16.off(); //Inverter Shutoff Indicator OFF
}
}
void runtime()
{
if(CEBstate == HIGH && Timerstate == HIGH){
times = ((millis() - msec));
Blynk.setProperty(V16, "label", "Current Generator Run Time");
Blynk.setProperty(V17, "label", "Current Fuel Consumption");
{
String readableTime;
getReadableTime(readableTime);
Blynk.virtualWrite(V16, readableTime);
Blynk.virtualWrite(V17, 1.7 * ((millis() - msec)/1000)/3600);
delay(100);
}
} else {
}
if(InvTimerstate == HIGH && CEBstate == LOW && Timerstate == LOW){
times = ((millis() - msec2));
Blynk.setProperty(V16, "label", "Inverter Run Time");
{
String readableTime;
getReadableTime(readableTime);
Blynk.virtualWrite(V16, readableTime);
}
delay(100);
} else {
}
}
Using indents sensibly (the Arduino IDE Tools > Auto Format will do most of the work for you) and adding some narrative will make the code much easier to follow. As you can (now) see there is an inconsistency about how you’ve written the last part of the code in this function…
void invertertime()
{
if (CEBstate == LOW)
{
if (inverterstate == HIGH)
{
// we get here if CEBstate == LOW and inverterstate == HIGH
led15.on();
Blynk.setProperty(V10, "color", "#23C48E");
Blynk.setProperty(V18, "color", "#23C48E"); //Inverter Status (ON) GREEN
digitalWrite(13, HIGH); //INV RELAY ON D7
delay(100);
Blynk.setProperty(V2, "offLabel", "OFF Inverter Before Starting");
Blynk.setProperty(V2, "onLabel", "OFF Inverter!");
}
else
{
// we get here if CEBstate == LOW and inverterstate == LOW
Blynk.setProperty(V18, "color", "#ED9D00"); //Inverter Status (OFF) Yellow
Blynk.setProperty(V10, "color", "#ED9D00");
digitalWrite(13, LOW); //INV RELAY OFF D7
delay(100);
Blynk.setProperty(V2, "offLabel", "Hold to Start");
Blynk.setProperty(V2, "onLabel", "Release");
}
}
else
{
// we get here if CEBstate == HIGH
// but we do nothing! maybe the code below should be incorportated here?
}
if (inverterstate == HIGH && CEBsensor == LOW)
{
// we get here if CEBstate == HIGH and CEBsensor == LOW
led16.on(); //Inverter Shutoff Indicator ON
}
else
{
// we get here with any other combination of CEBstate and CEBsensor, eg -
// CEBstate == HIGH and CEBsensor == LOW
// CEBstate == LOW and CEBsensor == LOW
// CEBstate == LOW and CEBsensor == HIGH
led16.off(); //Inverter Shutoff Indicator OFF
}
}
A few other things…
Don’t assign a value to the variable that will hold your timer ID…
These are assigned by the BlynkTimer library and are zero based.
There used to be a bug regarding timer ID’s, which was solved using a sacrificial timer, but I’m not sure if the bug still exists. More info here…
The way that you’re using aliases for your virtual pins makes no sense…
You’d be far better doing this…
//Blynk LED Widgets
WidgetLED COIL_LED(V3);
WidgetLED FUEL_LED(V7);
WidgetLED STARTER_LED(V4);
WidgetLED GENERATOR_SHUTOFF_LED (V13);
WidgetLED CEB_STATUS_LED(V14);
WidgetLED lNVERTER_STATUS_LED(V18);
WidgetLED INVERTER_SHUTOFF_LED(V20);
WidgetLED CHANGEOVER_RELEASE_INDICATOR(V24);
That way, you’ll be using meaningful names within your code, rather than simply mapping one meaningless number to another.
You also seem to have one widget that’s not mapped, and which you address directly…
Blynk.virtualWrite(V12, CEBsensor);
Pete.
Pete I really do appriciate the feedback and I will try to make the suggested improvements.
However I am still puzzled to why the board disconnects from blynks servers even when using the blank example with only the credentials?!
Turn on debugging for that sketch, and post the results and the sketch.
Pete.
I switched to a ESP32-WROOM for testing. Will update if this board also crashes with the following code, which the D1 mini did.
/*************************************************************
Blynk is a platform with iOS and Android apps to control
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
You can easily build mobile and web interfaces for any
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: https://www.blynk.io
Sketch generator: https://examples.blynk.cc
Blynk community: https://community.blynk.cc
Follow us: https://www.fb.com/blynkapp
https://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
This example runs directly on ESP32 chip.
NOTE: This requires ESP32 support package:
https://github.com/espressif/arduino-esp32
Please be sure to select the right ESP32 module
in the Tools -> Board menu!
Change WiFi ssid, pass, and Blynk auth token to run :)
Feel free to apply it to any other example. It's simple!
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
/* Fill in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME "TEST"
#define BLYNK_AUTH_TOKEN ""
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop()
{
Blynk.run();
}
Well there was zero difference and the boards still go offline and continously attempt to connect to blynk servers. I’m loosing my mind here!
Can we both agree that it isnt the code thats causing this and start looking at the probability that its something to do with Blynks servers in my region?!