Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to specify the MQTT broker URL with TLS.
IOT Protocols
mqtt_client.connect("[1]")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'mqtt://' which is not secure
Using 'http://' which is for web protocols
Using 'tcp://' which is not specific to MQTT
✗ Incorrect
The prefix 'mqtts://' is used to connect to an MQTT broker over TLS, ensuring encrypted communication.
2fill in blank
mediumComplete the code to set the TLS certificate file path for the MQTT client.
IOT Protocols
mqtt_client.tls_set(ca_certs="[1]")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a log file path instead of a certificate
Using a config text file path
Using a socket file path
✗ Incorrect
The 'ca_certs' parameter requires the path to the CA certificate file to verify the broker's identity.
3fill in blank
hardFix the error in the code to enable TLS for the MQTT client.
IOT Protocols
mqtt_client.[1](tls_version=ssl.PROTOCOL_TLSv1_2) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'enable_tls' or 'start_tls'
Using 'set_tls' which is incorrect
✗ Incorrect
The correct method to configure TLS settings in the MQTT client is 'tls_set'.
4fill in blank
hardFill both blanks to configure the MQTT client with username and password for secure connection.
IOT Protocols
mqtt_client.username_pw_set(username="[1]", password="[2]")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing username and password values
Using default or guest credentials
✗ Incorrect
The username is set to 'user123' and the password to 'pass123' for authentication.
5fill in blank
hardFill all three blanks to create a dictionary for TLS settings including certificate, key, and TLS version.
IOT Protocols
tls_settings = {"ca_certs": "[1]", "certfile": "[2]", "tls_version": [3], "keyfile": "[4]"} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using key file path as certfile
Using incorrect TLS version constant
Mixing file paths
✗ Incorrect
The CA certificate, client certificate, client key, and TLS version are correctly set for secure MQTT connection.