Skip to content

blizniukp/esp32_ble2mqtt

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


esp32_ble2mqtt

Bluetooth to MQTT gateway based on ESP32-WROOM-32

Report Bug · Request Feature

Read this in other language: English, Polski.

Table of Contents
  1. About The Project
  2. Hardware
  3. Uploading firmware to ESP32
  4. Device configuration
  5. Mqtt communication
  6. Roadmap
  7. License

About The Project

A simple gateway that allows you to communicate with up to 4 Bluetooth devices at the same time.

It is used together with the plug-in for HomeAssistant ha_addon_ble2mqtt.

This plug-in also allows you to configure the gateway.

The application is based on the project: gattc_multi_connect

Currently device supports up to 4 bluetooth connections simultaneously. To increase it's number, edit variable CONFIG_BT_ACL_CONNECTIONS (BT/BLE MAX ACL CONNECTIONS parameter in menuconfig).

Values greater than 4 have not been tested yet!

(back to top)

Hardware

The ESP32-WROOM-32 module was used in this project.

In addition, you can use a button and a 10KOHM resistor to reset the configuration.

To do this, connect the button and the resistor between the 3V3 and PIN D4 terminals.

The built-in LED turns on when Bluetooth data is received, and turns off when an MQTT message is sent. It also lights up every 30 seconds to indicate that the device is working.

(powrót do góry)

Uploading firmware to ESP32

The firmware can be uploaded using the application Esp Download Tool

The latest firmware version is available in Releases

We should have three files in the firmware package:

  • bootloader.bin
  • partitions.bin
  • firmware.bin

You should extract them to some directory on your disk.

After running the ESP32 DOWNLOAD TOOL application, indicate these files and complete the fields as in the screenshot below.

esp32_download_tool

Press the Start button to start uploading the firmware to the device.

(powrót do góry)

Device configuration

When the device is first started (or after a configuration reset), WiFi hotspot is created with the following name and password:

SSID: ble2mqtt

Password: 12345678

Once connected to the network, go to the configuration web page.

On the Linux system, just go to the page: http://ble2mqtt.local

On Windows/Android use the address: http://192.168.4.1

ble2mqtt_webpage

On the above page, complete the fields for WiFi configuration and Mqtt broker.

When all fields are completed, click on the Save button. The entered data will be saved to the non-volatile memory of the ESP32 module.

After writing, restart the device. If no error occurs, the device should connect to the WiFi network and then to the MQTT broker.

Configuration can be restarted. Then WiFi hotspot starts again and will be able to enter the configuration page.

This is done by starting the device with connected D4 pin with 3.3V supply through 10kOhm resistor. After starting the device, open the above-mentioned connection.

(powrót do góry)

Mqtt communication

Device subscribes to topic: /ble2mqtt/dev/#.

After connecting to the MQTT broker, the device publishes the following message and waits for a response.

topic: /ble2mqtt/app/getDevList

payload: {}

Below is an example of a response containing a list of two Bluetooth devices:

topic: /ble2mqtt/dev/devList

payload:

[
   {
      "name":"ROUND_PAD_1",
      "address":"DA:D5:10:DC:D0:3A",
      "address_type":"random",
      "service_uuid":"71F1BB00-1C43-5BAC-B24B-FDABEEC53913",
      "char_uuid":"71F1BB01-1C43-5BAC-B24B-FDABEEC53913"
   },
   {
      "name":"ROUND_PAD_2",
      "address":"DF:E2:FB:80:50:3E",
      "address_type":"random",
      "service_uuid":"71F1BB00-1C43-5BAC-B24B-FDABEEC53913",
      "char_uuid":"71F1BB01-1C43-5BAC-B24B-FDABEEC53913"
   }
]

When data is received over Bluetooth, it is published to the topic /ble2mqtt/app/value

The payload contains, among other things, the MAC address of the device and the value read.

Payload example:

{
    "address": "DA:D5:10:DC:D0:3A", 
    "is_notify": true, 
    "val_len": 8, 
    "val": "0101000000000000"
}

Roadmap

  • Adding a LED to indicate device status
  • Using TLS when communicating with the MQTT broker
  • Transferring data to Bluetooth devices

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

About

A BLE to MQTT bridge running on an ESP32

Resources

License

Stars

Watchers

Forks

Packages

No packages published