Complete the code to set the MQTT keep-alive interval to 60 seconds.
client.connect(broker_address, keepalive=[1])The keep-alive interval is set to 60 seconds to ensure the client sends a ping to the broker every 60 seconds.
Complete the code to handle MQTT client timeout after missing pings.
client.on_disconnect = lambda client, userdata, rc: print('Disconnected with result code [1]')
Result code 1 indicates the client disconnected due to a network timeout or keep-alive failure.
Fix the error in the MQTT client setup to correctly specify the keep-alive parameter.
client.connect(broker, port, keepalive=[1])The keepalive parameter must be an integer, not a string or other type.
Fill both blanks to create a dictionary that sets keep-alive to 45 and timeout to 120 seconds.
config = { 'keepalive': [1], 'timeout': [2] }The keepalive is set to 45 seconds and timeout to 120 seconds as required.
Fill all three blanks to create a function that sets keep-alive, timeout, and prints a status message.
def setup_mqtt(client, keep_alive, timeout): client.connect('broker.hivemq.com', 1883, keepalive=[1]) client._timeout = [2] print(f'MQTT setup with keep-alive=[3] seconds and timeout=[2] seconds')
The function uses 60 seconds for keep-alive, 120 seconds for timeout, and prints the keep_alive parameter value.