feat: 添加调试日志用于排查扫描问题

1. provisioning.py: 添加 start_scanning 调用日志
2. config_flow.py: 添加 coordinator 调用日志
3. serial_reader.py: 添加命令发送和接收的原始数据日志
This commit is contained in:
impressionyang 2026-04-16 16:25:06 +08:00
parent 1af5333792
commit b4643fa408
4 changed files with 39 additions and 5 deletions

View File

@ -235,10 +235,14 @@ class SigMeshGatewayOptionsFlow(config_entries.OptionsFlow):
if user_input is not None:
# 调用配网管理器开始扫描
try:
_LOGGER.info("开始调用 start_scanningDOMAIN 数据:%s", list(self.hass.data.get(DOMAIN, {}).keys()))
for coordinator in self.hass.data.get(DOMAIN, {}).values():
if hasattr(coordinator, 'start_scanning'):
_LOGGER.info("调用 coordinator.start_scanning()")
await coordinator.start_scanning()
_LOGGER.info("coordinator.start_scanning() 调用完成")
except Exception as e:
_LOGGER.error("start_scanning 调用失败:%s", e, exc_info=True)
self._errors["base"] = str(e)
return await self.async_step_prov_action()
return self.async_create_entry(title="", data={})

View File

@ -130,6 +130,8 @@ class ProvisioningManager:
async def start_scanning(self) -> None:
"""开始扫描设备."""
_LOGGER.debug("start_scanning 被调用,当前状态:%s", self._state.value)
# 如果已经在扫描中,先重置状态(允许用户重新启动扫描)
if self._state == ProvState.SCANNING:
_LOGGER.info("扫描已在进行中,重置扫描状态...")
@ -148,6 +150,7 @@ class ProvisioningManager:
# 发送扫描命令AT+PROV=SCAN
# 网关会开始扫描周围的配网设备,设备响应后通过串口上报
try:
_LOGGER.debug("准备发送扫描命令AT+PROV=SCAN")
await self.serial_reader.write_command("AT+PROV=SCAN")
_LOGGER.info("已发送扫描命令,等待设备响应...")
except Exception as e:

View File

@ -272,6 +272,7 @@ class SerialReader:
try:
line = line_bytes.decode("utf-8").strip()
_LOGGER.debug("串口接收:%s", line)
_LOGGER.debug("串口接收原始数据:%s", line_bytes.hex().upper())
self._parse_event_line(line)
except UnicodeDecodeError as e:
_LOGGER.warning("解码失败:%s, 错误:%s", line_bytes, e)
@ -299,8 +300,14 @@ class SerialReader:
async def write_command(self, command: str) -> int:
"""写入 AT 命令."""
cmd_bytes = f"{command}\r\n".encode()
_LOGGER.debug("发送命令:%s", command)
return await self.write(cmd_bytes)
_LOGGER.debug("发送命令:%s (原始数据:%s)", command, cmd_bytes.hex())
try:
result = await self.write(cmd_bytes)
_LOGGER.debug("命令发送成功,发送了 %d 字节", result)
return result
except Exception as e:
_LOGGER.error("命令发送失败:%s", e)
raise
def list_serial_ports() -> list[dict[str, str]]:

View File

@ -4,24 +4,44 @@
本指南介绍如何使用 SigMesh Gateway 集成的配网功能,将 Bluetooth Mesh 设备添加到网络中。
## 重要说明:配网参数来源
**配网参数Network Key, App Key, Network ID, IV Index是通过 danglo 工具设置到网关的,而不是从网关读取的。**
- **首次使用网关**:必须先用 danglo 组网工具设置配网参数
- **HA 配置时**:输入与 danglo 工具中相同的参数(或使用默认值)
- **原因**网关芯片Nordic nRF52840写入参数后无法通过命令读取需用户自行记录
## 配网流程
### 第一步:首次配置
添加集成时,需要配置以下配网参数:
#### 1. 使用 danglo 工具配置网关
添加集成前,先用亿佰特官方 danglo 组网工具配置网关:
1. 打开 danglo 工具,连接 E104-BT12USP 网关
2. 进入 **PROV** 选项卡
3. 设置配网参数并点击 **PROV** 写入网关
> **提示**:建议记录这些参数,后续 HA 配置和其他网关需要使用相同参数
#### 2. 在 HA 中配置集成
添加集成时,需要配置以下参数:
1. **串口配置**
- 选择串口设备(如 `/dev/ttyUSB0`
- 设置波特率(默认 115200
2. **配网参数**(首次使用需要)
2. **配网参数**必须与 danglo 工具中一致
- **Network Key**: 16 字节网络密钥32 字符十六进制)
- **App Key**: 16 字节应用密钥32 字符十六进制)
- **Network ID**: 2 字节网络 ID4 字符十六进制)
- **IV Index**: 4 字节 IV 索引(整数)
- **组地址起始值**: 组地址范围起始(默认 0xC000
> **注意**: 如果网关已经配置过,可以使用默认值(全 0
> **注意**: 如果网关已经配置过且参数已知,可以在 HA 配置时直接输入;如果不确定,可以使用默认值(全 0但需确保网关中的参数与 HA 配置一致
### 第二步:扫描设备