You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
478 B
15 lines
478 B
import paho.mqtt.client as mqtt
|
|
|
|
def publish_image(mqtt_client, topic, image_path):
|
|
with open(image_path, "rb") as image_file:
|
|
image_data = image_file.read()
|
|
mqtt_client.publish(topic, image_data)
|
|
|
|
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2,)
|
|
client.connect("121.40.129.71", 48835, 60) # 连接到 MQTT 代理
|
|
|
|
client.loop_start()
|
|
img_path = input("Enter the path of the image: ")
|
|
publish_image(client, "test/image", img_path)
|
|
client.loop_stop()
|