<alp/iot.h> — Wi-Fi & MQTT
Connectivity helpers for putting an E1M module on the network.
Header
#include <alp/iot.h>
Wi-Fi station
alp_wifi_t *wifi = alp_wifi_open(&(alp_wifi_config_t){
.mode = ALP_WIFI_MODE_STATION,
});
alp_wifi_connect(wifi, &(alp_wifi_credentials_t){
.ssid = "MyNetwork",
.password = "secret",
.security = ALP_WIFI_SECURITY_WPA2,
});
while (!alp_wifi_is_connected(wifi)) {
k_msleep(100);
}
alp_wifi_close(wifi);
On AEN this flows through the CC3501E coprocessor. On V2N it flows through the on-module Murata module. The application API is identical across silicon families.
MQTT
alp_mqtt_t *mqtt = alp_mqtt_open(&(alp_mqtt_config_t){
.broker_uri = "mqtt://broker.example.com:1883",
.client_id = "alp-device-001",
});
alp_mqtt_connect(mqtt);
alp_mqtt_publish(mqtt, "sensors/temperature", "23.5", 4, ALP_MQTT_QOS_0);
void on_message(const char *topic, const uint8_t *payload, size_t len, void *user) {
/* handle incoming message */
}
alp_mqtt_subscribe(mqtt, "actuators/+/cmd", ALP_MQTT_QOS_1, on_message, NULL);
// Drive the loop from your main thread, or spawn a worker
while (1) {
alp_mqtt_loop(mqtt, 100); // process pending events, 100 ms budget
}
alp_mqtt_close(mqtt);
TLS (mqtts://)
alp_mqtt_t *mqtt = alp_mqtt_open(&(alp_mqtt_config_t){
.broker_uri = "mqtts://broker.example.com:8883",
.client_id = "alp-device-001",
.tls = &(alp_mqtt_tls_config_t){
.ca_path = "/etc/ssl/certs",
.cert_path = "/etc/alp/device.crt",
.key_path = "/etc/alp/device.key",
},
});
The Yocto backend routes TLS through OpenSSL (mosquitto_tls_set); the Zephyr backend uses MbedTLS configured via <alp/security.h>.
:::warning mqtts:// now fails closed on a non-TLS build
v0.10 fixes a silent plaintext downgrade (GHSA-gqjv-932h-c5gm). The Zephyr MQTT backend, when CONFIG_MQTT_LIB_TLS was disabled, discarded the parsed TLS result and always selected a non-secure transport — transmitting an mqtts:// connection's credentials and payloads in plaintext while the app believed the scheme enforced TLS.
An mqtts:// broker URI on a build without CONFIG_MQTT_LIB_TLS is now rejected with ALP_ERR_NOSUPPORT before any connection is attempted. If you relied on the old behaviour, you were not getting TLS — enable CONFIG_MQTT_LIB_TLS or switch the scheme to mqtt:// deliberately.
:::
board.yaml
iot:
wifi: true
mqtt: true
tls: true
Default-initialiser macro
ALP_MQTT_CONFIG_DEFAULT(id) (v0.10) takes the broker URI as its identity argument:
alp_mqtt_config_t cfg = ALP_MQTT_CONFIG_DEFAULT("mqtt://broker.example.com:1883");
cfg.client_id = "e1m-node-1";
It sets broker_uri from id plus: client_id = NULL, username = NULL, password = NULL, keepalive_s = 60, clean_session = true, tls = NULL (no TLS).
See the shared macro contract for the C++ compound-literal caveat that applies to every ALP_*_CONFIG_DEFAULT.
See also
<alp/security.h>— TLS / PSA Crypto<alp/ble.h>— BLE 5.4- Examples: iot-connected-camera