B4J Question MQTT connection setup

hakha4

Member
Licensed User
Longtime User
I try to connect to a Mqtt broker online (https://about.gbridge.io/) that works like a bridge against Google home. The connection info is as below:
Hostname: mqtt.gbridge.io
Port: 8883
Username: Shown in your account’s dashboard under “My Account”
Password: Is your account’s password by default, but can be changed independently.
TLS: TLS V1.2 is required

Code:
B4X:
AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.SetFormStyle("UNIFIED")
    MainForm.RootPane.LoadLayout("1") 'Load the layout file.
    MainForm.Show
 
    Dim clientId As String = Rnd(0, 999999999) & DateTime.Now 'create a unique id
    Dim mo As MqttConnectOptions
    mo.Initialize(user, password)' set in  Process_Globals
    Dim jo As JavaObject = mo


    'jo.RunMethod("SetSSLProperties",?)' how to set 'TLS' true ???
 
    mqtt.Initialize("mqtt", "mqtt.gbridge.io:8883", clientId)
 
 
    mqtt.Connect2(mo)
    mytopic = "gBridge/xxxx/xxxx/onoff" & mqtt.ClientId
    StatusBar1.Initialize("StatusBar1")
    MainForm.RootPane.AddNode(StatusBar1, 0, 0, -1, 30)
    MainForm.RootPane.SetAnchors(StatusBar1, 0, -1, 0, 0)

End Sub

If I run code without taking 'TLS' into account I get java.lang.NullPointerException ....... at mqtt.initialize line. I don't know how to set the SSL property but when trying with NULL (jo.RunMethod("SetSSLProperties",NULL)) it throws error: java.lang.RuntimeException: Method: SetSSLProperties not found in: org.eclipse.paho.client.mqttv3.MqttConnectOptions.

Can someone help me pointing out how to set properties correct in MqttConnectOptions ? I have not found enough information in forum to solve this by myself. What basic is wrong in connection code ? It would be nice to get a bridge to Google home!
Regards Håkan

Sorry, posted in WRONG forum by mistake, should have been B4J. Don't know how to change that
 

hakha4

Member
Licensed User
Longtime User
Thank's. Run's without error now but complain's about missing certificate ((SunCertPathBuilderException) sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target). I'll try to solve that.
 
Upvote 0
Top