zigbee MQTT控制小米蓝牙插座开和关 型号Xiao Mi zigbee ZNCZ02LM 或支持zigbee的插座或设备

编程入门 行业动态 更新时间:2024-10-11 15:14:31

zigbee MQTT控制小米蓝牙<a href=https://www.elefans.com/category/jswz/34/1766127.html style=插座开和关 型号Xiao Mi zigbee ZNCZ02LM 或支持zigbee的插座或设备"/>

zigbee MQTT控制小米蓝牙插座开和关 型号Xiao Mi zigbee ZNCZ02LM 或支持zigbee的插座或设备

zigbee MQTT控制小米蓝牙插座开和关 型号Xiao Mi zigbee ZNCZ02LM 或支持zigbee的插座或设备

硬件准备

小米蓝牙插座,型号: Xiao Mi zigbee ZNCZ02LM 或支持zigbee的插座或设备

zigbee设备,型号: CC2531设备

参考链接:

/

/?action=show&id=23390

CC2531设备识别并安装pyCCSniffer

pyCCSniffer工具是使用德州仪器的CC2531 USB加密狗来嗅探数据包,剖析它们并将它们打印到控制台。

查看usb设备, 插入CC2531设备后
lsusb
显示CC2531设备
Bus 001 Device 003: ID 0451:16ae Texas Instruments, Inc. cd /optgit clone .git
cd pyCCSniffer
python pyCCSniffer.py
apt install python-pip 
pip install future   
pip install pyusb 安装失败,升级pip就成功了: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-4hIAE4/pyusb/
pip install libusb
pip install --upgrade pip
pip install pyusb成功显示
python pyCCSniffer.py
CC2531 USB Dongle <Channel: 11>
-------------------------------
Commands:
c: Print current RF Channel
h,?: Print this message
[11,26]: Change RF channel
s: Start/stop the packet capture
d: Toggle frame dissector
a*: Set an annotation (write "a" to remove it)
p: Print all capture packets
q: Quitpython pyCCSniffer.py -L /root/zigbee.log -D INFO
输入s没有这个目录
ls -l /dev/ttyACM0ls -l /dev/bus/usb/001/003 拔掉之后就没有了
ls -l /dev/bus/usb/001/005lsusb  换了一个CC2531设备后
Bus 001 Device 004: ID 0451:16a8 Texas Instruments, Inc. 就有这个目录了
ls -l /dev/ttyACM0ls -l /dev/bus/usb/001/004

安装Zigbee2MQTT

安装Zigbee2MQTT
sudo curl -sL .x | sudo -E bash -sudo apt-get install -y nodejs git make g++ gccnode --version
npm --versionsudo git clone .git /opt/zigbee2mqttcd /opt/zigbee2mqtt
npm civim /opt/zigbee2mqtt/data/configuration.yamladvanced:network_key: GENERATEnpm install
启动
npm start> zigbee2mqtt@1.21.1 start /opt/zigbee2mqtt
> node index.jsZigbee2MQTT requires node version ^10 || ^12 || ^14 || ^15 || ^16, you are running v8.10.0!Zigbee2MQTT:info  2022-09-30 14:38:47: Logging to console and directory: '/opt/zigbee2mqtt/data/log/2021-09-30.14-38-45' filename: log.txt
Zigbee2MQTT:info  2022-09-30 14:38:47: Starting Zigbee2MQTT version 1.21.1 (commit #4a51e0c0)
Zigbee2MQTT:info  2022-09-30 14:38:47: Starting zigbee-herdsman (0.13.138)
Zigbee2MQTT:info  2022-09-30 14:38:51: zigbee-herdsman started (resumed)
Zigbee2MQTT:info  2022-09-30 14:38:51: Coordinator firmware version: '{"meta":{"maintrel":3,"majorrel":2,"minorrel":6,"product":0,"revision":20190608,"transportrev":2},"type":"zStack12"}'
Zigbee2MQTT:info  2022-09-30 14:38:51: Currently 0 devices are joined:
Zigbee2MQTT:warn  2022-09-30 14:38:51: `permit_join` set to  `true` in configuration.yaml.
Zigbee2MQTT:warn  2022-09-30 14:38:51: Allowing new devices to join.
Zigbee2MQTT:warn  2022-09-30 14:38:51: Set `permit_join` to `false` once you joined all devices.
Zigbee2MQTT:info  2022-09-30 14:38:51: Zigbee: allowing new devices to join.
Zigbee2MQTT:info  2022-09-30 14:38:51: Connecting to MQTT server at mqtt://localhost
Zigbee2MQTT:info  2022-09-30 14:38:52: Connected to MQTT server
Zigbee2MQTT:info  2022-09-30 14:38:52: MQTT publish: topic 'zigbee2mqtt/bridge/state', payload 'online'

使用MQTT工具连接服务:mqtt://localhost,如MQTTX工具
监听mqtt的topic可以收到数据
zigbee2mqtt/#

如下部分数据:
Topic: zigbee2mqtt/bridge/logging QoS: 0
{"level":"info","message":"Connected to MQTT server"}Topic: zigbee2mqtt/bridge/logging QoS: 0
{"level":"info","message":"MQTT publish: topic 'zigbee2mqtt/bridge/state', payload 'online'"}

使用小米插座 型号:Xiao Mi zigbee ZNCZ02LM 控制成功

Xiao Mi zigbee ZNCZ02LM 测试成功

注意:
要使用支持zigbee的插座或设备: .html
小米蓝牙网关版本,型号:ZNCZ07CM 不支持zigbee 所以连不上

Xiao Mi zigbee ZNCZ02LM 设备按下按钮5秒左右, 灯闪烁,日志打印: Device '0x00158d00012ccbc2' joined 成功加入Zigbee2MQTT:info  2022-09-30 14:39:29: Device '0x00158d00012ccbc2' joined
Zigbee2MQTT:info  2022-09-30 14:39:29: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x00158d00012ccbc2","ieee_address":"0x00158d00012ccbc2"},"type":"device_joined"}'
Zigbee2MQTT:info  2022-09-30 14:39:29: Starting interview of '0x00158d00012ccbc2'
Zigbee2MQTT:info  2022-09-30 14:39:29: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x00158d00012ccbc2","ieee_address":"0x00158d00012ccbc2","status":"started"},"type":"device_interview"}'
Zigbee2MQTT:info  2022-09-30 14:39:29: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"friendly_name":"0x00158d00012ccbc2","ieee_address":"0x00158d00012ccbc2"},"type":"device_announce"}'
Zigbee2MQTT:info  2022-09-30 14:39:30: MQTT publish: topic 'zigbee2mqtt/0x00158d00012ccbc2', payload '{"consumption":0,"energy":0,"linkquality":81,"power":0,"state":"ON","temperature":38}'
Zigbee2MQTT:info  2022-09-30 14:39:31: MQTT publish: topic 'zigbee2mqtt/0x00158d00012ccbc2', payload '{"consumption":0,"energy":0,"linkquality":84,"power":0,"state":"ON","temperature":38}'
Zigbee2MQTT:info  2022-09-30 14:39:32: Successfully interviewed '0x00158d00012ccbc2', device has successfully been paired
Zigbee2MQTT:info  2022-09-30 14:39:32: Device '0x00158d00012ccbc2' is supported, identified as: Xiaomi Mi power plug ZigBee (ZNCZ02LM)
Zigbee2MQTT:info  2022-09-30 14:39:32: MQTT publish: topic 'zigbee2mqtt/bridge/event', payload '{"data":{"definition":{"description":"Mi power plug ZigBee","exposes":[{"features":[{"access":7,"description":"On/off state of the switch","name":"state","property":"state","type":"binary","value_off":"OFF","value_on":"ON","value_toggle":"TOGGLE"}],"type":"switch"},{"access":5,"description":"Instantaneous measured power","name":"power","property":"power","type":"numeric","unit":"W"},{"access":1,"description":"Sum of consumed energy","name":"energy","property":"energy","type":"numeric","unit":"kWh"},{"access":1,"description":"Measured temperature value","name":"temperature","property":"temperature","type":"numeric","unit":"°C"},{"access":7,"description":"Enable/disable the power outage memory, this recovers the on/off mode after power failure","name":"power_outage_memory","property":"power_outage_memory","type":"binary","value_off":false,"value_on":true},{"access":1,"description":"Link quality (signal strength)","name":"linkquality","property":"linkquality","type":"numeric","unit":"lqi","value_max":255,"value_min":0}],"model":"ZNCZ02LM","supports_ota":true,"vendor":"Xiaomi"},"friendly_name":"0x00158d00012ccbc2","ieee_address":"0x00158d00012ccbc2","status":"successful","supported":true},"type":"device_interview"}'

使用MQTT工具发送数据控制插座的开关 OFF为关闭 ON为打开

注意观察小米插座上的指示灯的状态

zigbee2mqtt/0x00158d00012ccbc2/set
{"state": "OFF"
}{"state": "ON"
}Zigbee2MQTT:info  2022-09-30 14:47:14: MQTT publish: topic 'zigbee2mqtt/0x00158d00012ccbc2', payload '{"consumption":0,"energy":0,"linkquality":81,"power":0,"state":"ON","temperature":38}'
Zigbee2MQTT:info  2022-09-30 14:47:24: MQTT publish: topic 'zigbee2mqtt/0x00158d00012ccbc2', payload '{"consumption":0,"energy":0,"linkquality":86,"power":0,"state":"OFF","temperature":38}'

效果演示视频

使用MQTT客户端工具发送,打开和关闭操作

注意观察小米插座上的指示灯的状态

zigbee MQTT控制小米蓝牙插座开和关

更多推荐

zigbee MQTT控制小米蓝牙插座开和关 型号Xiao Mi zigbee ZNCZ02LM 或支持zigbee的插座或设备

本文发布于:2024-03-10 13:25:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1728095.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:插座   蓝牙   小米   型号   设备

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!