1. 解决频繁频繁掉线的问题:原因是因为ble

sdk需要一开始就初始化,配网的时候只是去控制其广播是否开启。不然会导致一直掉线
This commit is contained in:
2025-05-29 13:08:40 +08:00
parent cb1ea6e364
commit 5ec8b9380c
19 changed files with 333 additions and 278 deletions

View File

@ -27,6 +27,7 @@ typedef enum {
#define SVC_ID_CCT "cct" // 色温控制
#define SVC_ID_LIGHT_MODE "lightMode" // 场景模式控制
#define SVC_ID_FADE_TIME "progressSwitch" // 渐变时长的控制
#define SVC_ID_NET_INFO "netInfo" // 配网信息
// JSON字段名定义
#define JSON_FIELD_ON "on" // 开关状态字段
@ -37,20 +38,21 @@ typedef enum {
// 当前亮度和色温状态
typedef struct {
typedef struct __attribute__((packed, aligned(1))) {
// 物模型同步需要 持久化维持
bool on; // 开关状态
uint8_t on; // 开关状态
lightMode_e elightMode;
uint16_t brightness_local; // 当前亮度 (0-1000)
uint16_t fade_time; // s
uint16_t cct_local; // 当前色温 (2700-6500)
// 持久化维持
int32_t power_on_cnt; // 上电次数计数
bool is_networked; // 是否已配网
uint8_t is_networked; // 是否已配网
uint8_t is_net_configured; // 设备是否曾经配网成功过
//运行时的数据
bool read_done; // 读取数据done
uint16_t duty_cw; // 冷白LED占空比
uint16_t duty_ww; // 暖白LED占空比
uint8_t read_done; // 读取数据done
} device_control_t;
// 色温范围定义
@ -122,11 +124,11 @@ typedef struct {
#define DEVICE_DATA_FLASH_SIZE 0x001000 // 使用一个页的大小
// 设备数据结构
typedef struct {
uint32_t checksum; // 校验和
uint32_t magic; // 魔数,用于验证数据有效性
uint32_t version; // 数据版本号
device_control_t control; // 设备控制状态
typedef struct __attribute__((packed, aligned(1))) {
uint8_t checksum; // 校验和
uint32_t magic; // 魔数,用于验证数据有效性
uint32_t version; // 数据版本号
device_control_t control; // 设备控制状态
} device_data_t;
#define DEVICE_DATA_MAGIC 0x4C505426 // "LPT&"的ASCII码
@ -159,6 +161,7 @@ typedef enum {
.brightness_local = BRIGHTNESS_REMOTE2LOCAL(INIT_STA__BRIGHTNESS), \
.fade_time = NET_CFG_DEFAULT_FADE_TIME, \
.is_networked = false, \
.is_net_configured = false, \
.duty_cw = 0, \
.duty_ww = 0, \
};