Skip to main content

MQTT

MQTT is the standard lightweight publish/subscribe protocol for machine-to-machine messaging. Endpoint uses the same MQTT client libraries that run on servers and desktops, so your application works against any broker, whether a local Mosquitto instance in the lab, hosted brokers like HiveMQ or EMQX, or the managed brokers inside Azure IoT Hub, AWS IoT Core, and Google Cloud Pub/Sub.

Client​

The .NET choice is MQTTnet: full QoS 0 / 1 / 2 support, TLS (using the operating system's certificate trust store), topic filters, and persistent sessions. On Python the standard library is paho-mqtt. On C/C++ use the Eclipse Mosquitto client library that Endpoint firmware already ships.

using MQTTnet;
using MQTTnet.Client;

var factory = new MqttFactory();
using var client = factory.CreateMqttClient();

var options = new MqttClientOptionsBuilder()
.WithTcpServer("broker.example.com", 8883)
.WithTls()
.WithCredentials("username", "password")
.WithClientId("endpoint-01")
.Build();

await client.ConnectAsync(options);
await client.SubscribeAsync("sensors/+/temperature");
await client.PublishStringAsync("sensors/01/temperature", "23.4");

Running an MQTT broker on the board​

Endpoint can host an MQTT broker, not just connect to one. On .NET the MQTTnet package also ships a broker component in the same assembly. On Linux, the Mosquitto broker daemon (mosquitto) is available over the package manager and can be launched from any language. A fleet of local devices can publish to Endpoint, which then forwards aggregated or filtered data upstream to the cloud. See the Endpoint as gateway page for the full pattern.