HTTPUpdateServer.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * Ported the ESP8266HTTPUpdateServer published by Arduino-core to
  3. * provide the web browser based OTA update on the ESP32 platform.
  4. * @file HTTPUpdateServer.h
  5. * @author hieromon@gmail.com
  6. * @version 0.9.10
  7. * @date 2019-06-06
  8. * @copyright MIT license.
  9. */
  10. #ifndef __HTTP_UPDATE_SERVER_H
  11. #define __HTTP_UPDATE_SERVER_H
  12. #ifdef ARDUINO_ARCH_ESP32
  13. // This class will available only EPS32 actually.
  14. class WebServer;
  15. class HTTPUpdateServer {
  16. public:
  17. explicit HTTPUpdateServer(bool serial_debug = false) : _serial_output(serial_debug), _server(nullptr), _username(_emptyString), _password(_emptyString), _authenticated(false) {}
  18. ~HTTPUpdateServer() {}
  19. void setup(WebServer* server) { setup(server, _emptyString, _emptyString); }
  20. void setup(WebServer* server, const String& path) { setup(server, path, _emptyString, _emptyString); }
  21. void setup(WebServer* server, const String& username, const String& password) { setup(server, "/update", username, password); }
  22. void setup(WebServer* server, const String& path, const String& username, const String& password);
  23. void updateCredentials(const String& username, const String& password) { _username = username; _password = password; }
  24. protected:
  25. void _setUpdaterError();
  26. private:
  27. bool _serial_output;
  28. WebServer* _server;
  29. String _username;
  30. String _password;
  31. bool _authenticated;
  32. String _updaterError;
  33. static const String _emptyString;
  34. };
  35. #endif // !ARDUINO_ARCH_ESP32
  36. #endif // !__HTTP_UPDATE_SERVER_H