Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Tasmota | 19,432 | 7 hours ago | 14 | gpl-3.0 | C | |||||
Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at | ||||||||||
Wled | 11,238 | 17 hours ago | 4 | August 03, 2021 | 309 | mit | C++ | |||
Control WS2812B and many more types of digital RGB LEDs with an ESP8266 or ESP32 over WiFi! | ||||||||||
Nodemcu Firmware | 7,276 | 2 months ago | 99 | mit | C | |||||
Lua based interactive firmware for ESP8266, ESP8285 and ESP32 | ||||||||||
Platformio Core | 6,673 | 6 days ago | 16 | August 12, 2022 | 184 | apache-2.0 | Python | |||
A professional collaborative platform for embedded development :alien: | ||||||||||
Arduinojson | 6,077 | 4 days ago | 24 | mit | C++ | |||||
📟 JSON library for Arduino and embedded C++. Simple and efficient. | ||||||||||
Esphome | 6,015 | 1 | 1 | 11 hours ago | 200 | June 22, 2022 | 157 | other | C++ | |
ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems. | ||||||||||
Blynk Library | 3,597 | 5 days ago | 9 | mit | C++ | |||||
Blynk library for embedded hardware. Works with Arduino, ESP8266, Raspberry Pi, Intel Edison/Galileo, LinkIt ONE, Particle Core/Photon, Energia, ARM mbed, etc. | ||||||||||
Openmqttgateway | 2,954 | 9 hours ago | 97 | gpl-3.0 | C++ | |||||
MQTT gateway for ESP8266, ESP32, Sonoff RF Bridge or Arduino with bidirectional 433mhz/315mhz/868mhz, Infrared communications, BLE, Bluetooth, beacons detection, mi flora, mi jia, LYWSD02, LYWSD03MMC, Mi Scale, TPMS, BBQ thermometer compatibility, SMS & LORA. | ||||||||||
Tft_espi | 2,532 | 9 days ago | 6 | other | C | |||||
Arduino and PlatformIO IDE compatible TFT library optimised for the Raspberry Pi Pico (RP2040), STM32, ESP8266 and ESP32 that supports different driver chips | ||||||||||
Irremoteesp8266 | 2,376 | 12 days ago | 31 | lgpl-2.1 | C++ | |||||
Infrared remote library for ESP8266/ESP32: send and receive infrared signals with multiple protocols. Based on: https://github.com/shirriff/Arduino-IRremote/ |
This library is intended to encapsulate the handling of WiFi and MQTT connections of an ESP8266/ESP32. You just need to provide your credentials and it will manage the following things:
+
, #
) in subscriptionsThe MQTT communication depends on the PubSubClient Library.
#include "EspMQTTClient.h"
EspMQTTClient client(
"WifiSSID",
"WifiPassword",
"192.168.1.100", // MQTT Broker server ip
"MQTTUsername", // Can be omitted if not needed
"MQTTPassword", // Can be omitted if not needed
"TestClient" // Client name that uniquely identify your device
);
void setup() {}
void onConnectionEstablished() {
client.subscribe("mytopic/test", [] (const String &payload) {
Serial.println(payload);
});
client.publish("mytopic/test", "This is a message");
}
void loop() {
client.loop();
}
See SimpleMQTTClient.ino
for the complete example.
For Wifi and MQTT connection handling (Recommended):
EspMQTTClient(
const char* wifiSsid,
const char* wifiPassword,
const char* mqttServerIp,
const char* mqttUsername, // Omit this parameter to disable MQTT authentification
const char* mqttPassword, // Omit this parameter to disable MQTT authentification
const char* mqttClientName = "ESP8266",
const uint16_t mqttServerPort = 1883);
MQTT connection handling only:
EspMQTTClient(
const char* mqttServerIp,
const uint16_t mqttServerPort, // It is mandatory here to allow these constructors to be distinct from those with the Wifi handling parameters
const char* mqttUsername, // Omit this parameter to disable MQTT authentification
const char* mqttPassword, // Omit this parameter to disable MQTT authentification
const char* mqttClientName = "ESP8266");
IMPORTANT: Must be called at each loop() of your sketch
void loop();
Basic functions for MQTT communications.
bool publish(const String &topic, const String &payload, bool retain = false);
bool subscribe(const String &topic, MessageReceivedCallback messageReceivedCallback, uint8_t qos = 0);
bool unsubscribe(const String &topic);
Change the maximum packet size that can be sent over MQTT. The default is 128 bytes.
bool setMaxPacketSize(const uint16_t size);
Change the keep alive interval (15 seconds by default)
void setKeepAlive(uint16_t keepAliveSeconds);
Enable debugging messages that will output to serial.
void enableDebuggingMessages(const bool enabled = true);
Enable the web updater. This will host a simple form that will allow firmware upgrade (using, e.g., the .bin
file produced by "Export Compiled Binary" in the Arduino IDE's "Sketch" menu). Must be set before the first loop() call.
void enableHTTPWebUpdater(const char* username, const char* password, const char* address = "/");
// this one will set user and password equal to those set for the MQTT connection.
void enableHTTPWebUpdater(const char* address = "/");
Enable last will message. Must be set before the first loop() call.
void enableLastWillMessage(const char* topic, const char* message, const bool retain = false);
Tell the broker to establish a persistent connection. Disabled by default. Must be called before the first loop() execution
void enableMQTTPersistence();
Change the delay between each MQTT reconnection attempt. Default is 15 seconds.
void setMqttReconnectionAttemptDelay(const unsigned int milliseconds);
Change the delay between each Wifi reconnection attempt. Default is 60 seconds.
void setWifiReconnectionAttemptDelay(const unsigned int milliseconds);
Connection status
bool isConnected(); // Return true if everything is connected.
bool isWifiConnected(); // Return true if WiFi is connected.
bool isMqttConnected(); // Return true if MQTT is connected.
bool getConnectionEstablishedCount() // Return the number of time onConnectionEstablished has been called since the beginning.
As ESP8266 does not like to be interrupted too long with the delay()
function, this function will allow a delayed execution of a function without interrupting the sketch.
void executeDelayed(const long delay, DelayedExecutionCallback callback);
Some useful getters
const char* getMqttClientName();
const char* getMqttServerIp();
const uint16_t getMqttServerPort();
To allow this library to work, you need to implement the onConnectionEstablished()
function in your sketch.
void onConnectionEstablished()
{
// Here you are sure that everything is connected.
}
In some special cases, like if you want to handle more than one MQTT connection in the same sketch, you can override this callback to another one for the second MQTT client using this function:
void setOnConnectionEstablishedCallback(ConnectionEstablishedCallback callback);
See example twoMQTTClientHandling.ino
for more details.
The function subscribe
allows subscribing a specific topic.
For example, if you want to subscribe to topic test/mytopic
, you can do this:
void onTestMessageReceived(const String& message) {
Serial.print("message received from test/mytopic: " + message);
}
client.subscribe("test/mytopic", onTestMessageReceived);
You can also use lambdas to shorten the code like this:
client.subscribe("test/mytopic", [](const String& message) {
Serial.print("message received from test/mytopic: " + message;
});
This library also handle MQTT topic wildcards. Most of the time, you will want to see what was the original topic when the callback is called. Here is how to do that.
Example: Subscribe to wildcardtest/#
and display received topic and message to Serial
void onMessageReceived(const String& topic, const String& message) {
Serial.println(topic + ": " + message);
}
client.subscribe("wildcardtest/#", onMessageReceived);
The same thing with lambdas:
client.subscribe("wildcardtest/#", [](const String& topic, const String& message) {
Serial.println(topic + ": " + message);
});