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

Monitoring connection events

Connecting to a broker is an asynchronous process that is error-prone and can take time. Applications should always strive to provide relevant feedback to their users as quickly as possible. For asynchronous communication processes, such relevant feedback can be showing the state of the process. The MqttClient object allows us to monitor this state, through the OnStateChanged event. For our example, we log each state change as an event:

this.mqttClient.OnStateChanged += (sender, state) => 
   Log.Informational("MQTT client state changed: " + 
         state.ToString()); 

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