Skip to main content

MQTT Connection Guide


MQTT Connection Overview

W55RP20-S2E supports MQTT client and MQTTS client mode.


Required Hardware and Software

Hardware

  • W55RP20-S2E
  • Cables (Ethernet / Serial)

Software


How to Connect to MQTT Broker through Mosquitto

W55RP20-S2E supports MQTT client and MQTTS client mode, but this section guides how to connect to MQTT broker through Mosquitto based on MQTT client mode.

Note : MQTTS client mode requires additional security-related settings, unlike MQTT client mode.

Step 1: Run Config-tool

Run installed 'Config-tool'

Step 2: Setup Mosquitto

Depending on the Mosquitto version, you may need to setup Mosquitto, so refer to the below to setup.

  • In Mosquitto versions earlier than 2.0 the default is to allow clients to connect without authentication.
  • In 2.0 and up, you must choose your authentication options explicitly before clients can connect.

Therefore, if you are using version 2.0 or later, refer to following link to setup 'mosquitto.conf' in the directory where Mosquitto is installed.

Step 3: Run MQTT Broker through Mosquitto

Ex>
mosquitto -c mosquitto.conf -p 1883 -v
Figure: Run MQTT broker through Mosquitto

Step 4: Setup Device through WIZnet S2E Configuration Tool for MQTT Broker Connection

  1. Select MQTT client mode in the Operation mode setting section
Figure: Select MQTT client mode
  1. Setup the remote host IP (or URL) and remote port in the Remote host / port section
Figure: Setup remote host IP and remote port
  1. Setup MQTT options
Figure: Setup MQTT options
  1. Click the Apply Settings button to save the settings
Figure: Click Apply Settings button
Figure: Saved settings

Step 5: Done

Device is successfully connected to the MQTT broker!

Figure: Status
Figure: Connect to MQTT broker

How to connect to AWS using MQTT

Step 1: Create a Thing and Policy in AWS and Download a Certificate

  1. To use AWS services, you must first sign in. Click the link below to go to the sign in page.

AWS login page



  1. Once logged in, search for “IoT Console” in the search bar and click on it.
Figure: Search “IoT Console"


  1. Click the “Things” tab on the left, then hit the orange “Create things” button.
Figure: click "Create Things"


  1. Select “Create single thing” and press the Next button.
Figure: Select "Create things"


  1. Enter “Thing name” and hit the Next button.
Figure: Enter "Thing name"


  1. Select “Auto-generate a new certificate (recommended)” and press the Next button.
Figure: Select "Auto-generate a new certificate" and click "Next"


  1. Next, you need to create a policy for securing your Thing. Click “Create policy”.
Figure: Click "Create policy"


  1. Set a name for the policy, configure the Policy Document as shown, and hit the Create button.
Figure: Setting policy information


  1. Go back to the “Create single thing” page you opened earlier and press the “Create thing” button.
Figure: Click "Create thing"


  1. Download all keys and certificates.
Figure: Download all keys and certificates




Step 2: Enter the certificate on the device

  1. In AWS, enter the MQTT Test Client tab and copy the endpoint.
Figure: Copy Endpoint


  1. Turn on the configuration tool to detect your device and set the “Basic settings” tab as follows
Figure: Set the “Basic settings” tab in the configuration tool


  1. Set up the “MQTT options” tab like this
  • MQTT Topics Section

    • Publish Topic: $aws/things/my_w232n_thing/shadow/update
    • Subscribe Topic: $aws/things/my_w232n_thing/shadow/update/accepted
  • MQTT Options

    • Client ID: my_w232n_thing
    • Keep-Alive: 60
    • QoS: QoS 0
  • Remote Host / Port

    • Remote Host: Paste the copied endpoint
    • Remote Port: 8883
Figure: Set “MQTT options”


  1. Go to the Certificate Manager tab and adjust the Root CA section as shown below.
Figure: Adjust the Root CA section


  1. Tap “Load file” to load the following certificate and key files
  • Root CA : AmazonRootCA1.pem
  • Client Certificate : xxxxx-certificate.pem.crt
  • Private Key : xxxxx-private.pem.key
Figure: Load certificate and key files


  1. Press each of the “Save to device” buttons.
Figure: Save certificate and key files


  1. click “Apply settings”.
Figure: click “Apply settings”




Step 3: Run (Subscribe)

  1. Go back to the AWS IoT Console page and click “MQTT test client” under the “Test” section to enter it. Then, in the MQTT Topics Section of the configuration tool, enter the Publish Topic $aws/things/my_w232n_thing/shadow/update in the “Topic filter” and hit the Subscribe button.
Figure: Subscrive topic


  1. Open your device's serial port using a terminal tool to transfer data.
Figure: Transfer data


  1. This will ensure that your MQTT communication with AWS is working correctly.
Figure: Successful MQTT communication with AWS




Step 4: Run (Publish)

  1. Return to the AWS IoT Console page and click “MQTT test client” under the “Test” section. Then in the MQTT Topics Section of the configuration tool, enter the Subscribe Topic $aws/things/my_w232n_thing/shadow/update/accepted in the “Topic name” and hit the Publish button.
Figure: Publish topic


  1. In the Serials window, you can see the data sent by AWS.
Figure: Successful MQTT communication with AWS