Settings.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <Arduino.h>
  2. #include <StringStream.h>
  3. #include <ArduinoJson.h>
  4. #ifndef _SETTINGS_H_INCLUDED
  5. #define _SETTINGS_H_INCLUDED
  6. #define SETTINGS_FILE "/config.json"
  7. #define SETTINGS_TERMINATOR '\0'
  8. #define WEB_INDEX_FILENAME "/index.html"
  9. class Settings {
  10. public:
  11. Settings() :
  12. adminUsername(""),
  13. adminPassword(""),
  14. // CE and CSN pins from nrf24l01
  15. cePin(D0),
  16. csnPin(D8),
  17. deviceIds(NULL),
  18. numDeviceIds(0)
  19. { }
  20. ~Settings() {
  21. if (deviceIds) {
  22. delete deviceIds;
  23. }
  24. }
  25. bool hasAuthSettings() {
  26. return adminUsername.length() > 0 && adminPassword.length() > 0;
  27. }
  28. static void deserialize(Settings& settings, String json);
  29. static void deserialize(Settings& settings, JsonObject& json);
  30. static void load(Settings& settings);
  31. void save();
  32. String toJson(const bool prettyPrint = true);
  33. void serialize(Stream& stream, const bool prettyPrint = false);
  34. void updateDeviceIds(JsonArray& arr);
  35. void patch(JsonObject& obj);
  36. String adminUsername;
  37. String adminPassword;
  38. uint8_t cePin;
  39. uint8_t csnPin;
  40. uint16_t *deviceIds;
  41. size_t numDeviceIds;
  42. };
  43. #endif