123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- #if defined(ARDUINO_ARCH_ESP8266)
- #include <ESP8266WiFi.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266mDNS.h>
- #include <ESP8266HTTPUpdateServer.h>
- #define HOSTIDENTIFY "esp8266"
- #define mDNSUpdate(c) do { c.update(); } while(0)
- using WebServerClass = ESP8266WebServer;
- using HTTPUpdateServerClass = ESP8266HTTPUpdateServer;
- #elif defined(ARDUINO_ARCH_ESP32)
- #include <WiFi.h>
- #include <WebServer.h>
- #include <ESPmDNS.h>
- #include "HTTPUpdateServer.h"
- #define HOSTIDENTIFY "esp32"
- #define mDNSUpdate(c) do {} while(0)
- using WebServerClass = WebServer;
- using HTTPUpdateServerClass = HTTPUpdateServer;
- #endif
- #include <WiFiClient.h>
- #include <AutoConnect.h>
- static const char AUX_AppPage[] PROGMEM = R"(
- {
- "title": "Hello world",
- "uri": "/",
- "menu": true,
- "element": [
- {
- "name": "caption",
- "type": "ACText",
- "value": "<h2>Hello, world</h2>",
- "style": "text-align:center;color:#2f4f4f;padding:10px;"
- },
- {
- "name": "content",
- "type": "ACText",
- "value": "In this page, place the custom web page handled by the sketch application."
- }
- ]
- }
- )";
- static const char* host = HOSTIDENTIFY "-webupdate";
- #define HTTP_PORT 80
- WebServerClass httpServer(HTTP_PORT);
- #define USERNAME "user"
- #define PASSWORD "pass"
- HTTPUpdateServerClass httpUpdater;
- AutoConnectAux update("/update", "Update");
- AutoConnect portal(httpServer);
- AutoConnectAux hello;
- void setup() {
- delay(1000);
- Serial.begin(115200);
- Serial.println("\nBooting Sketch...");
-
-
- httpUpdater.setup(&httpServer, USERNAME, PASSWORD);
-
- hello.load(AUX_AppPage);
- portal.join({ hello, update });
- if (portal.begin()) {
- if (MDNS.begin(host)) {
- MDNS.addService("http", "tcp", HTTP_PORT);
- Serial.printf("HTTPUpdateServer ready! Open http://%s.local/update in your browser\n", host);
- }
- else
- Serial.println("Error setting up MDNS responder");
- }
- }
- void loop() {
-
-
- mDNSUpdate(MDNS);
- portal.handleClient();
- delay(1);
- }
|