This article uses MQTT.fx as an example to introduce the method for using a third-party MQTT client to connect to IoT Platform. MQTT.fx is a MQTT client that is written in Java language and based on Eclipse Paho. It supports subscribing to messages and publishing messages through topics.

Prerequisites

You have created products and devices in the IoT Platform console, and have got the ProductKey, DeviceName, and DeviceSecrect of the devices. When you set the connection parameters for MQTT.fx, you will use the values of the ProductKey, DeviceName, and DeviceSecrect. For more information about creating products and devices, see Create a product and Create a device if you are using IoT Platform Basic, and see Create a product and Create a deviceif you are using IoT Platform Pro.

Procedure

  1. Download and install the MQTT.fx software.

    Download the MQTT.fx software for Windows from: http://mqtt-fx.software.informer.com/download/.

    Download the MQTT.fx software for Mac from: http://macdownload.informer.com/mqtt-fx/.

  2. Open MQTT.fx, and click the settings icon.


  3. Set the connection parameters.

    Currently, two types of connection modes are supported: TCP and TLS.

    • Set parameters for TCP connection.
      1. Enter basic information.


        • Profile Name: Enter a custom profile name.
        • Profile Type: Select MQTT Broker.
        • Broker Address: Enter the connection domain in the format ${YourProductKey}.iot-as-mqtt.${region}.aliyuncs.com. In this format, ${YourProductKey} and ${region} are two variables, whose respective values are your product key and the region ID of your IoT Platform service region. For information about region IDs, see Regions and zones. Example: alPUPCoxxxx.iot-as-mqtt.cn-shanghai.aliyuncs.com.
        • Broker Port: Set the port to 1883.
        • Client ID: Enter the content in the format ${clientId}|securemode=3,signmethod=hmacsha1|. ${clientId} is your client ID. You can enter any value, and the maximum length is 64 characters. We recommend that you use the MAC address or SN code of your device as the client ID. signmethod is the signature method you want to use. IoT Platform supports hmacmd5 and hmacsha1. Example: 12345|securemode=3,signmethod=hmacsha1|.
          Note
          Do not click Generate after you enter the Client ID information.
        • You can keep the default parameters for General, or set the values according to your needs.
      2. Click User Credentials, and enter your User Name and Password.


        • User Name: It must be the device name directly followed by the character (&) and the product key. Format: ${YourDeviceName}&${YourPrductKey}. The values of ${YourDeviceName} and ${YourPrductKey} respectively are the device name and product key. For example, the user name could be device&fOAt5H5TOWF.
        • Password: You must enter a encrypted value.

          Encryption method:

          Sort and join the parameters (clientId, deviceName, productKey, and timestamp in a lexicographical order. (If you have not set a timestamp, do not include timestamp in the string.) Then, use the deviceSecret of the device as the secret key to encrypt the resulting string by hmacsha1 or hmacmd5.

          Joint string example: clientId12345deviceNamedeviceproductKeyfOAt5H5TOWF.

          You can then enter the encrypted result as the password.

          For more information about encryption, see Direct connection to the MQTT client domain.

          You also can use a password generation tool to generate a password, or to verify the password you encrypted. Click here to download the tool package.

      3. Click OK after you have entered the required information.
    • Set parameters for TLS connection
      The method for setting parameters for TLS connection is almost the same as that for TCP, with the following two differences:
      • In Client ID, the securemode of TLS is different from that of TCP. For TLS connection, it must be securemode=2. Example: 12345|securemode=2,signmethod=hmacsha1|.


        The formats of the User Name and Password of User Credentials are the same as those of TCP.



      • For TLS connection, you must set SSL/TLS. Check Enable SSL/TLS and select TLSv1 as the protocol.


  4. Click Connect to connect MQTT.fx and IoT Platform.


Message communication test

Test if MQTT.fx and IoT Platform are successfully connected.

  1. In MQTT.fx, click Subscribe.
  2. Enter a topic of the device, and click Subscribe.


    If the topic is successfully subscribed to, it is displayed in the list.



  3. Go to the IoT Platform console. On the Topic List page of the Device Details, click the Publish button of the topic you subscribed to.
  4. Enter message content, and click OK.


  5. Go back to MQTT.fx to check if the message is received.


View logs

In MQTT.fx, click Log to view the operation logs and error logs.