2018年11月11日 星期日

ESP32 to Control LED With Blynk Via WiFi

ESP32 to Control LED With Blynk Via WiFi


#define BLYNK_PRINT Serial

int LEDpin        = 2;   //build in LED

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
//char ssid[] = "Your network name";
//char pass[] = "Your network password";
char ssid[] = "alex9ufo";
char pass[] = "alex9981";
//===========================================
WidgetLED led1(V1); //register to virtual pin 1
void led_status() { 
     Serial.print("Blynk LED pin status :");
     int pinvalue = digitalRead (LEDpin);
     Serial.println(String(pinvalue).c_str());
    if (pinvalue==HIGH){
        led1.on();
        }
    else{
        led1.off();
      }
}
//===========================================
void setup() {  
  pinMode(LEDpin, OUTPUT); 
  pinMode(LEDpin, HIGH);
  Serial.begin(115200);

  delay(10);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi connected");  
  Blynk.begin(auth , ssid, pass);

}
//===========================================
void loop(){
    Blynk.run();
    led_status(); 
    
}
//===========================================













沒有留言:

張貼留言

WOKWI LED + MQTT Node-Red SQLite

WOKWI LED + MQTT Node-Red SQLite const char *mqtt_broker = "broker.mqtt-dashboard.com" ; const char *topic1 = "alex9ufo/e...