基于MQTT利用米家-巴法平台,实现远程操作:windows、极米投影仪开关机等;
pip install requests paho-mqtt configparser asyncudp bluez-peripheral
apt install -y etherwake # WOL
apt install -y bluez bluez-tools libbluetooth-dev # 蓝牙
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
配对遥控器,模拟蓝牙遥控获取manufactorer data
# 日志输出级别 [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
修改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