MQTT Communication with Mosquitto Broker (Non Secure MQTT, Port 1883)
Lab Objective:
In this lab, participants will explore the fundamentals of MQTT (Message Queuing Telemetry Transport) communication using the Mosquitto public broker at https://test.mosquitto.org on port 1883, with a PSoC6 board.

The PSoC-6 board connects to the internet through a Wi-Fi hotspot, publishes a message such as “TURN ON LED”, and the PSoC-6 board will subscribes to receive the message and turns on its LED.
🔥 Requirements
🚩 Let start
Create Application

Coding
1. Edit wifi_config.h
Use your mobile hotspot as an access point. Edit “wifi_config.h” to match your mobile SSID setting:
#define WIFI_SSID “mobile_ssid”
#define WIFI_PASSWORD “password”

2. Edit file mqtt_client.h
Edit the following in “configs/mqtt_client.h”:
MQTT_BROKER_ADDRESS to “test.mosquitto.org”
Set the macros MQTT_PORT to 1883
MQTT_SECURE_CONNECTION to 1
MQTT_USERNAME to “” MQTT_PUB_TOPIC to “unique_topic”
MQTT_SUB_TOPIC to “unique_topic”
MQTT_SNI_HOSTNAME to “test.mosquitto.org”

3. Save the file
4. Build and Launch the Application
Open Putty, baud rate 115200
Result
Press user button
The GPIO interrupt service routine (ISR) notifies the publisher task.
The publisher task publishes a message on a topic.
The MQTT broker sends back the message to the MQTT client because it is also subscribed to the same topic.
When the message is received, the subscriber task turns the LED ON or OFF. As a result, the user LED toggles every time the user presses the button.

🎉 Congratulations! You can now complete this lab
Supported toolchains (make variable 'TOOLCHAIN')
GNU Arm® embedded compiler v10.3.1 (
GCC_ARM
) - Default value ofTOOLCHAIN
Arm® compiler v6.16 (
ARM
)IAR C/C++ compiler v9.30.1 (
IAR
)
Supported kits (make variable 'TARGET')
PSoC™ 62S2 Wi-Fi Bluetooth® pioneer kit (
CY8CKIT-062S2-43012
)PSoC™ 62S1 Wi-Fi Bluetooth® pioneer kit (
CYW9P62S1-43438EVB-01
)PSoC™ 62S1 Wi-Fi Bluetooth® pioneer kit (
CYW9P62S1-43012EVB-01
)PSoC™ 62S3 Wi-Fi Bluetooth® prototyping kit (
CY8CPROTO-062S3-4343W
)
Related resources
ModusToolbox™ Software Training
Other resources
Infineon provides a wealth of data at www.infineon.com to help you select the right device, and quickly and effectively integrate it into your design.
Document history
1.0.0
MQTT via Mosquitto broker
Authors:
Assoc. Prof. Wiroon Sriborrirux
Mr. Sriengchhun Chheang
Mr. Sabol Socare
© BDH Corporation, 2022-2023
Last updated
Was this helpful?