Integrated HTTP server (hello world page)
This commit is contained in:
parent
7559e78719
commit
2ea7220173
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
||||
/schema/*/*-backups
|
||||
|
||||
/.metadata/
|
||||
/ESP32/wifi-credentials.h
|
||||
|
@ -3,15 +3,48 @@
|
||||
#include <WiFi.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
||||
#include "wifi-credentials.h"
|
||||
|
||||
AsyncWebServer server(80);
|
||||
|
||||
const char index_html[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>ESP Web Server</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Hello world!</p>
|
||||
</body>
|
||||
</html>
|
||||
)rawliteral";
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
// Connect to Wi-Fi
|
||||
WiFi.begin(wifi_ssid, wifi_password);
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(1000);
|
||||
Serial.println("Connecting to Wifi...");
|
||||
}
|
||||
|
||||
// Print ESP Local IP Address
|
||||
Serial.print("Wifi connected, ip=");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||
{
|
||||
request->send(200, "text/html", index_html);
|
||||
});
|
||||
|
||||
server.begin();
|
||||
Serial.println("HTTP server started");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision());
|
||||
Serial.printf("This chip has %d cores\n", ESP.getChipCores());
|
||||
|
||||
delay(3000);
|
||||
delay(1000);
|
||||
}
|
||||
|
7
ESP32/wifi-credentials.h.template
Normal file
7
ESP32/wifi-credentials.h.template
Normal file
@ -0,0 +1,7 @@
|
||||
// To avoid saving your wifi credentials in the git repository, wifi-credentials.h.template is ignored by git
|
||||
|
||||
// Copy this file and name it wifi-credentials.h
|
||||
// Then edit your wifi SSID and password
|
||||
|
||||
const char* wifi_ssid = "REPLACE_WITH_YOUR_SSID";
|
||||
const char* wifi_password = "REPLACE_WITH_YOUR_PASSWORD";
|
Loading…
Reference in New Issue
Block a user