O'Reilly logo

Mastering Internet of Things by Peter Waher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Publishing the light field

When we have chosen the quality of service, we need to decide whether the content should be retained by the broker on the given topic. In our example, we choose not to. A new subscriber will be updated anyway if the sensor is connected. If the sensor is not connected, we don't want to give new subscribers obsolete sensor data.

The last parameter of the PUBLISH() method contains the actual payload of the packet we want to publish. Payloads in MQTT are always binary! There are no rules for how the content is encoded. We choose to encode our string using UTF-8:

 this.mqttClient.PUBLISH( "Waher/MIOT/" + this.deviceId + "/Light", MqttQualityOfService.AtMostOnce, false, Encoding.UTF8.GetBytes(ValueStr)); this.PublishLastJson(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required