2026-01-19 16:49:54 -05:00
|
|
|
#ifndef CONFIG_SERVICE_H
|
|
|
|
|
#define CONFIG_SERVICE_H
|
2026-01-19 11:50:10 -05:00
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
#include <Preferences.h>
|
|
|
|
|
|
|
|
|
|
// ============================================
|
2026-01-19 16:49:54 -05:00
|
|
|
// Config Service
|
|
|
|
|
// Manages persistent configuration in NVS
|
2026-01-19 11:50:10 -05:00
|
|
|
// ============================================
|
2026-01-19 16:49:54 -05:00
|
|
|
class ConfigService {
|
2026-01-19 11:50:10 -05:00
|
|
|
public:
|
2026-01-19 16:49:54 -05:00
|
|
|
static ConfigService& getInstance();
|
|
|
|
|
|
|
|
|
|
// Prevent copying
|
|
|
|
|
ConfigService(const ConfigService&) = delete;
|
|
|
|
|
ConfigService& operator=(const ConfigService&) = delete;
|
2026-01-19 11:50:10 -05:00
|
|
|
|
|
|
|
|
// Load config from NVS
|
|
|
|
|
bool load();
|
|
|
|
|
|
|
|
|
|
// Save config to NVS
|
|
|
|
|
void save();
|
|
|
|
|
|
|
|
|
|
// Clear all config
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
|
|
// Check if configured
|
2026-01-19 16:49:54 -05:00
|
|
|
bool isConfigured() const { return configured; }
|
2026-01-19 11:50:10 -05:00
|
|
|
|
|
|
|
|
// Getters
|
2026-01-19 16:49:54 -05:00
|
|
|
const String& getWifiSsid() const { return wifiSsid; }
|
|
|
|
|
const String& getWifiPassword() const { return wifiPassword; }
|
|
|
|
|
const String& getMqttHost() const { return mqttHost; }
|
|
|
|
|
uint16_t getMqttPort() const { return mqttPort; }
|
|
|
|
|
const String& getDeviceId() const { return deviceId; }
|
2026-01-19 11:50:10 -05:00
|
|
|
|
|
|
|
|
// Setters
|
|
|
|
|
void setWifiCredentials(const String& ssid, const String& password);
|
|
|
|
|
void setMqttConfig(const String& host, uint16_t port);
|
|
|
|
|
void setDeviceId(const String& id);
|
|
|
|
|
|
|
|
|
|
// Get unique AP name based on chip ID
|
|
|
|
|
String getAPName() const;
|
|
|
|
|
|
|
|
|
|
// Get unique default device ID based on chip ID
|
|
|
|
|
String getDefaultDeviceId() const;
|
|
|
|
|
|
|
|
|
|
private:
|
2026-01-19 16:49:54 -05:00
|
|
|
ConfigService() = default;
|
|
|
|
|
|
|
|
|
|
bool configured = false;
|
|
|
|
|
String wifiSsid = "";
|
|
|
|
|
String wifiPassword = "";
|
|
|
|
|
String mqttHost = "";
|
|
|
|
|
uint16_t mqttPort = 1883;
|
|
|
|
|
String deviceId = "";
|
|
|
|
|
|
2026-01-19 11:50:10 -05:00
|
|
|
Preferences preferences;
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-19 16:49:54 -05:00
|
|
|
#define configService ConfigService::getInstance()
|
2026-01-19 11:50:10 -05:00
|
|
|
|
2026-01-19 16:49:54 -05:00
|
|
|
#endif // CONFIG_SERVICE_H
|