| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #include <Arduino.h>
- #include <StringStream.h>
- #include <ArduinoJson.h>
- #ifndef _SETTINGS_H_INCLUDED
- #define _SETTINGS_H_INCLUDED
- #define XQUOTE(x) #x
- #define QUOTE(x) XQUOTE(x)
- #ifndef FIRMWARE_VARIANT
- #define FIRMWARE_VARIANT unknown
- #endif
- #ifndef MILIGHT_HUB_VERSION
- #define MILIGHT_HUB_VERSION unknown
- #endif
- #ifndef MILIGHT_MAX_STATE_ITEMS
- #define MILIGHT_MAX_STATE_ITEMS 100
- #endif
- #ifndef MILIGHT_MAX_STALE_MQTT_GROUPS
- #define MILIGHT_MAX_STALE_MQTT_GROUPS 10
- #endif
- #define SETTINGS_FILE "/config.json"
- #define SETTINGS_TERMINATOR '\0'
- #define WEB_INDEX_FILENAME "/web/index.html"
- #define MILIGHT_GITHUB_USER "sidoh"
- #define MILIGHT_GITHUB_REPO "esp8266_milight_hub"
- #define MILIGHT_REPO_WEB_PATH "/data/web/index.html"
- #define MINIMUM_RESTART_PERIOD 1
- #define DEFAULT_MQTT_PORT 1883
- enum RadioInterfaceType {
- nRF24 = 0,
- LT8900 = 1,
- };
- class GatewayConfig {
- public:
- GatewayConfig(uint16_t deviceId, uint16_t port, uint8_t protocolVersion)
- : deviceId(deviceId),
- port(port),
- protocolVersion(protocolVersion)
- { }
- const uint16_t deviceId;
- const uint16_t port;
- const uint8_t protocolVersion;
- };
- class Settings {
- public:
- Settings() :
- adminUsername(""),
- adminPassword(""),
- // CE and CSN pins from nrf24l01
- cePin(D0),
- csnPin(D8),
- resetPin(0),
- radioInterfaceType(nRF24),
- deviceIds(NULL),
- gatewayConfigs(NULL),
- numDeviceIds(0),
- numGatewayConfigs(0),
- packetRepeats(10),
- httpRepeatFactor(5),
- listenRepeats(3),
- _autoRestartPeriod(0),
- discoveryPort(48899),
- stateFlushInterval(10),
- mqttStateRateLimit(500)
- { }
- ~Settings() {
- if (deviceIds) {
- delete deviceIds;
- }
- }
- bool hasAuthSettings();
- bool isAutoRestartEnabled();
- size_t getAutoRestartPeriod();
- static void deserialize(Settings& settings, String json);
- static void load(Settings& settings);
- static RadioInterfaceType typeFromString(const String& s);
- static String typeToString(RadioInterfaceType type);
- void save();
- String toJson(const bool prettyPrint = true);
- void serialize(Stream& stream, const bool prettyPrint = false);
- void updateDeviceIds(JsonArray& arr);
- void updateGatewayConfigs(JsonArray& arr);
- void patch(JsonObject& obj);
- String mqttServer();
- uint16_t mqttPort();
- String adminUsername;
- String adminPassword;
- uint8_t cePin;
- uint8_t csnPin;
- uint8_t resetPin;
- RadioInterfaceType radioInterfaceType;
- uint16_t *deviceIds;
- GatewayConfig **gatewayConfigs;
- size_t numGatewayConfigs;
- size_t numDeviceIds;
- size_t packetRepeats;
- size_t httpRepeatFactor;
- String _mqttServer;
- String mqttUsername;
- String mqttPassword;
- String mqttTopicPattern;
- String mqttUpdateTopicPattern;
- String mqttStateTopicPattern;
- uint16_t discoveryPort;
- uint8_t listenRepeats;
- size_t stateFlushInterval;
- size_t mqttStateRateLimit;
- protected:
- size_t _autoRestartPeriod;
- template <typename T>
- void setIfPresent(JsonObject& obj, const char* key, T& var) {
- if (obj.containsKey(key)) {
- var = obj.get<T>(key);
- }
- }
- };
- #endif
|