update
This commit is contained in:
parent
62c5fa2f1f
commit
233dc494da
10
MQTT.py
10
MQTT.py
|
@ -5,7 +5,7 @@ import paho.mqtt.client as mqtt
|
|||
|
||||
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):
|
||||
|
@ -13,6 +13,14 @@ def valid(msg, client):
|
|||
if 'msg' not in origin_data:
|
||||
client.publish('error', payload='msg must be supplied', qos=0)
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -4,4 +4,6 @@ host=mqtt.lihaink.cn
|
|||
port=1883
|
||||
[record]
|
||||
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
|
|
@ -18,6 +18,9 @@ port = config.getint("broker", "port")
|
|||
# 录像地址
|
||||
post_record_list_url = config.get("record", "post_record_list_url")
|
||||
post_record_url = config.get("record", "post_record_url")
|
||||
# 发布消息的认证pwd
|
||||
publish_pwd = config.get("publish_pwd", "value")
|
||||
|
||||
|
||||
# 读取设备配置
|
||||
config.read('conf/device/device.conf')
|
||||
|
@ -33,5 +36,6 @@ password = config.get(device_name, "password")
|
|||
# 特殊配置
|
||||
config.read('conf/zhanguan/topic.conf')
|
||||
zhanguan_device_name = config.get("device", "name")
|
||||
|
||||
# tool配置
|
||||
mp4_path = '/home/pi/mp4'
|
|
@ -246,4 +246,4 @@ if __name__ == '__main__':
|
|||
client.on_connect = on_connect
|
||||
# Establish a connection
|
||||
client.connect(broker, port)
|
||||
client.loop_forever()
|
||||
client.loop_forever()
|
Loading…
Reference in New Issue