Integration notes
Use the steps below as a general guide for binding NanoMQTT to either clear-text TCP or TLS, run it inside a single non-blocking event loop, and verify the setup with a quick two-phase test.
Switch transports in one line
/* TLS (port 8883, NanoSSL already negotiated) */ MQTT_setTransportSSL(conn, ssl); /* Plain TCP (port 1883) */ MQTT_setTransportTCP(conn, socketFd);
Note
Call one of the above before MQTT_negotiateConnection()
. The rest of the API is identical.
Single event loop
for (;;) { fd_set rfds, wfds; FD_ZERO(&rfds); FD_ZERO(&wfds); int fd = MQTT_getTransportFd(conn); /* same fd as SSL when bound */ FD_SET(fd, &rfds); if (MQTT_hasPendingTx(conn)) FD_SET(fd, &wfds); int maxfd = fd; select(maxfd + 1, &rfds, &wfds, NULL, NULL); if (FD_ISSET(fd, &rfds) || FD_ISSET(fd, &wfds)) MQTT_recv(conn); /* read + flush */ }
Open the socket with O_NONBLOCK
. The loop works for both TCP and TLS.
Build note
The socket helpers are always available. Enable the asynchronous wrapper only if you need it:
# static or CMake: add the macro -D__ENABLE_MQTT_ASYNC_CLIENT__ # helper script ./build_mqtt_client.sh --async
Quick validation
Pass 1 - TCP Bind with
MQTT_setTransportTCP
; connect to port 1883 and publish a test message.Pass 2 - TLS Switch to
MQTT_setTransportSSL
, port 8883, and supply--ssl_ca_file <bundle>
. The payload and topic should be identical.
A match between the two passes confirms both the NanoSSL handshake and the MQTT control flow.