To add MQTT support to our sensor, we will use the
MqttClient class defined in the
Clayster.Library.Internet.MQTT namespace. We start by adding the following namespace to our
using section in the code:
Communication with the MQTT server will be done from a separate thread in our example. This is to assure that we avoid timing problems with the measurement logic. When new values are available, we flag this fact to the MQTT thread using auto-reset event objects. So, we need the following static variables:
private static Thread mqttThread = null; private static AutoResetEvent mqttNewTemp = new AutoResetEvent(false); private static AutoResetEvent mqttNewLight = new AutoResetEvent(false); ...