0
0
IOT Protocolsdevops~10 mins

MQTT keep-alive and timeout in IOT Protocols - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the MQTT keep-alive interval to 60 seconds.

IOT Protocols
client.connect(broker_address, keepalive=[1])
Drag options to blanks, or click blank then click option'
A60
B0
C120
D30
Attempts:
3 left
💡 Hint
Common Mistakes
Setting keep-alive to 0 disables it, which is not recommended here.
2fill in blank
medium

Complete the code to handle MQTT client timeout after missing pings.

IOT Protocols
client.on_disconnect = lambda client, userdata, rc: print('Disconnected with result code [1]')
Drag options to blanks, or click blank then click option'
A4
B0
C1
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing result code 0 (normal disconnect) with timeout code.
3fill in blank
hard

Fix the error in the MQTT client setup to correctly specify the keep-alive parameter.

IOT Protocols
client.connect(broker, port, keepalive=[1])
Drag options to blanks, or click blank then click option'
A'60'
B60
Cnull
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around numbers for keepalive.
4fill in blank
hard

Fill both blanks to create a dictionary that sets keep-alive to 45 and timeout to 120 seconds.

IOT Protocols
config = { 'keepalive': [1], 'timeout': [2] }
Drag options to blanks, or click blank then click option'
A45
B60
C120
D30
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up keepalive and timeout values.
5fill in blank
hard

Fill all three blanks to create a function that sets keep-alive, timeout, and prints a status message.

IOT Protocols
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')
Drag options to blanks, or click blank then click option'
A30
B120
Ckeep_alive
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Using hardcoded values instead of function parameters in print.