Android Question MQTT Connect() not working

AndroidMadhu

Active Member
Licensed User
Hello,
MQTT Connect() not working, also no error is coming at log. Nothing showing in error logs.
When I am running the below example [as per below link] it is running fine....
https://www.b4x.com/android/forum/threads/jmqtt-official-android-mqtt-client.59497/#content

But the below code is not running when I am incorporating the above codebase into my application....
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim cur As Cursor
Dim SQL1 As SQL
Dim mqtt As MqttClient
Dim sr As B4XSerializator
Private serverURI As String = "tcp://xxx.xxx.xxx.xxx:1883"
End Sub

Sub Activity_Create(FirstTime As Boolean)
.....

If FirstTime Then
mqtt.Initialize("mqtt", serverURI, Rnd(0, 999999999) & DateTime.Now)
Dim mo As MqttConnectOptions
mo.Initialize("usr", "psw")
mqtt.Connect2(mo)
Log("mqtt_init")
'Sleep(1000)

End If

End Sub

Sub mqtt_Connected (Success As Boolean)
If Success = False Then
Log(LastException)
lblStatus.Text = "Error connecting"
Else
Log("Connected")
lblStatus.Text = "Connected"
mqtt.Subscribe("outTopic", 0)
'mqtt.Subscribe("outTopic1", 0)
End If
End Sub
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
Dim cXML As String = BytesToString(Payload, 0, Payload.Length, "UTF8")
Log(Topic & "/" & cXML)
Select cXML
Case "clear"
Activity.Invalidate
Case "close"
Activity.Finish
End Select
' End If
End Sub

Sub Button2_Click
'For Publish to MQTT broker
Dim bc As ByteConverter
mqtt.Publish("outTopic",bc.StringToBytes("Hello","UTF8"))
End Sub

Am I missing anything?
Please advice
 
Top