Improve simple_web
This commit is contained in:
parent
66a64dbd59
commit
23621f4a5e
|
@ -18,7 +18,7 @@
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
|
|
||||||
const char* ssid = "*******";
|
const char* ssid = "*******";
|
||||||
const char* password = "*******";
|
const char* password = "********";
|
||||||
|
|
||||||
const char* PARAM_MESSAGE = "message";
|
const char* PARAM_MESSAGE = "message";
|
||||||
|
|
||||||
|
@ -32,24 +32,24 @@ void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
Serial.printf("WiFi Failed!\n");
|
delay(500);
|
||||||
return;
|
Serial.print(".");
|
||||||
}
|
}
|
||||||
|
Serial.println("Connected");
|
||||||
Serial.print("IP Address: ");
|
Serial.print("IP Address: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
request->send(200, "text/html", "<a href=\"/on\">Turn the LED ON</a><a href=\"/off\">Turn the LED OFF</a>");
|
request->send(200, "text/html", "<button onclick=\"fetch('http://192.168.178.198/on')\">Turn LED ON</button> <button onclick=\"fetch('http://192.168.178.198/off')\">Turn LED OFF</button>");
|
||||||
});
|
});
|
||||||
server.on("/on", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/on", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
request->send(200, "text/html", "<a href=\"/on\">Turn the LED ON</a><a href=\"/off\">Turn the LED OFF</a>");
|
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
digitalWrite(LED_BUILTIN, HIGH);
|
||||||
|
request->send(200, "text/plain", "Was there ever anything here?");
|
||||||
});
|
});
|
||||||
server.on("/off", HTTP_GET, [](AsyncWebServerRequest *request){
|
server.on("/off", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||||
request->send(200, "text/html", "<a href=\"/on\">Turn the LED ON</a><a href=\"/off\">Turn the LED OFF</a>");
|
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
|
request->send(200, "text/plain", "Was there ever anything here?");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send a GET request to <IP>/get?message=<message>
|
// Send a GET request to <IP>/get?message=<message>
|
||||||
|
|
Loading…
Reference in a new issue