macsave.ino 937 B

12345678910111213141516171819202122232425262728293031323334353637
  1. void handleSaveMac() {
  2. if (server.hasArg("mac")) {
  3. // Extract the string from the POST request
  4. String data = server.arg("mac");
  5. // Open the file in write mode
  6. File file = LittleFS.open(DB_PATH, "w");
  7. if (!file) {
  8. server.send(500, "text/plain", "Failed to open file for writing");
  9. return;
  10. }
  11. // Write the string data to the file
  12. file.print(data);
  13. file.close();
  14. sendOK();
  15. } else {
  16. server.send(400, "text/plain", "No string provided in the request");
  17. }
  18. }
  19. void handleGetMac() {
  20. // Open the file in read mode
  21. File file = LittleFS.open(DB_PATH, "r");
  22. if (!file) {
  23. server.send(500, "text/plain", "Failed to open file for reading");
  24. return;
  25. }
  26. // Read the string data from the file
  27. String data = file.readString();
  28. file.close();
  29. // Send the string data as the json resp
  30. server.send(200, "application/json", data);
  31. }