Android Question MQTT payload type

August Jimenez

Licensed User

I'm doing some test with a MQTT broker, using the MQTTBox tool, to verify all is working well, before use my APP. The topic to publish and the payload used are in the following screenshot:

With this tool, all is working fine. When I use the APP, I can connect to the broker perfectly, but the publish topic does not arrive correctly. My piece of code is the following:

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        mqtt.Initialize("mqtt", serverURI, "xxxxxxx")

        Dim mo As MqttConnectOptions
        mo.Initialize("xxxxxxxx", "yyyyyyyy")

        Dim jo As JavaObject = mo

        jo.RunMethod("setSocketFactory", Array(CreateTrustAllSSLSocketFactory))

    End If
End Sub

Sub CreateTrustAllSSLSocketFactory As Object
    Dim tm As CustomTrustManager
    Dim SSLContext As JavaObject
    SSLContext = SSLContext.InitializeStatic("").RunMethod("getInstance", Array("TLS"))
    SSLContext.RunMethod("init", Array(Null, tm, Null))
    Dim Factory As JavaObject = SSLContext.RunMethod("getSocketFactory", Null)
    Return Factory
End Sub

Sub mqtt_Connected (Success As Boolean)
    If Success = False Then 
        Log("Error connecting: " & LastException)

        mqtt.Publish("v/a/g/141414141414/s/temperature-141414141414-1", serializator.ConvertObjectToBytes("1539878280000,25.5"))

    End If
End Sub
As can be seen in the screenshot, the payload should be "Strings / JSON / XML / Characters", but in the "Publish" method of the jMQTT library, the payload must be "Byte".

How can I send this kind of payload?

Thanks and regards