12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #define DEBUG_SERIAL
- #ifdef DEBUG_SERIAL
- #define DEBUG_BEGIN Serial.begin(115200)
- #define DEBUG_PRINT(x) Serial.println(x)
- #else
- #define DEBUG_PRINT(x)
- #define DEBUG_BEGIN
- #endif
- #include <PersWiFiManager.h>
- #include <ArduinoJson.h>
- #include <ESP8266WiFi.h>
- #include <ESP8266SSDP.h>
- #include <SPIFFSReadServer.h>
- #include <DNSServer.h>
- #include <FS.h>
- #define DEVICE_NAME "ESP8266 DEVICE"
- SPIFFSReadServer server(80);
- DNSServer dnsServer;
- PersWiFiManager persWM(server, dnsServer);
- int x;
- String y;
- void setup() {
- DEBUG_BEGIN;
- DEBUG_PRINT();
-
- SPIFFS.begin();
-
- persWM.setApCredentials(DEVICE_NAME);
-
- persWM.begin();
-
- server.on("/api", []() {
- DEBUG_PRINT("server.on /api");
- if (server.hasArg("x")) {
- x = server.arg("x").toInt();
- DEBUG_PRINT(String("x: ")+x);
- }
- if (server.hasArg("y")) {
- y = server.arg("y");
- DEBUG_PRINT("y: "+y);
- }
-
- StaticJsonBuffer<200> jsonBuffer;
- JsonObject &json = jsonBuffer.createObject();
- json["x"] = x;
- json["y"] = y;
- char jsonchar[200];
- json.printTo(jsonchar);
- server.send(200, "application/json", jsonchar);
- });
-
- server.on("/description.xml", HTTP_GET, []() {
- SSDP.schema(server.client());
- });
- SSDP.setSchemaURL("description.xml");
- SSDP.setHTTPPort(80);
- SSDP.setName(DEVICE_NAME);
- SSDP.setURL("/");
- SSDP.begin();
- SSDP.setDeviceType("upnp:rootdevice");
- server.begin();
- DEBUG_PRINT("setup complete.");
- }
- void loop() {
- dnsServer.processNextRequest();
- server.handleClient();
-
- }
|