ผมมี NodeMCU ESP8266 V3 อยู่สองตัว อยากจะสั่งเปิด Led จากอีกตัวหนึ่งโดยใช้ผ่าน Blynk ครับ

Ex.MCU1 สั่งเปิด Led ผ่าน Blynk เปิด Led ที่ MCU2 โดยใช้ physical button เป็นตัวปิดเปิดครับ
ผมทดลองอัพโค้ดทั้งสองตัวเหมือนกัน ถ้ากดเปิด Led จาก Blynk Led ก็จะติดทั้งสอง node ครับ แต่กดจาก physical button จะเป็นการ updatewidget เฉยๆ :sweat_smile:

วางภาพการต่อและโค้ตที่ใช้ด้วยครับข้อมูลน้อยไป


#define BLYNK_TEMPLATE_ID “TMPLA7oTkObH”
#define BLYNK_DEVICE_NAME “Test”
#define BLYNK_AUTH_TOKEN “iP7N484GZj7ln2Zz6xKWDUV45H4IrnER”
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.
// Set password to “” for open networks.
char ssid[] = “wifi”;
char pass[] = “12345678”;
const int ledPin = 0;
const int btnPin = 2;

BlynkTimer timer;
void checkPhysicalButton();

int ledState = LOW;
int btnState = HIGH;

// Every time we connect to the cloud…
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(V0);
Blynk.syncVirtual(V1);

// Alternatively, you could override server state using:
//Blynk.virtualWrite(V2, ledState);
}

// When App button is pushed - switch the state
BLYNK_WRITE(V0) {
ledState = param.asInt();
digitalWrite(ledPin, ledState);
}
BLYNK_WRITE(V1) {
ledState = param.asInt();
digitalWrite(ledPin, ledState);
}

void checkPhysicalButton()
{
if (digitalRead(btnPin) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState != LOW) {

  // Toggle LED state
  ledState = !ledState;
  digitalWrite(ledPin, ledState);

  // Update Button Widget
  Blynk.virtualWrite(V0, ledState);
}
btnState = LOW;

} else {
btnState = HIGH;
}
}

void setup()
{
// Debug console
Serial.begin(115200);

Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, “blynk.cloud”, 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

pinMode(ledPin, OUTPUT);
pinMode(btnPin, INPUT_PULLUP);
digitalWrite(ledPin, ledState);

// Setup a function to be called every 100 ms
timer.setInterval(100L, checkPhysicalButton);
}

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

ถ้ากดเปิดจาก Blynk ไฟทั้งสองติดครับ แต่จะให้กดปุ่มแล้วไฟอีกตัวติดผมก็ไปต่อไม่เป็นเลยครับ