Please first attend either my introductory talk on MQTT, or someone else's. if they did not accept anyone’s introduction to MQTT talk, then the first 30 minutes of this tutorial will be an introduction to MQTT, and why it is better for IoT than using http.
This tutorial is based on the Paho Python IMqtt library.
First we will make sure that the MQTT server is working using the iMQTT client library. Login, send a message, watch the sent messages.
For this tutorial, the shared MQTT server will provide an MQTT topic with the “outside temperature”. The "outside temperature" varies sinusoidally over the course of a day. To speed development a simulated day passes every minute.
First we build a house process. The house process reads the outside temperature, adds a fixed amount of heat, and calculates the indoor temperature. To start with there are no lags. The house responds instantly. It prints both the outside and inside temperature. Of course heat and temperature are in different units so we assume that the house has a thermal capacity of 1 unit of heat (Joule per Kelvin) per degree celsius.
Next we add a thermostat process. It has a target temperature. The thermostat receives the outside temperature, applies a correction and publishes how much heat the house needs
Next we update the house process. The house reads the outside temperature, adds the heat recommended by the thermostat, and reaches the controlled temperature. if your inital house or thermostat did not work correctly, a working one will be provided.
For those who finish early, or want to keep working on this at home, we can treat the house as a heat capacitor. The amount of heat lost is proportional to the outside temperature. The amount of heat gained is based on the thermostat settings. You can try to build an optimal control policy.
By the end of this class you will be able to build a simple feedback control loop for MQTT Python IoT applications. This is a simple example, but very typical of IoT problems.
The last hour of this class will be spent discussing people’s specific applications. You are invited to say what it is you are building, and discuss any particular issues or concerns which you may have.
To guard against network failures, I will run a local area network on my laptop with an MQTT server and the weather process.
Comments Sign in to post comments