Prerequisites
Before you flash this example, make sure you have the following ready:- Your Wi-Fi SSID and password (2.4 GHz network — the ANX dev module does not support 5 GHz)
- Access to an MQTT broker with TLS on port 8883 — HiveMQ Cloud free tier works out of the box, or run a local Mosquitto instance
- ANX dev module running firmware 1.1.0 or later (TLS support was added in 1.1.0)
Configure Wi-Fi and MQTT
All runtime credentials live inconfig.json at the root of the example directory. Open the file and replace the placeholder values with your own before flashing — the ANX OS reads this file at boot and passes the settings to the Wi-Fi and MQTT drivers automatically.
config.json
Application Code
The application connects to Wi-Fi, establishes a TLS-secured MQTT session, then enters a loop that reads the ADC, formats a JSON payload, and publishes it every five seconds.connectivity.c
Run and Verify
Flash the example and open the serial monitor to confirm that both the Wi-Fi and MQTT connections succeed before the publish loop begins:Published line appears every five seconds. If the Wi-Fi connection drops, anx_wifi_connect() automatically retries in the background — MQTT publishes resume once the link is restored.
Subscribing to Messages
To verify that your payloads are actually reaching the broker, subscribe to the same topic from your desktop using themosquitto_sub CLI client:
- Linux / macOS
- Windows
Install
mosquitto-clients via your package manager (apt install mosquitto-clients or brew install mosquitto), then run the mosquitto_sub command above. The --capath /etc/ssl/certs flag points to the system CA bundle, which is sufficient for public brokers such as HiveMQ Cloud.ANX OS bundles a current set of root CA certificates in the firmware image, so setting
"tls": true in config.json is all you need for TLS to work — there is no certificate provisioning step on the device side. The bundled CA store is updated with each ANX OS release; keep your firmware current to stay compatible with broker certificate renewals.