ESPmanager-example.ino 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*-------------------------------------------------------------------------------------------------------
  2. Example ESP Manager software..
  3. BeerWare Licence, just give due credits
  4. Upload files to the ESP using this command (on mac and linux anyway, can upload using serial via SPIFFS data upload too)
  5. for file in `ls -A1`; do curl -F "file=@$PWD/$file" X.X.X.X/espman/upload; done
  6. * Thanks to me-no-dev
  7. --------------------------------------------------------------------------------------------------------*/
  8. #include <FS.h> // Settings saved to SPIFFS
  9. #include <ESP8266WiFi.h>
  10. #include <ESP8266HTTPClient.h>
  11. #include <ESP8266httpUpdate.h>
  12. #include <ESPAsyncTCP.h>
  13. #include <ESPAsyncWebServer.h>
  14. #include <AsyncJson.h>
  15. #include <ArduinoOTA.h>
  16. #include <ArduinoJson.h> // required for settings file to make it readable
  17. #include <Hash.h>
  18. #include <ESP8266mDNS.h>
  19. #include <ESPmanager.h>
  20. AsyncWebServer HTTP(80);
  21. ESPmanager settings(HTTP, SPIFFS);
  22. // You can specify a default hard coded set of credentials
  23. /*
  24. const char * defaultSSID = "";
  25. const char * defaultPSK = "";
  26. ESPmanager settings(HTTP, SPIFFS, "ESPManager", defaultSSID , defaultPSK);
  27. */
  28. void setup()
  29. {
  30. Serial.begin(115200);
  31. SPIFFS.begin();
  32. Serial.println("");
  33. Serial.println(F("Example ESPconfig - using ESPAsyncWebServer"));
  34. Serial.printf("Sketch size: %u\n", ESP.getSketchSize());
  35. Serial.printf("Free size: %u\n", ESP.getFreeSketchSpace());
  36. settings.begin();
  37. // This rewrite is active when the captive portal is working, and redirects the root / to the setup wizard.
  38. // This has to go in the main sketch to allow your project to control the root when using ESPManager.
  39. HTTP.rewrite("/", "/espman/setup.htm").setFilter( [](AsyncWebServerRequest * request) {
  40. return settings.portal();
  41. });
  42. // then use this rewrite and serve static to serve your index file(s)
  43. HTTP.rewrite("/", "/index.htm");
  44. HTTP.serveStatic("/index.htm", SPIFFS, "/index.htm");
  45. HTTP.begin();
  46. Serial.print(F("Free Heap: "));
  47. Serial.println(ESP.getFreeHeap());
  48. }
  49. void loop()
  50. {
  51. settings.handle();
  52. }