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.
19 lines
560 B
19 lines
560 B
5 months ago
|
import paho.mqtt.client as mqtt
|
||
|
|
||
|
def on_connect(client, userdata, flags, rc,properties):
|
||
|
print("Connected with result code " + str(rc))
|
||
|
client.subscribe("test/image")
|
||
|
|
||
|
def on_message(client, userdata, msg):
|
||
|
with open("received_image.jpg", "wb") as image_file:
|
||
|
image_file.write(msg.payload)
|
||
|
print("Image received and saved")
|
||
|
|
||
|
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, )
|
||
|
client.on_connect = on_connect
|
||
|
client.on_message = on_message
|
||
|
|
||
|
client.connect("121.40.129.71", 48835, 60) # 连接到 MQTT 代理
|
||
|
|
||
|
client.loop_forever()
|