/* Comment this out to disable prints and save space */
#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[] = "uugygyfyuihojojo"; // Token
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxx";//ชื่อ wifi
char pass[] = "xxxxx"; //รหัส wifi
// Set your LED and physical button pins here
const int ledPin1 = 16;
const int ledPin2 = 5;
const int ledPin3 = 4;
const int ledPin4 = 0;
const int ledPin5 = 2;
const int ledPin6 = 15;
const int btnPin1 = 1;
const int btnPin2 = 14;
const int btnPin3 = 12;
const int btnPin4 = 13;
BlynkTimer timer;
void checkPhysicalButton1();
void checkPhysicalButton2();
void checkPhysicalButton3();
void checkPhysicalButton4();
int ledState1 = LOW;
int btnState1 = HIGH;
int ledState2 = LOW;
int btnState2 = HIGH;
int ledState3 = LOW;
int btnState3 = HIGH;
int ledState4 = LOW;
int btnState4 = HIGH;
// Every time we connect to the cloud...
BLYNK_CONNECTED() {
Blynk.syncAll();
// Request the latest state from the server
Blynk.syncVirtual(V7);
Blynk.syncVirtual(V8);
Blynk.syncVirtual(V9);
Blynk.syncVirtual(V10);
const int ledPin5 = 2;
const int ledPin6 = 15;
}
// Alternatively, you could override server state using:
// Blynk.virtualWrite(V4, ledState);
// When App button is pushed - switch the state
BLYNK_WRITE(V7) {
ledState1 = param.asInt();
digitalWrite(ledPin1, ledState1);
}
BLYNK_WRITE(V8) {
ledState2 = param.asInt();
digitalWrite(ledPin2, ledState2);
}
BLYNK_WRITE(V9) {
ledState3 = param.asInt();
digitalWrite(ledPin3, ledState3);
}
BLYNK_WRITE(V10) {
ledState4 = param.asInt();
digitalWrite(ledPin4, ledState4);
}
void checkPhysicalButton1()
{
if (digitalRead(btnPin1) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState1 != LOW) {
// Toggle LED state
ledState1 = !ledState1;
digitalWrite(ledPin1, ledState1);
// Update Button Widget
Blynk.virtualWrite(V7, ledState1);
}
btnState1 = LOW;
} else {
btnState1 = HIGH;
}
}
void checkPhysicalButton2()
{
if (digitalRead(btnPin2) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState2 != LOW) {
// Toggle LED state
ledState2 = !ledState2;
digitalWrite(ledPin2, ledState2);
// Update Button Widget
Blynk.virtualWrite(V8, ledState2);
}
btnState2 = LOW;
} else {
btnState2 = HIGH;
}
}
void checkPhysicalButton3()
{
if (digitalRead(btnPin3) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState3 != LOW) {
// Toggle LED state
ledState3 = !ledState3;
digitalWrite(ledPin3, ledState3);
// Update Button Widget
Blynk.virtualWrite(V9, ledState3);
}
btnState3 = LOW;
} else {
btnState3 = HIGH;
}
}
void checkPhysicalButton4()
{
if (digitalRead(btnPin4) == LOW) {
// btnState is used to avoid sequential toggles
if (btnState4 != LOW) {
// Toggle LED state
ledState4 = !ledState4;
digitalWrite(ledPin4, ledState4);
// Update Button Widget
Blynk.virtualWrite(V10, ledState4);
}
btnState4 = LOW;
} else {
btnState4 = HIGH;
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
Serial.print("Conencting.");
if (!Blynk.connect()) {
Serial.print(".");
}
Blynk.connect();
pinMode(ledPin1, OUTPUT);
pinMode(btnPin1, INPUT_PULLUP);
digitalWrite(ledPin1, ledState1);
pinMode(ledPin2, OUTPUT);
pinMode(btnPin2, INPUT_PULLUP);
digitalWrite(ledPin2, ledState2);
pinMode(ledPin3, OUTPUT);
pinMode(btnPin3, INPUT_PULLUP);
digitalWrite(ledPin3, ledState3);
pinMode(ledPin4, OUTPUT);
pinMode(btnPin4, INPUT_PULLUP);
digitalWrite(ledPin4, ledState4);
// Setup a function to be called every 100 ms
timer.setInterval(100L, checkPhysicalButton1);
timer.setInterval(100L, checkPhysicalButton2);
timer.setInterval(100L, checkPhysicalButton3);
timer.setInterval(100L, checkPhysicalButton4);
}
void loop()
{
Blynk.run();
timer.run();
}
เพิ่มการตั้งค่านี้คือยังไงครับ เพิ่ม ssid2 pass2 หรือว่าต้องการเพิ่มอะไรที่ไม่ใช้ ssid หรือ pass เข้าไปในหน้านั้นด้วยเช่น id ที่เราตั้งขึ้นมาเอง
ลองดู NODE MCU ESP 8266 + AP CONFIG แบบกดปุ่มตั้งค่า + Blynk SERVER ว่าใช่อย่างที่ต้องการหรือปล่าวครับ