Virtual Pin state change disconnect

Hi,

I came up with a problem regarding my nodemcu light controll a while ago This is the regarding thread
and it looked like I solved the problem.
A few days ago I woke up in the middle of the night and my light was turned on, this happened a few times since then.
I know it has something to do with my esp disconnecting from the internet for a short time (our internet host has some struggle these times); it only turns on after the esp reconnected to the internet, but isnt turned on every time; it seems random!

I have a relay board connected to the esp and use two relays to switch between the 2 inputs for the light (to form a two-way connection, so I can controll the lights with both a switch and blynk.

What causes that problem? :frowning:

Code: (Code needed for the light is between **)


#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";


long unsigned int switchActivated;
long unsigned int switchActivated2;

BlynkTimer timer;
**int light = 0;**

void setup()
{
  // Debug console
  Serial.begin(9600);
  
  **pinMode(4, OUTPUT);**
**  pinMode(0, OUTPUT);**
  
  Blynk.begin(auth, ssid, pass);

}


**BLYNK_CONNECTED() {**
**    Blynk.syncVirtual(V3);**
}


BLYNK_WRITE(V1) //Button Widget is writing to pin V
{
  if (param.asInt()){
    switchActivated2 = millis(); 
    digitalWrite(5, HIGH);
    Blynk.virtualWrite(V1, HIGH);
    Blynk.virtualWrite(V5, 1023);
    Blynk.virtualWrite(V4, 0);
  }
}

  BLYNK_WRITE(V2) //Button Widget is writing to pin V
{
  if (param.asInt()){
    switchActivated = millis(); 
    digitalWrite(16, HIGH);
    Blynk.virtualWrite(V2, HIGH);
    Blynk.virtualWrite(V4, 1023);
    Blynk.virtualWrite(V5, 0);
  }
}

**BLYNK_WRITE(V3) //Button Widget is writing to pin V**
**{**
**  if (param.asInt()){**

**    if (light == 0) {**
**       digitalWrite(4, HIGH);**
**       digitalWrite(0, LOW);**
**       light = 1;**
**    }**
**     else  {**
**       digitalWrite(0, HIGH);**
**       digitalWrite(4, LOW);**
**       light = 0;**
**    }        **
**  }**
**}**

void loop()
{
  Blynk.run();
  timer.run();

  
  if(switchActivated > 0 && switchActivated + 20000 < millis())
{
  switchActivated = 0;
  digitalWrite(16, LOW);
   Blynk.virtualWrite(V2, LOW);
   
}

 if(switchActivated2 > 0 && switchActivated2 + 20000 < millis())
{
  switchActivated2 = 0;
  digitalWrite(5, LOW);
   Blynk.virtualWrite(V1, LOW);
   
}
}

Using GPIO0 probably isn’t a great idea:

Pete.

Hi Pete,

Oh s***, ive seen that all the pins have some sort of second functionallity but I didnt knew some where not to use.
Thank you for the info, will definitely try that tomorrow, hope it helps…

Nick

1 Like