Browse Source

Integrated HTTP server (hello world page)

master
Youen Toupin 3 years ago
parent
commit
2ea7220173
  1. 1
      .gitignore
  2. 41
      ESP32/vehicle-monitor.cpp
  3. 7
      ESP32/wifi-credentials.h.template

1
.gitignore vendored

@ -3,3 +3,4 @@
/schema/*/*-backups /schema/*/*-backups
/.metadata/ /.metadata/
/ESP32/wifi-credentials.h

41
ESP32/vehicle-monitor.cpp

@ -3,15 +3,48 @@
#include <WiFi.h> #include <WiFi.h>
#include <ESPAsyncWebServer.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() void setup()
{ {
Serial.begin(115200); 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...");
} }
void loop() // Print ESP Local IP Address
Serial.print("Wifi connected, ip=");
Serial.println(WiFi.localIP());
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
{ {
Serial.printf("ESP32 Chip model = %s Rev %d\n", ESP.getChipModel(), ESP.getChipRevision()); request->send(200, "text/html", index_html);
Serial.printf("This chip has %d cores\n", ESP.getChipCores()); });
server.begin();
Serial.println("HTTP server started");
}
delay(3000); void loop()
{
delay(1000);
} }

7
ESP32/wifi-credentials.h.template

@ -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…
Cancel
Save