This is a simple program that shows how does the "subscriber" in MQTT server model works. It's a little bit more complicated than the "publisher" but it is still the basic things you need to know. As in the publisher we have an IP address which you have to edit to your case, for more explanation you can see this program. It also have a Client instance, but this time we have to "subscribe", not to "publish". The more complicated thing here is that we have one function called "on_message". It prints the topic and the message, which is posted. Our client is subscribed to topic "Air Conditioner" respectivly the printed topic always will be "Air Conditioner". The function is called every time when somebody post a message on this topic. For this purpouse we have the "on_message", which actually catches the messages. For now we'll not discuss what magic stands behind the "on_message". The last thing you need to know is the infinite loop which we start, because our "subscriber" have to check non-stop for messages.
- 14 Dec 2018