Created
June 14, 2020 18:54
-
-
Save yussufbiyik/10c04b4c92bc69da3b224e97a80e2bfa to your computer and use it in GitHub Desktop.
Example result from ESP8266WebServer-Creator
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 <Arduino.h> | |
#include <ESP8266WebServer.h> | |
const char* ssid = "WiFi Name"; | |
const char* password = "WiFi Password"; | |
ESP8266WebServer server(80); | |
// Home page | |
void home(){ | |
char *home = "<!DOCTYPE html>" | |
"<html lang='en'>" | |
"<head>" | |
"<meta charset='UTF-8'>" | |
"<meta name='viewport' content='width=device-width, initial-scale=1.0'>" | |
"<title>Page Title</title>" | |
"</head>" | |
"<body>" | |
"<!-- Page Content -->" | |
"</body>" | |
"</html>"; | |
server.send(200, "text/html", home); | |
} | |
// Second example page | |
void secondpage(){ | |
char *secondpage = "<!DOCTYPE html>" | |
"<html lang='en'>" | |
"<head>" | |
"<meta charset='UTF-8'>" | |
"<meta name='viewport' content='width=device-width, initial-scale=1.0'>" | |
"<title>Second Page Title</title>" | |
"</head>" | |
"<body>" | |
"<!-- Second Page Content -->" | |
"</body>" | |
"</html>"; | |
server.send(200, "text/html", secondpage); | |
} | |
// Connect WiFi and declare pages | |
void setup() { | |
Serial.begin(115200); | |
delay(10); | |
WiFi.begin(ssid,password); | |
while(WiFi.status() != WL_CONNECTED){ | |
Serial.print("Connection failed, trying again.\n"); | |
delay(500); | |
} | |
Serial.println("Connected Succesfully.\n"); | |
server.begin(); | |
Serial.print("Server is live use http://"); | |
Serial.print(WiFi.localIP()); | |
Serial.print("/"); | |
server.begin(); | |
server.on("/home", home); | |
server.on("/secondpage", secondpage); | |
} | |
void loop() { | |
server.handleClient(); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment