『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
楼主: XCray

[修仙教程] 【ESPHome】ESP32 DIY通用蓝牙网关,接入米家系门锁等各种设备

  [复制链接]

105

主题

2954

帖子

1万

积分

超级版主

智能家居&单板滑雪痴迷爱好者

Rank: 8Rank: 8

积分
12119
金钱
9100
HASS币
460

教程狂人突出贡献

 楼主| 发表于 2024-5-26 21:56:22 | 显示全部楼层
silang521 发表于 2024-5-26 20:11
X大 我的门锁型号是MJZNMS03LM   开门关门传感器也有数据但是esphome log里面还是会显示  parse_xiaomi_h ...

这我得回忆一下原来的思路和代码,不过建议先试试ha内置的xiaomi_ble组件,很可能已经可以很好的支持这款锁了。
如果ha主机没有蓝牙的话就把esp32刷成蓝牙代理
回复

使用道具 举报

7

主题

269

帖子

1513

积分

金牌会员

Rank: 6Rank: 6

积分
1513
金钱
1244
HASS币
0
发表于 2024-5-26 21:58:42 | 显示全部楼层
XCray 发表于 2024-5-26 21:56
这我得回忆一下原来的思路和代码,不过建议先试试ha内置的xiaomi_ble组件,很可能已经可以很好的支持这款 ...

我已经把esp32刷成蓝牙代理 但是好长时间都发现不了这个门锁
回复

使用道具 举报

7

主题

269

帖子

1513

积分

金牌会员

Rank: 6Rank: 6

积分
1513
金钱
1244
HASS币
0
发表于 2024-5-27 13:35:27 | 显示全部楼层
XCray 发表于 2024-5-26 21:56
这我得回忆一下原来的思路和代码,不过建议先试试ha内置的xiaomi_ble组件,很可能已经可以很好的支持这款 ...

X大 下面是我获取到的报错信息
[13:34:25][D][xiaomi_blez:117]: Packet : 30.44.99.05.45.41.C8.DB.13.AE.FB.2D.01.00 (14)
[13:34:25][D][xiaomi_blez:120]: parse_xiaomi_header(): service data has no DATA flag.
[13:34:25][D][ble_adv:039]: New BLE device
[13:34:25][D][ble_adv:041]:   address: FB:AE:13B:C8:41
[13:34:25][D][ble_adv:043]:   name:
[13:34:25][D][ble_adv:045]:   Advertised service UUIDs:
[13:34:25][D][ble_adv:050]:   Advertised service data:
[13:34:25][D][ble_adv:052]:     - 0xFE95: (length 14)
[13:34:25][D][ble_adv:054]:   Advertised manufacturer data:
[13:34:25][D][sensor:094]: 'BLE Sensor': Sending state 48.00000  with 1 decimals of accuracy
[13:34:25][D][ble_adv:065]: (length 14)304499054541C8DB13AEFB2D0100CC3F
[13:34:26][D][xiaomi_blez:117]: Packet : 30.44.99.05.45.41.C8.DB.13.AE.FB.2D.01.00 (14)
[13:34:26][D][xiaomi_blez:120]: parse_xiaomi_header(): service data has no DATA flag.
[13:34:26][D][ble_adv:039]: New BLE device
[13:34:26][D][ble_adv:041]:   address: FB:AE:13B:C8:41
[13:34:26][D][ble_adv:043]:   name:
[13:34:26][D][ble_adv:045]:   Advertised service UUIDs:
[13:34:26][D][ble_adv:050]:   Advertised service data:
[13:34:26][D][ble_adv:052]:     - 0xFE95: (length 14)
[13:34:26][D][ble_adv:054]:   Advertised manufacturer data:
[13:34:26][D][sensor:094]: 'BLE Sensor': Sending state 48.00000  with 1 decimals of accuracy
[13:34:26][D][ble_adv:065]: (length 14)304499054541C8DB13AEFB2D0100CC3F
[13:34:27][D][xiaomi_blez:117]: Packet : 30.44.99.05.45.41.C8.DB.13.AE.FB.2D.01.00 (14)
[13:34:27][D][xiaomi_blez:120]: parse_xiaomi_header(): service data has no DATA flag.
[13:34:27][D][ble_adv:039]: New BLE device
[13:34:27][D][ble_adv:041]:   address: FB:AE:13B:C8:41
[13:34:27][D][ble_adv:043]:   name:
[13:34:27][D][ble_adv:045]:   Advertised service UUIDs:
[13:34:27][D][ble_adv:050]:   Advertised service data:
[13:34:27][D][ble_adv:052]:     - 0xFE95: (length 14)
[13:34:27][D][ble_adv:054]:   Advertised manufacturer data:
[13:34:27][D][sensor:094]: 'BLE Sensor': Sending state 48.00000  with 1 decimals of accuracy
[13:34:27][D][ble_adv:065]: (length 14)304499054541C8DB13AEFB2D0100CC3F
[13:34:28][D][xiaomi_blez:117]: Packet : 30.44.99.05.45.41.C8.DB.13.AE.FB.2D.01.00 (14)
[13:34:28][D][xiaomi_blez:120]: parse_xiaomi_header(): service data has no DATA flag.
[13:34:28][D][ble_adv:039]: New BLE device
[13:34:28][D][ble_adv:041]:   address: FB:AE:13B:C8:41
[13:34:28][D][ble_adv:043]:   name:
[13:34:28][D][ble_adv:045]:   Advertised service UUIDs:
[13:34:28][D][ble_adv:050]:   Advertised service data:
[13:34:28][D][ble_adv:052]:     - 0xFE95: (length 14)
[13:34:28][D][ble_adv:054]:   Advertised manufacturer data:
[13:34:28][D][sensor:094]: 'BLE Sensor': Sending state 48.00000  with 1 decimals of accuracy
[13:34:28][D][ble_adv:065]: (length 14)304499054541C8DB13AEFB2D0100CC3F
[13:34:32][D][xiaomi_blez:117]: Packet : 30.44.99.05.45.41.C8.DB.13.AE.FB.2D.01.00 (14)
[13:34:32][D][xiaomi_blez:120]: parse_xiaomi_header(): service data has no DATA flag.
[13:34:32][D][ble_adv:039]: New BLE device
[13:34:32][D][ble_adv:041]:   address: FB:AE:13B:C8:41
[13:34:32][D][ble_adv:043]:   name:
[13:34:32][D][ble_adv:045]:   Advertised service UUIDs:
[13:34:32][D][ble_adv:050]:   Advertised service data:
[13:34:32][D][ble_adv:052]:     - 0xFE95: (length 14)
[13:34:32][D][ble_adv:054]:   Advertised manufacturer data:
[13:34:32][D][sensor:094]: 'BLE Sensor': Sending state 48.00000  with 1 decimals of accuracy
[13:34:32][D][ble_adv:065]: (length 14)304499054541C8DB13AEFB2D0100CC3F

接下来该怎么做?
回复

使用道具 举报

7

主题

269

帖子

1513

积分

金牌会员

Rank: 6Rank: 6

积分
1513
金钱
1244
HASS币
0
发表于 2024-5-27 13:36:38 | 显示全部楼层
XCray 发表于 2024-5-26 21:56
这我得回忆一下原来的思路和代码,不过建议先试试ha内置的xiaomi_ble组件,很可能已经可以很好的支持这款 ...

======
9905
45
AEFB2D
41C8DB13
b'A\xc8\xdb\x13'
decrptdata: b'dab2e318'
>>>

以上是python解出来的结果
回复

使用道具 举报

7

主题

269

帖子

1513

积分

金牌会员

Rank: 6Rank: 6

积分
1513
金钱
1244
HASS币
0
发表于 2024-5-27 14:03:00 | 显示全部楼层
jy940006145 发表于 2023-9-1 18:55
你好,请教一下,40位字符的问题解决了么?可以使用么?

40位的我已经解决,等测试好我会发一个完整的获取教程
回复

使用道具 举报

105

主题

2954

帖子

1万

积分

超级版主

智能家居&单板滑雪痴迷爱好者

Rank: 8Rank: 8

积分
12119
金钱
9100
HASS币
460

教程狂人突出贡献

 楼主| 发表于 2024-5-28 14:33:12 | 显示全部楼层
本帖最后由 XCray 于 2024-5-28 15:39 编辑

service data has no DATA flag提示应该可以忽略,收到了不含数据的没啥用处的广播。
就是这个:30.44.99.05.45.41.C8.DB.13.AE.FB.2D.01.00
3044为FrameControl,二进制为0011 0000 0100 0100
30含义:未加密、包含mac、包含capability、不含Object、不含Mesh
44含义:未绑定、请求App进行注册绑定、旧版本认证、版本号4
99.05为pid,0599
45为序号
41.C8.DB.13.AE.FB为MAC地址
2D为设备能力,0010 1101,包含I/O能力字段、前绑定、可加密不可集中可连接
01.00为I/O能力,可输入6位数字

我也觉得奇怪,貌似还没有用app绑定?

你得把关心的事件(如开锁)对应的消息打印出来,对着小米的文档去翻译,然后再针对性的修改代码

回复

使用道具 举报

105

主题

2954

帖子

1万

积分

超级版主

智能家居&单板滑雪痴迷爱好者

Rank: 8Rank: 8

积分
12119
金钱
9100
HASS币
460

教程狂人突出贡献

 楼主| 发表于 2024-5-28 15:52:01 | 显示全部楼层
silang521 发表于 2024-5-26 21:58
我已经把esp32刷成蓝牙代理 但是好长时间都发现不了这个门锁

那就是不支持
回复

使用道具 举报

7

主题

269

帖子

1513

积分

金牌会员

Rank: 6Rank: 6

积分
1513
金钱
1244
HASS币
0
发表于 2024-5-28 20:46:18 | 显示全部楼层
XCray 发表于 2024-5-28 14:33
service data has no DATA flag提示应该可以忽略,收到了不含数据的没啥用处的广播。
就是这个:30.44.99.0 ...

X大 我已经绑定过APP,下面是开门关门的代码

[22:57:42][D][xiaomi_blez:117]: Packet : 50.44.99.05.86.41.C8.DB.13.AE.FB.0B.00.09.A4.00.00.00.00.62.9F.54.66 (23)
[22:57:42][D][xiaomi_blez:089]: value_length:9;payload_length:12
[22:57:42][D][xiaomi_blez:246]: Got Xiaomi MijiaLock (FB:AE:13B:C8:41):
[22:57:42][D][xiaomi_blez:249]:   OpMethod:164
[22:57:42][D][xiaomi_blez:261]:   OpTS:1716821858
[22:57:42][D][xiaomi_blez:264]:   KeyID:0
[22:57:42][D][sensor:094]: 'OpMethod': Sending state 164.00000  with 0 decimals of accuracy
[22:57:42][D][sensor:094]: 'KeyID': Sending state 0.00000  with 0 decimals of accuracy
[22:57:42][D][sensor:094]: 'OpTS': Sending state 1716821888.00000  with 0 decimals of accuracy
[22:57:42][D][sensor:094]: 'BLE Sensor': Sending state 56.00000  with 1 decimals of accuracy
[22:57:42][D][ble_adv:065]: (length 23)504499058641C8DB13AEFB0B00093FCC55E401
[22:57:43][D][xiaomi_blez:117]: Packet : 50.44.99.05.86.41.C8.DB.13.AE.FB.0B.00.09.A4.00.00.00.00.62.9F.54.66 (23)
[22:57:43][D][xiaomi_blez:126]: 125.parse_xiaomi_header(): duplicate data packet received (23).
[22:57:43][D][sensor:094]: 'BLE Sensor': Sending state 0.00000  with 1 decimals of accuracy
[22:57:43][D][ble_adv:065]: (length 23)504499058641C8DB13AEFB0B00093FCC55E401
[22:57:43][D][xiaomi_blez:117]: Packet : 50.44.99.05.86.41.C8.DB.13.AE.FB.0B.00.09.A4.00.00.00.00.62.9F.54.66 (23)
[22:57:43][D][xiaomi_blez:126]: 125.parse_xiaomi_header(): duplicate data packet received (23).
[22:57:43][D][sensor:094]: 'BLE Sensor': Sending state 0.00000  with 1 decimals of accuracy
[22:57:43][D][ble_adv:065]: (length 23)504499058641C8DB13AEFB0B00093FCC55E401
[22:57:44][D][xiaomi_blez:117]: Packet : 50.44.99.05.86.41.C8.DB.13.AE.FB.0B.00.09.A4.00.00.00.00.62.9F.54.66 (23)
[22:57:44][D][xiaomi_blez:126]: 125.parse_xiaomi_header(): duplicate data packet received (23).
[22:57:44][D][sensor:094]: 'BLE Sensor': Sending state 0.00000  with 1 decimals of accuracy
[22:57:44][D][ble_adv:065]: (length 23)504499058641C8DB13AEFB0B00093FCC55E401
[22:57:44][D][xiaomi_blez:117]: Packet : 50.44.99.05.86.41.C8.DB.13.AE.FB.0B.00.09.A4.00.00.00.00.62.9F.54.66 (23)
[22:57:44][D][xiaomi_blez:126]: 125.parse_xiaomi_header(): duplicate data packet received (23).
[22:57:44][D][sensor:094]: 'BLE Sensor': Sending state 0.00000  with 1 decimals of accuracy
[22:57:44][D][ble_adv:065]: (length 23)504499058641C8DB13AEFB0B00093FCC55E401
[22:57:44][D][xiaomi_blez:117]: Packet : 50.44.99.05.87.41.C8.DB.13.AE.FB.0B.00.09.A1.00.00.00.00.63.9F.54.66 (23)
[22:57:44][D][xiaomi_blez:089]: value_length:9;payload_length:12
[22:57:44][D][xiaomi_blez:246]: Got Xiaomi MijiaLock (FB:AE:13B:C8:41):
[22:57:44][D][xiaomi_blez:249]:   OpMethod:161
[22:57:44][D][xiaomi_blez:261]:   OpTS:1716821859
[22:57:44][D][xiaomi_blez:264]:   KeyID:0
[22:57:44][D][sensor:094]: 'OpMethod': Sending state 161.00000  with 0 decimals of accuracy
[22:57:45][D][sensor:094]: 'KeyID': Sending state 0.00000  with 0 decimals of accuracy
[22:57:45][D][sensor:094]: 'OpTS': Sending state 1716821888.00000  with 0 decimals of accuracy
回复

使用道具 举报

105

主题

2954

帖子

1万

积分

超级版主

智能家居&单板滑雪痴迷爱好者

Rank: 8Rank: 8

积分
12119
金钱
9100
HASS币
460

教程狂人突出贡献

 楼主| 发表于 2024-5-29 21:57:13 | 显示全部楼层
程序运行正常,解密也没有问题。代码不修改已经能用了,在HA里多做些工作。
也可以修改代码,把“操作”分解开来。
比如你贴出来的OpMethod 164,转成二进制是1010 0100,根据小米文档,是人工、门内开锁;而161是人工、上锁。
时间戳在HA里可以直接展现成日期时分秒。
回复

使用道具 举报

7

主题

269

帖子

1513

积分

金牌会员

Rank: 6Rank: 6

积分
1513
金钱
1244
HASS币
0
发表于 2024-6-6 21:09:50 | 显示全部楼层
XCray 发表于 2024-5-29 21:57
程序运行正常,解密也没有问题。代码不修改已经能用了,在HA里多做些工作。
也可以修改代码,把“操作”分 ...

请教X大我解出来的所有的指纹都是一个ID 2147549184   


[20:53:27][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.83.41.C8.DB.13.AE.FB.0B.00.09.20.06.00.01.80.2E.B1.61.66 (23)
[20:53:27][D][xiaomi_blez:092]: value_length:9;payload_length:12
[20:53:27][D][xiaomi_blez:248]: Got Xiaomi MijiaLock (FB:AE:13B:C8:41):
[20:53:27][D][xiaomi_blez:251]:   OpMethod:32
[20:53:27][D][xiaomi_blez:263]:   OpTS:1717678382
[20:53:27][D][xiaomi_blez:266]:   KeyID1:-2147418106
[20:53:27][D][sensor:094]: 'OpMethod': Sending state 32.00000  with 0 decimals of accuracy
[20:53:27][D][sensor:094]: 'KeyID': Sending state 2147549184.00000  with 0 decimals of accuracy
[20:53:27][D][sensor:094]: 'OpTS': Sending state 1717678336.00000  with 0 decimals of accuracy
[20:53:28][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.83.41.C8.DB.13.AE.FB.0B.00.09.20.06.00.01.80.2E.B1.61.66 (23)
[20:53:28][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.83.41.C8.DB.13.AE.FB.0B.00.09.20.06.00.01.80.2E.B1.61.66 (23)
[20:53:28][D][xiaomi_blez:121]: sx2 Packet : 30.44.99.05.84.41.C8.DB.13.AE.FB.2D.01.00 (14)
[20:53:28][D][xiaomi_blez:083]: parse_xiaomi_message(): payload has wrong size (3)!
[20:53:29][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.85.41.C8.DB.13.AE.FB.06.00.05.FF.FF.FF.FF.00 (19)
[20:53:29][D][xiaomi_blez:092]: value_length:5;payload_length:8
[20:53:29][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.85.41.C8.DB.13.AE.FB.06.00.05.FF.FF.FF.FF.00 (19)
[20:53:30][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.85.41.C8.DB.13.AE.FB.06.00.05.FF.FF.FF.FF.00 (19)
[20:53:30][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.85.41.C8.DB.13.AE.FB.06.00.05.FF.FF.FF.FF.00 (19)
[20:53:30][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.85.41.C8.DB.13.AE.FB.06.00.05.FF.FF.FF.FF.00 (19)
[20:53:30][W][component:237]: Component esp32_ble_tracker took a long time for an operation (57 ms).
[20:53:30][W][component:238]: Components should block for at most 30 ms.
[20:53:31][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.86.41.C8.DB.13.AE.FB.0B.00.09.20.05.00.01.80.32.B1.61.66 (23)
[20:53:31][D][xiaomi_blez:092]: value_length:9;payload_length:12
[20:53:31][D][xiaomi_blez:248]: Got Xiaomi MijiaLock (FB:AE:13B:C8:41):
[20:53:31][D][xiaomi_blez:251]:   OpMethod:32
[20:53:31][D][xiaomi_blez:263]:   OpTS:1717678386
[20:53:31][D][xiaomi_blez:266]:   KeyID1:-2147418107
[20:53:31][D][sensor:094]: 'OpMethod': Sending state 32.00000  with 0 decimals of accuracy
[20:53:31][D][sensor:094]: 'KeyID': Sending state 2147549184.00000  with 0 decimals of accuracy
[20:53:31][D][sensor:094]: 'OpTS': Sending state 1717678336.00000  with 0 decimals of accuracy
[20:53:31][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.86.41.C8.DB.13.AE.FB.0B.00.09.20.05.00.01.80.32.B1.61.66 (23)
[20:53:31][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.86.41.C8.DB.13.AE.FB.0B.00.09.20.05.00.01.80.32.B1.61.66 (23)
[20:53:32][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.86.41.C8.DB.13.AE.FB.0B.00.09.20.05.00.01.80.32.B1.61.66 (23)
[20:53:32][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.86.41.C8.DB.13.AE.FB.0B.00.09.20.05.00.01.80.32.B1.61.66 (23)
[20:53:32][D][xiaomi_blez:121]: sx2 Packet : 50.44.99.05.86.41.C8.DB.13.AE.FB.0B.00.09.20.05.00.01.80.32.B1.61.66 (23)

剩下的该怎么修改?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-28 01:34 , Processed in 1.093117 second(s), 31 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表