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

Connecting to the broker

Once we have our Device ID and know which broker we want to use, it's easy to connect to it. We begin by defining an MQTT client variable for our application:

private MqttClient mqttClient = null; 

We then create the corresponding MqttClient object (defined in the Waher.Networking.MQTT namespace). Creating the object will automatically connect to the broker:

this.mqttClient = new MqttClient("iot.eclipse.org", 8883, true, 
   this.deviceId, string.Empty); 

The first parameter defines the host name or IP address of the broker. The second defines the port to connect to. The iot.eclipse.org broker supports unencrypted MQTT communication on port 1883 and encrypted communication on 8883. We choose the encrypted version (third ...

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