Sub Class_Globals
Private tim As Timer
Private iCount As Int = 0
Private mqtt As MyMQTT
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
tim.Initialize("tim", 1000)
tim_Tick
tim.Enabled = True
InitializeMyMQTT
StartMessageLoop
End Sub
Sub InitializeMyMQTT
mqtt.Initialize(Me, "mq")
mqtt.InitializeBroker("user", "passforuser", 56000)
mqtt.InitializeClient("user", "passforuser", "127.0.0.1", 56000)
mqtt.Connect
Do While True
Sleep(1000)
Log("In Here")
If mqtt.IsClientConnected Then
mqtt.Subscribe("SampleTopic", mqtt.QOS_0_MOST_ONCE)
Exit
End If
Loop
End Sub
Private Sub mq_Connected(Success As Boolean)
End Sub
Private Sub mq_Connected2(Success As Boolean, ClientID As String)
End Sub
Private Sub mq_Disconnected
End Sub
Private Sub mq_Disconnected2(ClientID As String)
End Sub
Private Sub mq_MessageArrived(Topic As String, Payload() As Byte)
Log(BytesToString(Payload, 0, Payload.Length, "UTF-8"))
End Sub
Sub StopEverything
#if b4i
#Else
Try
mqtt.StopBroker
Catch
Log(LastException)
End Try
#End If
Try
mqtt.StopClient
Catch
Log(LastException)
End Try
End Sub
Private Sub tim_Tick
iCount = iCount + 1
Log(iCount)
End Sub