-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3a97f2
commit 856b30a
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <ESP8266WiFi.h> | ||
#include <WiFiClient.h> | ||
#include <ESP8266WebServer.h> | ||
|
||
const char* ssid = "PSLab_ESP"; | ||
|
||
ESP8266WebServer server(80); | ||
|
||
//Simple http server to handle different requests on endpoints | ||
|
||
//Method to handle root endpoint | ||
void handleRoot() { | ||
server.send(200, "text/plain", "hello PSLab"); | ||
} | ||
|
||
//Method to handle 404 error | ||
void handleNotFound() { | ||
String message = "File Not Found\n\n"; | ||
message += "URI: "; | ||
message += server.uri(); | ||
message += "\nMethod: "; | ||
message += (server.method() == HTTP_GET) ? "GET" : "POST"; | ||
message += "\nArguments: "; | ||
message += server.args(); | ||
message += "\n"; | ||
for (uint8_t i = 0; i < server.args(); i++) { | ||
message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; | ||
} | ||
server.send(404, "text/plain", message); | ||
} | ||
|
||
void setup(void) { | ||
//Create wifi accesspoint | ||
WiFi.softAP(ssid); | ||
IPAddress myIP = WiFi.softAPIP(); | ||
|
||
//Declare endpoints here | ||
server.on("/", handleRoot); | ||
|
||
//endpoint to get vesion of PSLab | ||
server.on("/version", []() { | ||
server.send(200, "text/plain", "This will return PSLab version"); | ||
}); | ||
|
||
//end point for 404 error | ||
server.onNotFound(handleNotFound); | ||
|
||
//initiate the server | ||
server.begin(); | ||
} | ||
|
||
void loop(void) { | ||
server.handleClient(); | ||
} |