This commit is contained in:
xyj 2023-12-05 17:00:32 +08:00
parent cdd51bee73
commit 4d8ece6847
1 changed files with 4 additions and 4 deletions

View File

@ -16,26 +16,26 @@ def on_connect(client, userdata, flags, rc):
global times
if rc == 0:
print("连接成功,执行数据推送和本地存储")
subprocess.Popen(["supervisorctl stop sensor_to_local && supervisorctl start sensor_to_server"], shell=True)
subprocess.Popen(['/usr/bin/bash start_data_upload'], shell=True)
times = 3
def on_connect_fail(client, userdata):
print("失败,执行本地存储")
subprocess.Popen(["supervisorctl stop sensor_to_server && supervisorctl start sensor_to_local"], shell=True)
subprocess.Popen(['/usr/bin/bash stop_data_upload'], shell=True)
times = 3
if __name__ == '__main__':
while True:
try:
client = mqtt.Client(transport="websockets")
client = mqtt.Client()
client.username_pw_set("demo", "123456")
# Specify callback function
client.on_connect = on_connect
client.on_connect_fail = on_connect_fail
# Establish a connection
client.connect('ceshi-mqtt.lihaink.cn', 8083)
client.connect('ceshi-mqtt.lihaink.cn', 1883)
# Publish a message
client.loop_forever()
except Exception as e: