We have implemented an MQTT interface with support for TLS security. Here's what you need to do:

  1. Use a broker address of mqtt.pndsn.com
  2. Use the standard ports: 1883 for unsecured connections; 8883 for secured (TLS) connections
  3. Use a Client ID composed like this: <publish_key>/<subscribe_key>/<actual_device_ID>
    In other words make your device ID be in three parts, separated by slash (/). The first part is your PubNub publish key, the second part is your PubNub subscribe key, and the last part is the actual unique device identifier.

IMPORTANT: to ensure that you do not receive duplicate messages, make sure that each MQTT client has a unique clientid, for example:

  • client 1 - [pubkey]/[subkey]/clientid1
  • client 2 - [pubkey]/[subkey]/clientid2

You can use any MQTT client to test this before you get started but be sure it support MQTT 3.1 or newer. Older versions have limitations on the length of the client ID (24 characters or less!). 

MQTT.fx Client Example

This is an example of using MQTT.fx client to connect, send and receive a message using PubNub's MQTT interface. This should work the same for any other MQTT client or API/framework as long as it supports MQTT v3.1 or later.

Connecting to the PubNub Network

Using the PubNub demo pub/sub keys (use your own free PubNub key set for your purposes), you can see how easy it is to setup a connection to PubNub's MQTT Interface. The client ID (clientid1) is completely random. You can generate a client ID and then prepend your pub/sub keys to that or just make up a simple one like below. There are more properties to MQTT.fx connection profile but all the defaults will work (customize at your own risk).

Once you have created a connection profile, select it and click Connect.

Subscribe to topic1 from MQTT.fx

Enter topic1 as the the topic (channel) and click the Subscribe button.

Subscribe to topic1 from PubNub Dev Console

Before you publish a message, use the PubNub Dev Console to subscribe to the topic (channel), just to prove that it is going through the PubNub Network like any other message that is sent through PubNub using a PubNub SDK or the PubNub REST API. Just enter demo for the publish and subscribe keys (or use your own key set but has to be the same keys you are using in MQTT.fx for this demo), and topic1 as the channel (no need to change the origin) and click the SUBSCRIBE button.

Not shown in above screenshot, watch the messages output panel in the Dev Console when you publish a message from MQTT.fx.

Publish a message to topic1 using MQTT.fx

Enter topic1 as the target topic (channel) and a sample message like below and click the Publish button. 

    {"text":"hello, from MQTT.fx"}

After you click the Publish button, go back to the Subscribe section to verify that the message was received. If you see it, it means that the message was sent to the PubNub Network and back to MQTT.fx client successfully.

To verify that the message did go through the PubNub Network, go back to the PubNub Dev Console and look at the messages output panel.

Publish a message to topic1 from PubNub Dev Console

While you are looking at the messages output panel to verify that the message was received by the PubNub Dev Console, try publishing a message (see the message input box just above the messages output panel to enter/publish your message) and return back to MQTT.fx to verify that the message was received successfully.

Now your MQTT applications are ready for the big time by leveraging PubNub's proven highly scalable and super secure Realtime Network. If you have any issues or questions, please contact PubNub Support.

See Also: