Option Explicit On Option Strict On Module Module1 Sub Main() Dim M As New MQTT_Client() AddHandler M.Connected, AddressOf hMQQTConnected ' M.Connect_ClientID = "HelloWorld" M.Connect_CleanSession = True M.Connect_KeepAlive = 60 * 2 M.Connect_WillMessage = "Ut oh..." M.Connect_WillTopic = "Crap" M.SetHost("mindy", 1883) M.Connect() 'While M.IsReady = False ' Console.Write(".") ' System.Threading.Thread.Sleep(100) 'End While 'Console.WriteLine() While True If Console.KeyAvailable Then Select Case Console.ReadKey.KeyChar Case "q"c : Exit While Case "s"c : M.SendPUBLISH_QoS0("Hello", System.Text.ASCIIEncoding.ASCII.GetBytes(Now.ToString("yyyyMMdd HH:mm:ss"))) End Select Else End If ' Do stuff?? 'System.Threading.Thread.Sleep(100) 'If System.Threading.ManualResetEvent.WaitAny({M.PUBLISHWaitHandle}, 100) <> System.Threading.WaitHandle.WaitTimeout Then ' While True ' Dim Msg As MQTT_Client.msgPUBLISH = M.GetNextPUBLISHMessage ' If Msg Is Nothing Then Exit While ' Console.WriteLine("PUBLISH: " + Msg.TopicName + ":" + Msg.H_QoSLevel.ToString + CStr(IIf(Msg.H_Retain, "R", "")) + ": " + System.Text.ASCIIEncoding.ASCII.GetString(Msg.Payload)) ' End While 'End If Dim Msg As MQTT_Client.msgPUBLISH = M.WaitOnePUBLISHMessage(100) If Msg IsNot Nothing Then Console.WriteLine("PUBLISH: " + Msg.TopicName + ":" + Msg.H_QoSLevel.ToString + CStr(IIf(Msg.H_Retain, "R", "")) + ": " + System.Text.ASCIIEncoding.ASCII.GetString(Msg.Payload)) End If End While M.SendDISCONNECT() End Sub Private Sub hMQQTConnected(sender As MQTT_Client) 'sender.SendSUBSCRIBE(New MQTT_Client.TopicFilters From {New MQTT_Client.TopicFilters.TopicFilterQoS("#", 0)}) sender.SendSUBSCRIBE(New MQTT_Client.TopicFilters From {New MQTT_Client.TopicFilters.TopicFilterQoS("homie/+/sensor/#", 0)}) End Sub End Module