mirror of
https://github.com/mattintech/pyBTMCP.git
synced 2026-07-11 14:21:52 +00:00
v1.2.0: Firmware refactor to service-oriented architecture + WiFi fixes
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>
This commit is contained in:
49
firmware/esp32_ble_sim/include/services/wifi_service.h
Normal file
49
firmware/esp32_ble_sim/include/services/wifi_service.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef WIFI_SERVICE_H
|
||||
#define WIFI_SERVICE_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
// ============================================
|
||||
// WiFi Service
|
||||
// Manages WiFi STA and AP modes
|
||||
// ============================================
|
||||
class WiFiService {
|
||||
public:
|
||||
static WiFiService& getInstance();
|
||||
|
||||
// Prevent copying
|
||||
WiFiService(const WiFiService&) = delete;
|
||||
WiFiService& operator=(const WiFiService&) = delete;
|
||||
|
||||
// Lifecycle
|
||||
void setup();
|
||||
void loop();
|
||||
|
||||
// State queries
|
||||
bool isConnected() const { return wifiConnected; }
|
||||
bool isApActive() const { return apModeActive; }
|
||||
String getIP() const;
|
||||
|
||||
// Actions
|
||||
void startAP();
|
||||
void stopAP();
|
||||
void reconnect(); // Trigger reconnection attempt
|
||||
|
||||
private:
|
||||
WiFiService() = default;
|
||||
|
||||
bool wifiConnected = false;
|
||||
bool apModeActive = false;
|
||||
unsigned long lastWifiAttempt = 0;
|
||||
int wifiRetryCount = 0;
|
||||
|
||||
static const int MAX_WIFI_RETRIES = 5;
|
||||
|
||||
void connectToWiFi();
|
||||
void startAPMode();
|
||||
void stopAPMode();
|
||||
};
|
||||
|
||||
#define wifiService WiFiService::getInstance()
|
||||
|
||||
#endif // WIFI_SERVICE_H
|
||||
Reference in New Issue
Block a user