endpoints.ino 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //Handlers for Web Server
  2. void handle_index() {
  3. server.send(200, "text/html", "[OK] - hds 4-way relay module");
  4. }
  5. void handle_status() {
  6. DynamicJsonDocument doc(256);
  7. //doc["relay1"] = relayStatus[0] ? true : false;
  8. //doc["relay2"] = relayStatus[1] ? true : false;
  9. //doc["relay3"] = relayStatus[2] ? true : false;
  10. //doc["relay4"] = relayStatus[3] ? true : false;
  11. String json;
  12. serializeJson(doc, json);
  13. server.send(200, "application/json", json.c_str());
  14. }
  15. void handle_deviceInfo() {
  16. // Open the file in read mode
  17. File file = LittleFS.open("/config.json", "r");
  18. if (!file) {
  19. // If the file doesn't exist, send a 404 Not Found response
  20. server.send(404, "application/json", "{\"error\":\"device config missing from firmware\"}");
  21. return;
  22. }
  23. String fileContent = "";
  24. while (file.available()) {
  25. fileContent += (char)file.read();
  26. }
  27. file.close();
  28. server.send(200, "application/json", fileContent);
  29. }
  30. void handle_uuid() {
  31. server.send(200, "application/json", "\"" + deviceUUID + "\"");
  32. }