This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
// put your setup code here, to run once: | |
pinMode(LED_BUILTIN, OUTPUT); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
digitalWrite(LED_BUILTIN, LOW); | |
delay(1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(115200); | |
//The SSID must be >8 characters and <64 characters | |
//I'm adding the chip ID onto the end to get a unique (ish) name | |
String ssid = "ESP8266 " + String(ESP.getChipId(), HEX); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <ESP8266WebServer.h> | |
ESP8266WebServer webServer(80); | |
void setup() { | |
//Put your setup code here, to run once: | |
Serial.begin(115200); | |
//Add the chip ID onto the end to get a unique (ish) name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
webServer.on("/", [](){ | |
webServer.send(200, "text/plain", "Hello World"); | |
}); | |
webServer.begin(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop() { | |
// put your main code here, to run repeatedly: | |
webServer.handleClient(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WebServer.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ESP8266WebServer webServer(80); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a simple homepage | |
webServer.on("/", servePage); | |
// Handle any incomming arguments | |
webServer.on("/args", handleArgs); | |
// Redirect all unknown traffic back to the homepage | |
webServer.onNotFound([](){ | |
webServer.sendHeader("Location","/"); | |
webServer.send(303); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void servePage() { | |
// Create a basic webpage | |
String htmlPage; | |
htmlPage += "<a href='/args?led=toggle'><button>Toggle LED</button></a>\r\n"; | |
// Serve the webpage when requested | |
webServer.send(200, "text/html", htmlPage); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void handleArgs() { | |
// Create a string containing all the arguments, send them out to the serial port | |
String message = "#Args:" + String(webServer.args()) + "\n"; | |
for (int i = 0; i < webServer.args(); i++) | |
message += webServer.argName(i) + ": "+ webServer.arg(i) + "\n"; | |
Serial.print(message); | |
// Look for a specific argument and toggle the LED is required | |
for (int i = 0; i < webServer.args(); i++) | |
if((webServer.argName(i) == "led") && (webServer.arg(i) == "toggle")) |
OlderNewer