Arduino: NodeMCU + Relay + Blynk

Подключаем NodeMCU к серверу Blynk и управляем реле.

#define pinRel D0
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "blynk_id";
char ssid[] = "ssid";
char pass[] = "password";

WidgetLED led1(V1);
BLYNK_READ(V0) {
  Blynk.virtualWrite(V0, digitalRead(pinRel));
  if (digitalRead(pinRel) == 0) {
    led1.on();
    } else {
      led1.off();
      }
}

void setup() {
  Blynk.begin(auth, ssid, pass, "server_blynk", 8442);
  pinMode(pinRel,OUTPUT);
  digitalWrite(pinRel, HIGH);
}

void loop() {
  Blynk.run();
}
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define pinRel D0

char auth[] = "token";
char ssid[] = "ssid";
char pass[] = "pass";

BlynkTimer timer;
WidgetLED led1(V1);

void relLed()
{  if (digitalRead(pinRel) == 0) {
    led1.on();
    } else {
      led1.off();
      }
}

BLYNK_WRITE(V0)
{
  int pinValue = param.asInt();
  if (pinValue == -9999) {
    digitalWrite(pinRel, HIGH);
    Serial.println(pinValue);
    } else {
      digitalWrite(pinRel, LOW);
      Serial.println(pinValue);
      }
}

void setup() {
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass, "62.176.17.5", 8442);
  pinMode(pinRel,OUTPUT);
  digitalWrite(pinRel, HIGH);
  timer.setInterval(1000L, relLed);
}

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