ESP32-BLE2MQTT: Kickstart Your Embedded System’s IoT Journey

In IoT applications, Bluetooth Low Energy (BLE) and the MQTT protocol play crucial roles. BLE allows devices to communicate wirelessly with low power consumption, while MQTT provides a lightweight publish/subscribe messaging protocol for communication between devices. The ESP32-BLE2MQTT project cleverly combines these two protocols, creating a powerful BLE to MQTT bridge that offers developers a simple and efficient way to publish BLE data to MQTT topics and control BLE devices through MQTT topics.

ESP32-BLE2MQTT: Kickstart Your Embedded System's IoT Journey

Overview of ESP32-BLE2MQTT Features

The ESP32-BLE2MQTT project is a BLE to MQTT bridge based on the ESP32 SoC, with its core functionality being the exposure of BLE GATT characteristics as MQTT topics, enabling bidirectional communication. Specifically, the main features of the project include:

1. Mapping BLE Characteristics to MQTT Topics

Mapping the GATT characteristics of BLE devices to MQTT topics, for example, for a device with a MAC address of a0:e6:f8:50:72:53, its Battery Level characteristic in the Battery Service will map to a0:e6:f8:50:72:53/BatteryService/BatteryLevel MQTT topic.

2. Bidirectional Communication

Supports reading characteristic values from BLE devices and publishing them to MQTT topics, as well as publishing messages via MQTT topics to set characteristic values of BLE devices.

3. Notification Support

When the characteristic values of BLE devices change, ESP32-BLE2MQTT will automatically publish the new values to the corresponding MQTT topics.

4. Read Requests

Read requests can be actively initiated to BLE devices by publishing messages to the corresponding topic (ending with /Get).

5. State and Configuration Information Publishing

In addition to characteristic values, ESP32-BLE2MQTT also publishes other topics to record device state and configuration information, such as:

  • <Peripheral MAC address>/Connected: Indicates whether the BLE device is connected.

  • <Peripheral MAC address>/Owner: Records the name of the ESP32-BLE2MQTT instance currently connected to the BLE device.

  • BLE2MQTT-XXX/Version: Records the version of the ESP32-BLE2MQTT application.

  • BLE2MQTT-XXX/ConfigVersion: Records the MD5 hash value of the ESP32-BLE2MQTT configuration file.

  • BLE2MQTT-XXX/Uptime: Records the uptime of ESP32.

  • BLE2MQTT-XXX/Status: Records the operational status of ESP32-BLE2MQTT.

6. Support for Beacons

ESP32-BLE2MQTT supports publishing advertisement data from non-connected BLE devices (beacons). For example, for iBeacon, ESP32-BLE2MQTT will publish BLE2MQTT-XXXX/<Broadcaster MAC address>/Type, BLE2MQTT-XXXX/<Broadcaster MAC address>/RSSI and other topics, along with metadata containing UUID, Major, Minor, and Distance.

Configuration of ESP32-BLE2MQTT Project

The ESP32-BLE2MQTT project uses a configuration file named config.json, which contains various configuration options, such as network connection, MQTT server configuration, and BLE device configuration.

1. Network Configuration

The configuration file supports both WiFi and Ethernet connection methods, allowing you to choose one based on your needs.

2. MQTT Server Configuration

The configuration file allows setting the address, port number, username, password, and SSL configuration of the MQTT server.

3. BLE Device Configuration

The configuration file supports setting whitelist/blacklist MAC addresses and customizing BLE services and characteristics.

4. Logging Configuration

The configuration file supports setting up to send log information to a remote host.

Compiling and Using the ESP32-BLE2MQTT Project

1. Install ESP-IDF

You must first install the Espressif IoT Development Framework, which provides a complete toolchain for developing ESP32 devices.

2. Clone the Repository and Download Dependencies

Clone the ESP32-BLE2MQTT repository from GitHub and download the dependencies.

3. Modify the Configuration File

Modify the config.json configuration file to suit your environment.

4. Compile and Flash

Use the ESP-IDF toolchain to compile the project and flash the compiled firmware to the ESP32 device.

5. Remote Logging

If the remote logging feature is enabled in the configuration file, you can use the idf.py remote-monitor command to receive log information from the ESP32 device.

6. Firmware and Configuration File Updates

You can use idf.py upload and idf.py upload-config commands to update the firmware and configuration file of the ESP32 device, respectively.

7. Supported Boards

The ESP32-BLE2MQTT project supports various ESP32 development boards.

Conclusion

The ESP32-BLE2MQTT project provides developers with a powerful, easy-to-use, and flexible BLE to MQTT bridge. It simplifies communication between BLE devices and MQTT servers, greatly facilitating IoT application development. This project helps developers easily collect and control BLE data and integrate it into various IoT application scenarios.

Project Address:https://github.com/shmuelzon/esp32-ble2mqtt

Leave a Comment

×