mirror of
https://github.com/mattintech/pyBTMCP.git
synced 2026-07-11 12:01:53 +00:00
Firmware: - Fixed WiFi reconnection bug after power cycle by adding WiFi.persistent(false) and disabling auto-connect/auto-reconnect - Fixed AP mode not broadcasting by properly handling WIFI_AP_STA mode transitions - Refactored to service-oriented architecture: - device_state: Central state management with event callbacks - config_service: NVS persistence (renamed from config_manager) - wifi_service: WiFi STA/AP management (extracted from main.cpp) - mqtt_service: MQTT client and message routing (extracted from main.cpp) - ble_service: BLE GATT services (renamed from ble_services) - web_service: HTTP configuration portal (renamed from web_portal) - main.cpp reduced from ~470 lines to ~60 lines (thin orchestrator) - Each service is self-contained with setup()/loop() pattern Backend: - Added heart rate variation endpoint - UI improvements Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
65 lines
1.6 KiB
C++
65 lines
1.6 KiB
C++
#ifndef CONFIG_SERVICE_H
|
|
#define CONFIG_SERVICE_H
|
|
|
|
#include <Arduino.h>
|
|
#include <Preferences.h>
|
|
|
|
// ============================================
|
|
// Config Service
|
|
// Manages persistent configuration in NVS
|
|
// ============================================
|
|
class ConfigService {
|
|
public:
|
|
static ConfigService& getInstance();
|
|
|
|
// Prevent copying
|
|
ConfigService(const ConfigService&) = delete;
|
|
ConfigService& operator=(const ConfigService&) = delete;
|
|
|
|
// Load config from NVS
|
|
bool load();
|
|
|
|
// Save config to NVS
|
|
void save();
|
|
|
|
// Clear all config
|
|
void clear();
|
|
|
|
// Check if configured
|
|
bool isConfigured() const { return configured; }
|
|
|
|
// Getters
|
|
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; }
|
|
|
|
// 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:
|
|
ConfigService() = default;
|
|
|
|
bool configured = false;
|
|
String wifiSsid = "";
|
|
String wifiPassword = "";
|
|
String mqttHost = "";
|
|
uint16_t mqttPort = 1883;
|
|
String deviceId = "";
|
|
|
|
Preferences preferences;
|
|
};
|
|
|
|
#define configService ConfigService::getInstance()
|
|
|
|
#endif // CONFIG_SERVICE_H
|