B4J Question Send zipped file as payload in MQTT

davelew1s

Active Member
Licensed User
Longtime User
HI! I am trying to send a zipped folder as paylod using MQTT, I have tried everthing I can think of but with no success. I m not sure it is even possible ... so if it is, any help will be welcome ... if it's not, then back to the drawering board.
Thanks Dave.
 

davelew1s

Active Member
Licensed User
Longtime User
Can you post the code you tried? Which error did you get?

You can send any data you like with MQTT.
Thanks for the reply here is the code for send and receive as it is,
it works ok on small zip files but very slow on bigger ones and on large files it causes the client to disconnect.
B4X:
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
    MainForm.Title = Topic
    Label1.Text = Label1.Text & Topic & CRLF
    Label1.Text = Label1.Text & Payload.Length & CRLF
    Dim t() As String
    t = Regex.Split(",",Topic)
 
    'Dim obj As Object = Payload     '    serializator.ConvertBytesToObject(Payload)
    'If Topic.Contains("main") Then 
     Dim out As OutputStream = File.OpenOutput(File.DirData("cloud/temp"), t(1), False)
     out.WriteBytes(Payload, 0, Payload.Length)
       out.Close
     'Dim ra As RandomAccessFile
     'ra.Initialize("C:\Users\Dave\AppData\Roaming\cloud\temp",t(1),False)
     'ra.WriteObject(Payload,False,ra.CurrentPosition)
    ' ra.WriteBytes(obj,0,Payload.Length,ra.CurrentPosition)
  
  
 
     Arc.AsyncUnZip(File.DirData("cloud/temp"),t(1), "C:\Users\Dave\Desktop" , "aaa")
     'Arc.UnZip(File.DirData("cloud"), "dave.zip", "C:\Users\Dave\Desktop" , "aaa")
    'End If
End Sub

Sub sendmessage
    mytopic = "workshop," & "test.zip"    'filenametosend
    'Dim fn As Object = File.OpenInput(File.DirData("cloud"),"test.zip" )
 
    mqtt.Publish2(mytopic,Bit.InputStreamToBytes(File.OpenInput(File.DirData("cloud"),"test.zip" )),0,False)
    'mqtt.Publish(mytopic, serializator.ConvertObjectToBytes(fn))
    'mqtt.Publish(mytopic,fn)
 
End Sub
 
Upvote 0

davelew1s

Active Member
Licensed User
Longtime User
The data is handled in memory so you might run out of available memory.

What is the size of the large zips?


Large zip 6Meg causes broker to disconnect
3 Meg works but takes several minutes
4Kb is almost instant
I'm using cloudmqtt as the broker
Thanks Dave.
 
Upvote 0
Top