set_led_level(data) at line (6) is where we integrate with GPIOZero to change the brightness of our LED and the method similar to the corresponding methods we covered in Chapter 3, Networking with RESTful APIs and Web Sockets Using Flask, so we will not cover the internals here again:
def set_led_level(data): # (6)
...
The data parameter is expected to be a Python dictionary in the form of { "level": 50 }, where the integer is between 0 and 100 to indicate the brightness percentage.
Next, we have the callback functions for MQTT. We'll start by reviewing on_connect()Â and on_disconnect().