This commit is contained in:
xyj 2023-12-14 11:29:40 +08:00
parent 62c5fa2f1f
commit 233dc494da
4 changed files with 17 additions and 3 deletions

10
MQTT.py
View File

@ -5,7 +5,7 @@ import paho.mqtt.client as mqtt
from tool import * from tool import *
from config import broker, port, subscribe_topic, publish_topic, username, password from config import broker, port, subscribe_topic, publish_topic, username, password, publish_pwd
def valid(msg, client): def valid(msg, client):
@ -13,6 +13,14 @@ def valid(msg, client):
if 'msg' not in origin_data: if 'msg' not in origin_data:
client.publish('error', payload='msg must be supplied', qos=0) client.publish('error', payload='msg must be supplied', qos=0)
return False return False
# TODO 增加安全性
if 'pwd' not in origin_data:
client.publish('error', payload='pwd must be supplied', qos=0)
return False
# 判断密码是否正确
if publish_pwd != origin_data['pwd']:
client.publish('error', payload='pwd is not corrected', qos=0)
return False
return True return True

View File

@ -4,4 +4,6 @@ host=mqtt.lihaink.cn
port=1883 port=1883
[record] [record]
post_record_list_url=https://shop.lihaink.cn/api/index/file_list post_record_list_url=https://shop.lihaink.cn/api/index/file_list
post_record_url=https://shop.lihaink.cn/api/index/upload post_record_url=https://shop.lihaink.cn/api/index/upload
[publish_pwd]
value=123456

View File

@ -18,6 +18,9 @@ port = config.getint("broker", "port")
# 录像地址 # 录像地址
post_record_list_url = config.get("record", "post_record_list_url") post_record_list_url = config.get("record", "post_record_list_url")
post_record_url = config.get("record", "post_record_url") post_record_url = config.get("record", "post_record_url")
# 发布消息的认证pwd
publish_pwd = config.get("publish_pwd", "value")
# 读取设备配置 # 读取设备配置
config.read('conf/device/device.conf') config.read('conf/device/device.conf')
@ -33,5 +36,6 @@ password = config.get(device_name, "password")
# 特殊配置 # 特殊配置
config.read('conf/zhanguan/topic.conf') config.read('conf/zhanguan/topic.conf')
zhanguan_device_name = config.get("device", "name") zhanguan_device_name = config.get("device", "name")
# tool配置 # tool配置
mp4_path = '/home/pi/mp4' mp4_path = '/home/pi/mp4'

View File

@ -246,4 +246,4 @@ if __name__ == '__main__':
client.on_connect = on_connect client.on_connect = on_connect
# Establish a connection # Establish a connection
client.connect(broker, port) client.connect(broker, port)
client.loop_forever() client.loop_forever()