Skip to main content

Get started

Follow this guide to compile the synchronous sample client and verify broker connectivity.

Before you begin

Make sure you have:

  • TrustCore SDK U6 or later (NanoMQTT is built in by default). To rebuild only NanoMQTT, run ./build.sh nanomqtt from projects/mqtt_client/.

  • A POSIX shell and a C11‑compatible tool‑chain.

  • (Optional) A system CA bundle. On most Linux distributions this is /etc/ssl/certs/ca-bundle.crt (or /etc/ssl/certs/ca-certificates.crt). If the file is missing or outdated, TLS verification will fail.

  • Access to a public or private MQTT broker. The examples use broker.hivemq.com.

Build the sample client (with SSL)

./scripts/nanomqtt/mqtt_client/build_mqtt_client.sh --ssl

The script creates mqtt_client_sample in mocn-mss/bin/.

cd mocn-mss   # run commands from here

Quick publish/subscribe demo

Export a few helper variables:

export MQTT_SERVER=broker.hivemq.com   # any MQTT‑5 capable broker
export MQTT_PORT=1883                  # TCP
export MQTT_SSL_PORT=8883              # TLS

Start a subscriber (plain TCP)

./bin/mqtt_client_sample \
--mqtt_servername ${MQTT_SERVER:-broker.hivemq.com} \
--mqtt_port ${MQTT_PORT:-1883} \
--mqtt_sub_topic demo/topic \
--mqtt_clean_start

Tip

See Command-line reference for option details.

The client blocks, waiting for messages.

Publish a message over TLS

./bin/mqtt_client_sample \
--mqtt_servername ${MQTT_SERVER:-broker.hivemq.com} \
--mqtt_port ${MQTT_SSL_PORT:-8883} \
--mqtt_transport SSL \
--ssl_ca_file /etc/ssl/certs/ca-bundle.crt \
--mqtt_pub_topic demo/topic \
--mqtt_pub_message "Hello NanoMQTT" \
--mqtt_clean_start

Look for the expected subscriber output:

demo/topic Hello NanoMQTT

Caution

--ssl_allow_untrusted disables server‑certificate validation and is suitable only for ad‑hoc tests.

What's next?