Android Question MQTT payload type

Discussion in 'Android Questions' started by August Jimenez, Oct 18, 2018.

  1. August Jimenez

    August Jimenez Member Licensed User

    Hi,

    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:

    [​IMG]

    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:

    Code:
    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))

            mqtt.Connect2(mo)
           
        
    End If
       
    End Sub

    Sub CreateTrustAllSSLSocketFactory As Object
       
        
    Dim tm As CustomTrustManager
       
        tm.InitializeAcceptAll
       
        
    Dim SSLContext As JavaObject
       
        SSLContext = SSLContext.InitializeStatic(
    "javax.net.ssl.SSLContext").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)
           
        
    Else
           
            
    log("Connected")

            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
     

    Attached Files:

  2. DonManfred

    DonManfred Expert Licensed User

    Johan Hormaza likes this.
  3. August Jimenez

    August Jimenez Member Licensed User

    Thank you very much, DonManfred. Now it's working well.

    Regards
     
    DonManfred likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice