小编ahn*_*tar的帖子

如何使用 mosquitto 发送图像?

我正在尝试在 Raspberry Pi2 中使用 MQTT mosquitto 代理(发布和订阅)发送 jpg 图像。

这是我的python代码pub.py(修改)

import paho.mqtt.client as mqtt

def on_publish(mosq, userdata, mid):
    mosq.disconnect()

client = mqtt.Client()
client.connect("test.mosquitto.org", 1883, 60)
client.on_publish = on_publish

f=open("b.jpg", "rb") #3.7kiB in same folder
fileContent = f.read()
byteArr = bytearray(fileContent)
client.publish("image",byteArr,0)

client.loop_forever()
Run Code Online (Sandbox Code Playgroud)

它是 sub.py(已修改)

import paho.mqtt.client as mqtt

def on_connect(client, userdata, rc):
    print("Connect" + str(rc))
    client.subscribe("image") 

def on_message(client, userdata, msg):
    print "Topic : ", msg.topic
    f = open("/tmp/output.jpg", "w")  #there is a output.jpg which is different
    f.write(msg.payload)
    f.close()

client = …
Run Code Online (Sandbox Code Playgroud)

python publish-subscribe mqtt raspberry-pi mosquitto

3
推荐指数
1
解决办法
2万
查看次数

使用 MQTT 发送的图像的最大尺寸是多少

我正在尝试在两个 R-pi 中使用 MQTT 发送一些图像。我想知道要发送的图像的最大尺寸是多少。我认为 1MB 是最大尺寸,但是 26.5KB 的图像无法发送。请回答我的问题谢谢。

python mqtt raspberry-pi mosquitto

1
推荐指数
1
解决办法
2192
查看次数