MycilaMQTT
A simple and efficient MQTT/MQTTS client for Arduino / ESP32 based on Espressif API
- Automatic reconnect
- Automatic resubscribe
- Dead simple configuration which allows easier integration with a configuration system and quick reload (
end()
andbegin()
) of the client - automatic management of will topic
- Arduino 2 (ESP-IDF 4) Support
- Arduino 3 (ESP-IDF 5) Support
- SSL/TLS support (server certificates and CA bundles)
- Async mode (blocking mode or non-blocking mode when publishing)
- Does not support message fragmentation - reassembling: make sure to set buffer size accordingly (
MYCILA_MQTT_BUFFER_SIZE
) - Retain support
Usage
Mycila::MQTT::Config config;
config.server = "test.mosquitto.org";
config.port = 1884;
config.username = "rw";
config.password = "readwrite";
config.clientId = "my-app-1234";
config.willTopic = "foo/status";
mqtt.onConnect([]() {
Serial.println("MQTT connected");
});
mqtt.subscribe("my-app/value/set", [](const String& topic, const String& payload) {
Serial.printf("MQTT message received: %s -> %s\r\n", topic.c_str(), payload.c_str());
});
mqtt.begin(config);
mqtt.publish("my-app/value", "Hello World!");
SSL / TLS
Please see the examples to see how to use server certificates or CA certificate bundles.
Alternatives
PsychicMqttClient is also an MQTT library based on ESP-IDF written by @theelims that you might want to consider, which is more feature rich and has better support for CA bundles.