# MQTT-HOME **Repository Path**: upchr/mqtt-home ## Basic Information - **Project Name**: MQTT-HOME - **Description**: 基于MQTT利用米家-巴法平台,实现远程操作:windows、极米投影仪开关机等 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2026-01-07 - **Last Updated**: 2026-01-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: mq, 米家, 巴法云, 远程开关机 ## README # MQTT自定义处理接入 基于MQTT利用米家-巴法平台,实现远程操作:windows、极米投影仪开关机等; ## 参考 ##### [巴法云控制台](https://cloud.bemfa.com/web/user/index) ##### [小爱接入巴法云](https://cloud.bemfa.com/docs/src/speaker_mi.html) ##### [电脑入米家,让小爱同学随意操控电脑开关机](https://blog.csdn.net/cgy233/article/details/127407571) ##### [极米new Z6X接入米家教程 实现小爱控制蓝牙开机及Wifi关机 ](https://www.znds.com/tv-1244090-1-1.html) ## 食用方法 ### 0.环境配置 #### 0.1 PIP依赖 ``` pip install requests paho-mqtt configparser asyncudp bluez-peripheral ``` #### 0.2 特定功能依赖 ``` apt install -y etherwake # WOL apt install -y bluez bluez-tools libbluetooth-dev # 蓝牙 ``` #### 0.3 ssh-windows免密 ``` ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/id_rsa #windows开启sshd服务 #公钥复制带windows:C:\Users\user\.ssh\authorized_keys ssh-copy-id hostname@broadcast ``` #### 0.4 极米投影仪配对 ``` 配对遥控器,模拟蓝牙遥控获取manufactorer data ``` ### 1.修改config.ini配置文件 ```dosini # 日志输出级别 [General] log_level = INFO # 巴法云配置 [MQTT_CONFIG] bemfa_broker=bemfa.com bemfa_port=9501 # 巴法平台控制台获取的私钥 bemfa_client_id=xxxx # 开启接收处理的设备主题mqtt_topic [Devices] enabled = xxxx ,xgimi009, pc009, pc2topic # 自定义设备信息 # 接入格式: #[Device:mqtt_topic] #type = XXHandler #配置为devices.xx中xxHandler处理器 #xxx=xxx #参考下面示范,对应处理器内容 # 巴法云主题:xgimi009-极米 [Device:xgimi009] type = XGiMiHandler #配置为devices.xgimi中XGiMiHandler处理器 x_ip=xxxx #极米ip manufacturer_data=xxxx #极米遥控码 # 巴法云主题:pc009-pc1 [Device:pc009] type = PCHandler #配置为devices.xgimi中PCHandler处理器 broadcast=xxxx #windows-ip hostname=xxxx #windows-username mac=xxxx #windows-mac # 巴法云主题:pc2topic-pc2 [Device:pc2topic] type = PCHandler broadcast=xxxx #windows-ip hostname=xxxx #windows-username mac=xxxx #windows-mac # 二开可追加配置:自动加载devices/消息处理器 [DeviceModules] modules = devices.pc, devices.xgimi ``` ### 2.脚本注册为服务自启动 修改mqtt.service文件中的WorkingDirectory和ExecStart为自己的路径 ``` [Unit] Description=MQTT Client Contral PC Daemon After=network.target Wants=network.target [Service] Environment=PYTHONUNBUFFERED=1 Type=simple WorkingDirectory=/xxxxx/mqtt-home ExecStart=/bin/sh -c "python3 main.py 2>&1 | tee -a log/mqtt.log | /usr/bin/logger -t mqtt" Restart=always RestartSec=20s User=root [Install] WantedBy=multi-user.target ``` 安装/卸载服务 ``` cd mqtt-home 安装服务:chmod +x install.sh && ./install.sh 卸载服务:chmod +x uninstall.sh && ./uninstall.sh ```