### Publish a Message

To publish a MQTT message, the payload must be converted to a bytes string.
Option 1 = String.GetBytes
Dim valuestr As String = NumberFormat(value,0,0)
mqtt.Publish(mqtttopicilluminance, valuestr.GetBytes("UTF8"))
Option 2 = ByteConverter Library.
'Textfields used to set the topic and the message to publish
Private tfPublishTopic As TextField
Private tfPublishMessage As TextField
'Some values
tfPublishTopic.Text = "test/topic"
tfPublishMessage.Text = "Hello World"
'Publish
Try
Dim bc As ByteConverter
mqtt.Publish2(tfPublishTopic.Text, bc.StringToBytes(tfPublishMessage.Text, "utf8"), 0, False)
Log($"${DateTime.Time(DateTime.Now)} - Topic published."$)
Catch
Log($"${DateTime.Time(DateTime.Now)} - Error publishing topic."$)
End Try

Changed: , Category: MQTT, File: T6C221M1627.htm, ID: 1627