msg MQTT message

main
zart 5 months ago
parent 2be07f8c8e
commit 20e0d57df5

@ -97,7 +97,7 @@ if [ -f "smp_init.sh" ]; then
fi fi
# 执行smp_init.sh # 执行smp_init.sh
# ./smp_init.sh ./smp_init.sh
echo "smp_init.sh 执行完成" echo "smp_init.sh 执行完成"
else else
echo "smp_init.sh 不存在" echo "smp_init.sh 不存在"

@ -8,7 +8,7 @@ port = 48835
with open("../user.txt", "r") as f: with open("edu_coder/user.txt", "r") as f:
user_id = f.read().strip() user_id = f.read().strip()
user_id = user_id.split("=")[-1] user_id = user_id.split("=")[-1]

@ -2,7 +2,7 @@ import paho.mqtt.client as mqtt
import time import time
import os import os
if not os.path.exists("user.txt"): if not os.path.exists("edu_coder/user.txt"):
os.system("bash get_user.sh") os.system("bash get_user.sh")
broker = '121.40.129.71' broker = '121.40.129.71'
@ -38,7 +38,7 @@ client.connect(broker, port, 60)
# 启动一个后台线程来处理网络流量和回调 # 启动一个后台线程来处理网络流量和回调
client.loop_start() client.loop_start()
with open("user.txt", "r") as f: with open("edu_coder/user.txt", "r") as f:
user = f.read().strip() user = f.read().strip()
# # 发布消息 # # 发布消息

@ -8,7 +8,7 @@ port = 48835
with open("../user.txt", "r") as f: with open("smp_coder/user.txt", "r") as f:
user_id = f.read().strip() user_id = f.read().strip()
user_id = user_id.split("=")[-1] user_id = user_id.split("=")[-1]
@ -27,7 +27,7 @@ def on_message(client, userdata, msg):
if msg.payload.decode() == "image produce": # 收到拍照请求 if msg.payload.decode() == "image produce": # 收到拍照请求
# 打开相机,拍照,保存图片,发送图片 # 打开相机,拍照,保存图片,发送图片
if not os.path.exists("/tmp/image.jpg"): if not os.path.exists("/tmp/image.jpg"):
os.system("bash camera.sh") os.system("bash smp_coder/camera.sh")
else: else:
client.publish("response/{}".format(user_id), "image produce success!", qos=2) client.publish("response/{}".format(user_id), "image produce success!", qos=2)

Loading…
Cancel
Save