fix:修补蓝牙配网bug

This commit is contained in:
yangzhijia
2026-08-12 09:22:28 +08:00
parent 93112dcdfd
commit 08a055b611
32 changed files with 13266 additions and 327 deletions

View File

@@ -19,6 +19,10 @@
#include <WebServer.h>
#include <DNSServer.h>
#include <LittleFS.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include <ArduinoJson.h>
#include "config.h"
@@ -29,9 +33,10 @@ struct DeviceConfig {
char mqtt_user[20];
char mqtt_pass[20];
char device_id[20];
char env_note[20]; // 环境备注
char wifi_ssid[33]; // WiFi SSID (持久化)
char wifi_pass[65]; // WiFi 密码 (持久化)
char env_note[20]; // 环境备注 (房间名)
char env_type[16]; // 环境类型 bedroom/bathroom/...
char wifi_ssid[33]; // WiFi SSID
char wifi_pass[65]; // WiFi 密码
};
class WiFiMgmt {
@@ -50,6 +55,8 @@ public:
const char* getDeviceId() const;
const char* getEnvNote() const;
void startConfigPortal();
void handleBLEProvision(const char* json); // BLE 配网回调
void enqueueBLEJson(const char* json); // BLE 线程安全入队 (仅暂存)
void resetSettings();
private:
@@ -70,6 +77,10 @@ private:
void _updateWifiScan(); // WiFi 扫描缓存
String _htmlPage(); // 返回配网 HTML 页面
// BLE 蓝牙配网
void _startBLE();
void _stopBLE();
WebServer* _server;
DNSServer* _dns;
DeviceConfig _config;
@@ -91,6 +102,17 @@ private:
// LED 独立任务
TaskHandle_t _ledTaskHandle;
volatile uint8_t _ledMode; // 0=灭 1=慢闪 2=快闪 3=常亮
// BLE
BLEServer* _bleServer;
BLECharacteristic* _bleInfoChar; // READ: 设备信息
BLECharacteristic* _bleChar; // WRITE+NOTIFY: 配网
BLEAdvertising* _bleAdv;
// BLE 回调保护: 不在 BTC_TASK 栈里做 Flash 写操作
String _blePendingJson; // 待处理的 BLE 配网 JSON
bool _blePendingFlag; // 有未处理的 BLE 数据
void _processBLEPending(); // 在 loop() 上下文处理
};
#endif // WIFI_MANAGER_H