1. Connecting with Mosquitto without using TLS
Follow next indications to connect with mosquitto_sub y mosquitto_pub to MyQttHub.com:
Create a couple of credentials if you do not have them (look at the following link: How to create and manage your MQTT devices with MyQttHub.com )
You must create two credentials: one for sending and another to receive messages. If you want to reuse same credentials look at: How to skip MQTT connection replace, reusing same credentials
Now, to connect (without using TLS), run the following command (replacing , y with your credentials):
>> mosquitto_sub -h node02.myqtthub.com -i <client-id> -u <username-> -P '<password>' -t message/topic/to/subscribe -q 2
Previous command will subscribe and print all messages received on that topic. Now, in another terminal and without stopping previous command, send messages with the following:
>> mosquitto_pub -h node02.myqtthub.com -i <client2-id> -u <username2> -P '<password2>' -t message/topic/to/subscribe -m "hello world"
If everything went ok, you will see messages sent printed at the terminal running mosquitto_sub.
2. Connecting with Mosquitto using TLS
Now, to connect to MyQttHub.com using TLS and mosquitto_sub and mosquitto_pub you will have to add “-p 8883 --capath /etc/ssl/certs” like this:
`>> mosquitto_sub -h node02.myqtthub.com -p 8883 --capath /etc/ssl/certs -i <client-id> -u <username-> -P '<password>' -t message/topic/to/subscribe -q 2`
These options are:
-p 8883instruct mosquitto to connect to 8883 TLS port
--capathinstruct mosquitto where to find public root certificates to complete client certificate trust chain.
- These options (-p and --capath) must be configured on both commands (mosquitto_sub and mosquitto_pub).