Project Awesome project awesome

ESPHelper

MQTT and Wi-fi automation-oriented library for the 8266.

Package 330 stars GitHub

ESPHelper

ESPHelper is a C++ library designed to simplify WiFi and MQTT connectivity for ESP8266 and ESP32 platforms. It manages WiFi and MQTT connections, automatic reconnection, topic subscriptions, and supports OTA (Over-The-Air) updates, making it ideal for IoT and home automation projects.

Features

  • Automatic WiFi and MQTT Connection Management: Handles connecting, reconnecting, and resubscribing to MQTT topics.
  • MQTT Topic Subscription Management: Add, remove, and auto-resubscribe to topics.
  • OTA Updates: Easily enable/disable OTA, set OTA password and hostname.
  • Broadcast Mode: Create an access point for configuration or OTA when no WiFi is available.
  • Web Configuration: Optional web interface for device configuration (ESPHelperWebConfig).
  • Callback Support: Set custom callbacks for WiFi connection, WiFi loss, and MQTT messages.
  • Secure MQTT: Supports SSL/TLS connections to MQTT brokers.

Requirements

Make sure you have these libraries installed:

In addition to those libraries, make sure that you have the ESP core files installed for your platform.

Getting Started

See the examples/GettingStarted folder for usage examples.

Basic Usage

#include "ESPHelper.h"

ESPHelper helper;

void setup() {
    helper.setSSID("yourSSID");
    helper.setPASS("yourPassword");
    helper.setMQTTIP("mqtt.example.com");
    helper.begin();
}

void loop() {
    helper.loop();
}

Useful Methods:

  • bool begin(); Initialize the system (must be called once).

  • int loop(); must be called as often as possible to maintain connections and run the various subsystems

  • bool subscribe(char* topic); subscribe to a given MQTT topic (will NOT auto re-subscribe on connection lost)

  • bool addSubscription(char* topic); add a topic to the subscription list (will auto re-subscribe on connection lost)

  • bool removeSubscription(char* topic); remove a topic from the subscription list and unsubscribe

  • void publish(char* topic, char* payload); publish a given MQTT message to a given topic

ToDo

  • Implement callback for lost WiFi connection
Back to ESP