Connect to a broker with will message
Private Sub Connect_WithWillMsg() On Error GoTo errExit Dim connOption As MQTTConnectOption Dim retCode As MqttConnectionCode Set mFactory = Application.CreateMQTT Set mClient = mFactory.CreateClient Set connOption = mFactory.CreateConnectOption() connOption.ClientID = "Client01" connOption.Version = MqttVersion500 connOption.Protocol = MqttProtocolTcp connOption.WithTcpServer "broker.com", 1883 Dim will As MQTTWillMessage Set will = connOption.WillMessage will.PayloadFormat = MqttPayloadCharacter will.contenttype = "String" will.payload = "This is will message." will.Topic = "SE" Dim data() As Byte data = StrConv("This is the correlation.", vbFromUnicode) will.correlation = data will.ResponseTopic = "This is the response topic." will.AddUserProperty "Head1", "Node1" will.QoS = MqttQoS2 will.retain = True retCode = mClient.Connect(connOption) Exit Sub errExit: MsgBox err.Description End Sub
Provide Feedback