อธิบายโค้ดอันนี้ให้ผมหน่อยได้ไหมครับว่าตรงไหนทำอะไรได้วงเล็บให้หน่อยจะเอาไปส่งอาจารย์ครับ
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
const char* ssid = "WIFI_SSID";
const char* password = "WIFI_PASSWORD";
const IPAddress ip(192, 168, 1, 100);
const IPAddress subnet(255, 255, 255, 0);
const IPAddress gt(192, 168, 1, 1);
const int SwitchPin = 12; // GPIO12
int SwitchValue = HIGH;
ESP8266WebServer server(80);
void handleNotFound(){
//server.send(404, "text/plain", "404 Not Found");
if(SwitchValue == HIGH) {
server.send(200, "text/plain", "ON");
}else{
server.send(200, "text/plain", "OFF");
}
delay(1000);
}
void setup(void){
// Set Output PIN
pinMode(SwitchPin, OUTPUT);
digitalWrite(SwitchPin, SwitchValue);
// Connect WiFi
WiFi.mode(WIFI_STA);
WiFi.config(ip, gt, subnet);
WiFi.begin(ssid, password);
// Wait for connection
while(WiFi.status() != WL_CONNECTED){
delay(1000);
}
server.on("/", [](){
if(SwitchValue == HIGH) {
server.send(200, "text/plain", "ON");
}else{
server.send(200, "text/plain", "OFF");
}
delay(1000);
});
server.on("/ON", [](){
SwitchValue = HIGH;
server.send(200, "text/plain", "ON");
digitalWrite(SwitchPin, SwitchValue);
delay(1000);
});
server.on("/OFF", [](){
SwitchValue = LOW;
server.send(200, "text/plain", "OFF");
digitalWrite(SwitchPin, SwitchValue);
delay(1000);
});
server.onNotFound(handleNotFound);
server.begin();
}
void loop(void){
server.handleClient();
}
ช่วยบอกโค้ดให้หน่อยครับ
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
const char* ssid = "WIFI_SSID";
const char* password = "WIFI_PASSWORD";
const IPAddress ip(192, 168, 1, 100);
const IPAddress subnet(255, 255, 255, 0);
const IPAddress gt(192, 168, 1, 1);
const int SwitchPin = 12; // GPIO12
int SwitchValue = HIGH;
ESP8266WebServer server(80);
void handleNotFound(){
//server.send(404, "text/plain", "404 Not Found");
if(SwitchValue == HIGH) {
server.send(200, "text/plain", "ON");
}else{
server.send(200, "text/plain", "OFF");
}
delay(1000);
}
void setup(void){
// Set Output PIN
pinMode(SwitchPin, OUTPUT);
digitalWrite(SwitchPin, SwitchValue);
// Connect WiFi
WiFi.mode(WIFI_STA);
WiFi.config(ip, gt, subnet);
WiFi.begin(ssid, password);
// Wait for connection
while(WiFi.status() != WL_CONNECTED){
delay(1000);
}
server.on("/", [](){
if(SwitchValue == HIGH) {
server.send(200, "text/plain", "ON");
}else{
server.send(200, "text/plain", "OFF");
}
delay(1000);
});
server.on("/ON", [](){
SwitchValue = HIGH;
server.send(200, "text/plain", "ON");
digitalWrite(SwitchPin, SwitchValue);
delay(1000);
});
server.on("/OFF", [](){
SwitchValue = LOW;
server.send(200, "text/plain", "OFF");
digitalWrite(SwitchPin, SwitchValue);
delay(1000);
});
server.onNotFound(handleNotFound);
server.begin();
}
void loop(void){
server.handleClient();
}