I'm trying to send an image over paho-mqtt. I can send a simple string via client.publish() or when not using the paho.client -> client.publish(), but publish.single() my bytearray.
When trying to send the bytearray with client.publish() I get a socket error on my broker and it doesnt send my message (No on_publish call). What am I missing?
client = paho.Client()
client.on_connect = on_connect
client.on_publish = on_publish
client.connect(MQTT_BROKER, MQTT_PORT)
f = open("foo.jpg", "rb")
fileContent = f.read()
f.close()
byteArr = bytearray(fileContent)
client.publish("/data", byteArr) # only works with strings. socket error on broker when using bytearray
# publish.single("/data", byteArr, hostname=MQTT_BROKER) # works with string and bytearray