B4R Question MQTT - Connect & Reconnect in B4R

Andrej Meszaros

Member
Licensed User
Longtime User
Hi,

Erel has a great solution for mqtt connection testing in B4A, B4i and B4J.
But how is it in B4R ?

Has anybody idea ?

Thanks

Andrej
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code is from one of the examples:
B4X:
Sub Connect(unused As Byte)
   If mqtt.Connect = False Then
     Log("trying to connect again")
     CallSubPlus("Connect", 1000, 0)
     Return
   End If
   Log("Connected to broker")
   mqtt.Subscribe("arduino", 0)
   mqtt.Publish2("pc", Array As Byte(1, 2, 3), True)
End Sub

Sub Mqtt_Disconnected
   Log("Disconnected")
   mqtt.Close
   Connect(0)
End Sub

Sub Mqtt_MessageArrived (Topic As String, Payload() As Byte)
   Log("Message arrived. Topic=", Topic, " payload: ", Payload)
End Sub
 
Upvote 0
Top