MQTT Connection Guide-[EN]
MQTT Connection Overview
W232N supports MQTT client and MQTTS client mode.
Required Hardware and Software
Hardware
- W232N
- 5V Power adapter
- Cables (Ethernet / Serial)
Software
- WIZnet S2E Configuration Tool
- Mosquitto:
How to Connect to MQTT Broker through Mosquitto
W232N 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
- Select MQTT client mode in the Operation mode setting section
Figure: Select MQTT client mode |
- Setup the remote host IP (or URL) and remote port in the Remote host / port section
Figure: Setup remote host IP and remote port |
- Setup MQTT options
Figure: Setup MQTT options |
- 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
- To use AWS services, you must first sign in. Click the link below to go to the sign in page.
- Once logged in, search for “IoT Console” in the search bar and click on it.
Figure: Search “IoT Console" |
- Click the “Things” tab on the left, then hit the orange “Create things” button.
Figure: click "Create Things" |
- Select “Create single thing” and press the Next button.
Figure: Select "Create things" |
- Enter “Thing name” and hit the Next button.
Figure: Enter "Thing name" |
- Select “Auto-generate a new certificate (recommended)” and press the Next button.
Figure: Select "Auto-generate a new certificate" and click "Next" |
- Next, you need to create a policy for securing your Thing. Click “Create policy”.
Figure: Click "Create policy" |
- Set a name for the policy, configure the Policy Document as shown, and hit the Create button.
Figure: Setting policy information |
- Go back to the “Create single thing” page you opened earlier and press the “Create thing” button.
Figure: Click "Create thing" |
- Download all keys and certificates.
Figure: Download all keys and certificates |
Step 2: Enter the certificate on the device
- In AWS, enter the MQTT Test Client tab and copy the endpoint.
Figure: Copy Endpoint |
- 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 |
- 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” |
- Go to the Certificate Manager tab and adjust the Root CA section as shown below.
Figure: Adjust the Root CA section |
- 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 |
- Press each of the “Save to device” buttons.
Figure: Save certificate and key files |
- click “Apply settings”.
Figure: click “Apply settings” |
Step 3: Run (Subscribe)
- 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 |
- Open your device's serial port using a terminal tool to transfer data.
Figure: Transfer data |
- This will ensure that your MQTT communication with AWS is working correctly.
Figure: Successful MQTT communication with AWS |
Step 4: Run (Publish)
- 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 |
- In the Serials window, you can see the data sent by AWS.
Figure: Successful MQTT communication with AWS |