0
0
IOT Protocolsdevops~20 mins

mosquitto_pub and mosquitto_sub commands in IOT Protocols - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
MQTT Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of mosquitto_pub with QoS 1
What is the output or result when running this command?
mosquitto_pub -h test.mosquitto.org -t "home/temperature" -m "22" -q 1
IOT Protocols
mosquitto_pub -h test.mosquitto.org -t "home/temperature" -m "22" -q 1
AThe command fails with a syntax error due to missing -p port option
BThe message "22" is published but with QoS 0, ignoring the -q flag
CThe message "22" is published to topic "home/temperature" with QoS 1, and the command exits with status 0
DThe command connects but does not send any message because -m is ignored
Attempts:
2 left
💡 Hint
The -q flag sets the Quality of Service level for message delivery.
💻 Command Output
intermediate
2:00remaining
mosquitto_sub output for retained messages
If a retained message "ON" exists on topic "home/lights", what will this command output immediately after subscribing?
mosquitto_sub -h test.mosquitto.org -t "home/lights"
IOT Protocols
mosquitto_sub -h test.mosquitto.org -t "home/lights"
AIt prints an error about missing -m flag
BIt immediately prints "ON" and then waits for new messages
CIt prints nothing until a new message is published
DIt disconnects immediately without output
Attempts:
2 left
💡 Hint
Retained messages are sent to new subscribers immediately.
Configuration
advanced
2:30remaining
Correct mosquitto_pub command to use TLS with client certificate
Which mosquitto_pub command correctly publishes message "Hello" to topic "secure/topic" using TLS with client certificate and key files located at /certs/client.crt and /certs/client.key?
Amosquitto_pub -h broker.example.com -t "secure/topic" -m "Hello" --cafile /certs/ca.crt --cert /certs/client.crt --key /certs/client.key -p 8883
Bmosquitto_pub -h broker.example.com -t "secure/topic" -m "Hello" --cert /certs/client.crt --key /certs/client.key
Cmosquitto_pub -h broker.example.com -t "secure/topic" -m "Hello" --tls --cert /certs/client.crt --key /certs/client.key
Dmosquitto_pub -h broker.example.com -t "secure/topic" -m "Hello" --cafile /certs/ca.crt -p 1883
Attempts:
2 left
💡 Hint
TLS requires specifying the CA file and client cert/key along with the secure port.
Troubleshoot
advanced
2:00remaining
Troubleshooting mosquitto_sub connection failure
You run this command:
mosquitto_sub -h 192.168.1.100 -t "sensor/data" -p 1884

But it fails to connect. What is the most likely cause?
AThe topic name "sensor/data" is invalid
BThe mosquitto_sub command requires -m flag to connect
CThe IP address 192.168.1.100 is unreachable due to firewall
DThe broker is not listening on port 1884, default is 1883
Attempts:
2 left
💡 Hint
Check the broker's listening port and firewall settings.
🔀 Workflow
expert
3:00remaining
Sequence to test message delivery with mosquitto_pub and mosquitto_sub
Arrange the steps in correct order to test publishing and subscribing to a topic using mosquitto_pub and mosquitto_sub on the same machine.
A1,2,3,4
B2,1,3,4
C1,3,2,4
D2,3,1,4
Attempts:
2 left
💡 Hint
Subscribe first to receive messages published after subscription.