Hi all.
I need sketch for ESP8266 (nodemcu) to sync physical button on other ESP’s. for example when I pushed physical button on one ESP, then all other ESP’s GPIO2 turning on.
thanks & sorry for bad english
Hi all.
I need sketch for ESP8266 (nodemcu) to sync physical button on other ESP’s. for example when I pushed physical button on one ESP, then all other ESP’s GPIO2 turning on.
thanks & sorry for bad english
thanks for reply. but I need for ESP and how this work ? which pin is for physical button and which for GPIO2 ?
@Dmitriy
You may use this example with little changes with ESP - https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=Widgets%2FBridge
thanks for reply. I solved my problem with Eventor. I set same auth token on all esp with eventor
and final question: How can I change physical button mode to push in sketch ?
You mean pin mode?
No. when I pushed physical button the LED is keep on but I want turn on a moment
You need to send 2 commands. One with HIGH and second one with LOW.
Can you help me to edit my sketch ?
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
//#define BLYNK_PRINT Serial // Defines the object that is used for printing
//#define BLYNK_DEBUG // Optional, this enables more detailed prints
#define VPIN V2
char auth[] = "xxxx"; //blynk auth token
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxx";
char pass[] = "xxxx";
void lightOn();
void lightOff();
boolean LampState = 0;
boolean SwitchReset = true;
const int TacSwitch = D5;
const int RelayPin = D6;
SimpleTimer timer;
WidgetLED VLED(V12);
void setup()
{
Serial.begin(115200);
pinMode(RelayPin, OUTPUT);
pinMode(TacSwitch, INPUT_PULLUP);
delay(10);
digitalWrite(RelayPin, LOW);
Blynk.begin(auth, ssid, pass);
timer.setInterval(100, ButtonCheck);
}
void loop()
{
Blynk.run();
timer.run();
}
void ButtonCheck() {
boolean SwitchState = (digitalRead(TacSwitch));
if (!SwitchState && SwitchReset == true) {
if (LampState) {
lightOff();
} else {
lightOn();
}
SwitchReset = false;
delay(50);
}
else if (SwitchState) {
SwitchReset = true;
}
}
void ToggleRelay() {
LampState = !LampState;
if (LampState) {
lightOn();
}
else lightOff();
}
void lightOn() {
digitalWrite(RelayPin, LOW);
LampState = 1;
Blynk.virtualWrite(VPIN, HIGH);
VLED.off();
}
void lightOff() {
digitalWrite(RelayPin, HIGH);
LampState = 0;
Blynk.virtualWrite(VPIN, LOW);
VLED.on();
}
BLYNK_WRITE(VPIN) {
int SwitchStatus = param.asInt();
if (SwitchStatus == 2){
ToggleRelay();
}
else if (SwitchStatus){
lightOn();
}
else lightOff();
}
Help you with what exactly?
Please realise that most everyone here have their own code/project/life to troubleshoot, so not too many can take the time to sift through your entire code to first find and then fix whatever is apparently wrong.
Help me how to add push mode physical key to my sketch !
Have you checked out any of the Sketch Builder examples?
Its worked but I need timer on pushed button. I want to turn on GPIO for 5 second when I pushed physical button
Well you are already using timers, so you should understand how to add another to run for 5 seconds, after button push, and then turn off GPIO 5.
Here is one example of a basic timer snippet for an Action - Delay - Action function:
BLYNK_WRITE(Vx) { // Virtual button on Vx to activate action
int BTN = param.asInt();
if (BTN == 1) {
ActionON; // Run ActionON function
}
}
void ActionON() {
digitalWrite(pin, HIGH); // Set pin high
timer.setTimer(5000L, ActionOFF); // Run ActionOFF function in 5 seconds
}
void ActionOFF() {
digitalWrite(pin, LOW); // Set pin Low
}
thanks the problem is solved.
May God be pleased with you