Android Question Send and reveive an image using MQTT

Juan Marrero

Active Member
Licensed User
Longtime User
Is it possible to send and receive images using MQTT? I've been trying to do so but always get an error saying that the object i used cannot be serialized with serializator.ConvertObjectToBytes. I've tried with ImageView, Bitmap, Object, InputStream and Type (with ImageView inside).

These are 2 examples of what I've tried:
B4X:
'    Dim img As ImageView
          
'    img.Initialize("")
'    img.Bitmap = LoadBitmap(fd.FilePath, fd.ChosenName)
'
'    mqtt.Publish(mytopic, serializator.ConvertObjectToBytes(img))

     Dim iStream As InputStream         
     iStream = File.OpenInput(fd.FilePath, fd.ChosenName)
           
     mqtt.Publish(mytopic, serializator.ConvertObjectToBytes(iStream))

Also I can't receive the image in the server because I can't compare the object to an image because what the server receives is a Byte Array:
B4X:
If obj Is Image Then 'The example uses CircleData that is a Type with basic data types

End If
 

walterf25

Expert
Licensed User
Longtime User
I've never used MQTT, but i'm assuming you can generate a checksum and check that on the other side when it's received, and compare it.

Just a thought!

Walter
 
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime User
I used serialization because the MQTTExample uses it. It seems to be sending and receiving it but I'm having a hard time adding the image to a listview in b4j and to the customlistview in b4a. I'll post a new thread for this.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…