Subscribe
The MQTT Subscribe function enables a client to subscribe to a message publisher by topic and QoS level. The capture of events for the specific client can also be turned on through the EnableEvents parameter if desired for troubleshooting purposes.
Note: Use the oMQTT.Connection function to connect the client.
Group: MQTT Object
Type: Function
Syntax:
oMQTT.Subscribe( Topic, Payload, QOS, Retain) As Boolean
Subscribe (Boolean) returns true if subscription succeeded, false if it failed
Topic (String) The topic (subject) of the message
QoS (Long) QOS 0: At most once (deliver and forget); QOS 1: At lease once ; QOS 2: Exactly once
EnableEvent (Boolean) True sets the message to be retained. False will not retain the message.
Example:
Dim WithEvents moClient As New MQTT
Private Sub btnPublish_Click()
On Error Resume Next
Dim sIndex As String
sIndex = Split(cboQOS.Text, " ")(0)
If Not moClient.Publish(txtTopic.Text, txtPayload.Text, CLng(sIndex), chkRetain.Checked) Then
App.MsgBox("Error: " & moClient.Error)
Exit Sub
Else
App.MsgBox("Published to " & txtTopic.Text)
End If
End Sub
Versions Supported: RFgen 5.1.1.35 and 5.2.3 and newer.