Challenge: Using a smartphone to control the system
By just changing a couple of settings in the Mosquitto config file (mosquitto.conf, located in the Mosquitto installation directory), it’s possible to access the broker from other devices in the network. A simple way to get started is to uncomment `listener 1883` and also `allow_anonymous true`. Use the search functionality in your text editor to find the lines with those texts, and remove the hashtag at the start of those lines.
listener 1883 allow_anonymous true
After changing the configuration, restart the mosquitto service to apply the changes. Then, download an app that can connect to MQTT brokers (“MQTT Dash” is a popular Android app, but any similar app will do the trick). In the app, configure a client to talk to the address of your pc with the Mosquitto broker (you can find the ip by running `ipconfig` in the command prompt).
Here is an example of how the final setup can look (the black screen to the left is the smartphone).
In this example, two new topics are introduced: ‘master_fan’ and ‘master_light’. These can be added to the previous code as in the example below.
if inputs['sensor'] == 'OFF' or inputs['master_fan']: outputs['power'] = 'ON' else: outputs['power'] = 'OFF'