All Projects → shmuelzon → Esp32 Ble2mqtt

shmuelzon / Esp32 Ble2mqtt

Licence: mit
A BLE to MQTT bridge running on an ESP32

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Esp32 Ble2mqtt

Blinker Library
An IoT Solution,Blinker library for embedded hardware. Works with Arduino, ESP8266, ESP32.
Stars: ✭ 1,095 (+263.79%)
Mutual labels:  esp32, ble, mqtt
Nimble Arduino
A fork of the NimBLE library structured for compilation with Ardruino, designed for use with ESP32.
Stars: ✭ 108 (-64.12%)
Mutual labels:  esp32, ble, bluetooth
Open Home Automation
Open Home Automation with Home Assistant, ESP8266/ESP32 and MQTT
Stars: ✭ 820 (+172.43%)
Mutual labels:  esp32, ble, mqtt
Esp32 Ble Keyboard
Bluetooth LE Keyboard library for the ESP32 (Arduino IDE compatible)
Stars: ✭ 533 (+77.08%)
Mutual labels:  esp32, ble, bluetooth
Esp32 Ble Mouse
Bluetooth LE Mouse library for the ESP32 (Arduino IDE compatible)
Stars: ✭ 180 (-40.2%)
Mutual labels:  esp32, ble, bluetooth
Pedalinomini
Same features of Pedalino™ in a compact form.
Stars: ✭ 139 (-53.82%)
Mutual labels:  esp32, ble, bluetooth
ruuvitag-demo
Demo of reading Bluetooth Low Energy sensor measurements of RuuviTag environmental sensors and feeding them to MQTT, a database and dashboards
Stars: ✭ 14 (-95.35%)
Mutual labels:  mqtt, bluetooth, ble
ESP32BleAdvertise
Simple library for BLE advertise using ESP32 in Arduino
Stars: ✭ 39 (-87.04%)
Mutual labels:  esp32, bluetooth, ble
Esp32 Blecollector
ᛡᛒ BLE Scanner + Data persistence on SD Card for M5Stack, Odroid-Go, ESP32-Wrover-Kit and other models
Stars: ✭ 145 (-51.83%)
Mutual labels:  esp32, ble, bluetooth
Blinker Doc
blinker中文文档
Stars: ✭ 139 (-53.82%)
Mutual labels:  esp32, ble, mqtt
Openmqttgateway
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.
Stars: ✭ 2,413 (+701.66%)
Mutual labels:  esp32, ble, mqtt
arduino-ble-gadget
Create your own Do-It-Yourself BLE enabled sensor gadget on the ESP32 platform.
Stars: ✭ 31 (-89.7%)
Mutual labels:  esp32, bluetooth, ble
soma-ctrl
Node util for controlling SOMA smart shade via MQTT or HTTP
Stars: ✭ 19 (-93.69%)
Mutual labels:  mqtt, bluetooth
BulletGCSS
A High Caliber Ground Control Station System designed for the 21st century lifestyle
Stars: ✭ 29 (-90.37%)
Mutual labels:  mqtt, esp32
Easybluetooth
一款iOS BLE蓝牙调试工具,非常简单容易,也可以作为一个蓝牙库,快速集成和开发。 可以两步搞定蓝牙开发操作。 第一步连接设备,第二步特征读写数据。
Stars: ✭ 282 (-6.31%)
Mutual labels:  ble, bluetooth
ble-utilities-unreal
This is Unreal Engine plugin that allows to scan for BLE devices with Cycling Power service running, connect to one of them and subscribe for its notifications.
Stars: ✭ 48 (-84.05%)
Mutual labels:  bluetooth, ble
Arduino-BLE-MIDI
MIDI over Bluetooth Low Energy (BLE-MIDI) 1.0 for Arduino
Stars: ✭ 133 (-55.81%)
Mutual labels:  esp32, ble
android-ble-made-easy
An Android Library for handling Bluetooth Low Energy on Android Easy
Stars: ✭ 34 (-88.7%)
Mutual labels:  bluetooth, ble
ESP32 BLE OTA Arduino
OTA update on ESP32 via BLE
Stars: ✭ 41 (-86.38%)
Mutual labels:  esp32, ble
SnorkTracker
GPS IoT tracker board for scanning gps and environment information and sending this to a MQTT server via GPRS.
Stars: ✭ 38 (-87.38%)
Mutual labels:  mqtt, esp32

ESP32-BLE2MQTT

This project is a BLE to MQTT bridge, i.e. it exposes BLE GATT characteristics as MQTT topics for bidirectional communication. It's developed for the ESP32 SoC and is based on ESP-IDF release v4.1. Note that using any other ESP-IDF version might not be stable or even compile.

For example, if a device with a MAC address of a0:e6:f8:50:72:53 exposes the 0000180f-0000-1000-8000-00805f9b34fb service (Battery Service) which includes the 00002a19-0000-1000-8000-00805f9b34fb characteristic (Battery Level), the a0:e6:f8:50:72:53/BatteryService/BatteryLevel MQTT topic is published with a value representing the battery level.

Characteristics supporting notifications will automatically be registered on and new values will be published once available. It's also possible to proactively issue a read request by publishing any value to the topic using the above format suffixed with '/Get'. Note that values are strings representing the characteristic values based on their definitions grabbed from http://bluetooth.org. For example, a battery level of 100% (0x64) will be sent as a string '100'.

In order to set a GATT value, publish a message to a writable characteristic using the above format suffixed with /Set. Payload should be of the same format described above and will be converted, when needed, before sending to the BLE peripheral.

In addition to the characteristic values, the BLE2MQTT devices also publish additional topics to help book-keeping:

  • <Peripheral MAC address>/Connected - With a payload of true/false depicting if the peripheral is currently connected or not. Note that this topic is monitored by the BLE2MQTT instance currently connected to the peripheral so that if another instance publishes false, the current instance will re-publish true
  • <Peripheral MAC address>/Owner - The name of the BLE2MQTT instance currently connected to the peripheral, e.g. BLE2MQTT-XXXX, where XXXX are the last 2 octets of the ESP32's WiFi MAC address
  • BLE2MQTT-XXX/Version - The BLE2MQTT application version currently running
  • BLE2MQTT-XXX/ConfigVersion - The BLE2MQTT configuration version currently loaded (MD5 hash of configuration file)
  • BLE2MQTT-XXX/Uptime - The uptime of the ESP32, in seconds, published every minute

Broadcasters

Broadcasters are non-connectable BLE devices that only send advertisements. This application supports publishing these advertisements over MQTT. For each broadcaster, at-least two topics are published:

  • BLE2MQTT-XXXX/<Broadcaster MAC address>/Type - The broadcaster type, e.g. iBeacon
  • BLE2MQTT-XXXX/<Broadcaster MAC address>/RSSI - The RSSI value of the received advertisement

In addition, depending on the broadcaster type and payload, additional meta-data is published.

  • For iBeacon: UUID, Major, Minor and Distance
  • For Eddystone:
    • UID frames: Namespace, Instance and Distance
    • URL frames: URL and Distance
    • TLM frames: Voltage, Temperature, Count and Uptime
  • For MiJia temperature and humidity sensors: MACAddress, MessageCounter, Temperature, Humidity and BatteryLevel
  • For BeeWi Smart Door sensors: Status and Battery
  • For Xiomi LYWSD03MMC Temperature Sensors running the ATC1441 firmware: MACAddress, MessageCounter, Temperature, Humidity, BatteryLevel and BatteryVolts (See https://github.com/atc1441/ATC_MiThermometer)

Note: Broadcaster topics are published without the retained flag regardless of what's defined in the configuration file.

Compiling

Download the repository and its dependencies:

git clone --recursive https://github.com/shmuelzon/esp32-ble2mqtt

Modify the configuration file to fit your environment, build and flash (make sure to modify the serial device your ESP32 is connected to):

idf.py flash -p /dev/ttyS1

Remote Logging

If configured, the application can send the logs remotely via UDP to another host to allow receiving logs from remote devices without a serial connection. To receive these logs on your host, execute idf.py remote-monitor.

Configuration

The configuration file provided in located at data/config.json in the repository. It contains all of the different configuration options.

The wifi section below includes the following entries:

{
  "wifi": {
    "ssid": "MY_SSID",
    "password": "MY_PASSWORD",
    "eap": {
      "method": null,
      "identity": null,
      "client_cert": null,
      "client_key": null,
      "server_cert": null,
      "username": null,
      "password": null
    }
  }
}
  • ssid - The WiFi SSID the ESP32 should connect to
  • password - The security password for the above network
  • eap - WPA-Enterprise configuration (for enterprise networks only)
    • method - TLS, PEAP or TTLS
    • identity - The EAP identity
    • ca_cert, client_cert, client_key - Full path names, including a leading slash (/), of the certificate/key file (in PEM format) stored under the data folder
    • username, password - EAP login credentials

The eth section below includes the following entries:

{
  "eth": {
    "phy": "MY_ETH_PHY",
    "phy_power_pin": -1
  }
}
  • phy - The PHY chip connected to ESP32 RMII, one of:
    • IP101
    • RTL8201
    • LAN8720
    • DP83848
  • phy_power_pin - Some ESP32 Ethernet modules such as the Olimex ESP32-POE require a GPIO pin to be set high in order to enable the PHY. Omitting this configuration or setting it to -1 will disable this.

Note: Defining the eth section will disable WiFi

The mqtt section below includes the following entries:

{
  "mqtt": {
    "server": {
      "host": "192.168.1.1",
      "port": 1883,
      "ssl": false,
      "client_cert": null,
      "client_key": null,
      "server_cert": null,
      "username": null,
      "password": null,
      "client_id": null
    },
    "publish": {
      "qos": 0,
      "retain": true
    },
    "topics" :{
      "prefix": "",
      "get_suffix": "/Get",
      "set_suffix": "/Set"
    }
  }
}
  • server - MQTT connection parameters
    • host - Host name or IP address of the MQTT broker
    • port - TCP port of the MQTT broker. If not specificed will default to 1883 or 8883, depending on SSL configuration
    • client_cert, client_key, server_cert - Full path names, including a leading slash (/), of the certificate/key file (in PEM format) stored under the data folder. For example, if a certificate file is placed at data/certs/my_cert.pem, the value stored in the configuration should be /certs/my_cert.pem
    • username, password - MQTT login credentials
    • client_id - The MQTT client ID
  • publish - Configuration for publishing topics
  • topics
    • prefix - Which prefix should be added to all MQTT value topics. OTA related topics are already prefixed and are not affected by this value
    • get_suffix - Which suffix should be added to the MQTT value topic in order to issue a read request from the characteristic
    • set_suffix - Which suffix should be added to the MQTT value topic in order to write a new value to the characteristic

The ble section of the configuration file includes the following default configuration:

{
  "ble": {
    "//Optional: 'whitelist' or 'blacklist'": [],
    "services": {
      "definitions": {},
      "//Optional: 'whitelist' or 'blacklist'": []
    },
    "characteristics": {
      "definitions": {},
      "//Optional: 'whitelist' or 'blacklist'": []
    },
    "passkeys": {}
  }
}
  • whitelist/blacklist - An array of MAC addresses of devices. If whitelist is used, only devices with a MAC address matching one of the entries will be connected while if blacklist is used, only devices that do not match any entry will be connected. It's possible to use the wildcard character ? to denote any value for a nibble.

    "whitelist": [
      "aa:bb:cc:dd:ee:ff",
      "00:11:22:??:??:??"
    ]
    
  • services - Add additional services or override a existing definitions to the ones grabbed automatically during build from http://www.bluetooth.org. Each service can include a name field which will be used in the MQTT topic instead of its UUID. In addition, it's possible to define a white/black list for discovered services. The white/black list UUIDs may contain the wildcard character ? to denote any value for a nibble. For example:

    "services": {
      "definitions": {
        "00002f00-0000-1000-8000-00805f9b34fb": {
          "name": "Relay Service"
        }
      },
      "blacklist": [
        "0000180a-0000-1000-8000-00805f9b34fb",
        "0000ffff-????-????-????-????????????"
      ]
    }
    
  • characteristics - Add additional characteristics or override existing definitions to the ones grabbed automatically during build from http://www.bluetooth.org. Each characteristic can include a name field which will be used in the MQTT topic instead of its UUID and a types array defining how to parse the byte array reflecting the characteristic's value. In addition, it's possible to define a white/black list for discovered characteristics. The white/black list UUIDs may contain the wildcard character ? to denote any value for a nibble. For example:

    "characteristics": {
      "definitions": {
        "00002f01-0000-1000-8000-00805f9b34fb": {
          "name": "Relay State",
          "types": [
            "boolean"
          ]
        }
      },
      "blacklist": [
        "00002a29-0000-1000-8000-00805f9b34fb",
        "0000ffff-????-????-????-????????????"
      ]
    }
    
  • passkeys - An object containing the passkey (number 000000~999999) that should be used for out-of-band authorization. Each entry is the MAC address of the BLE device and the value is the passkey to use. It's possible to use the wildcard character ? to denote any value for a nibble.

    "passkeys": {
      "aa:bb:cc:dd:ee:ff": 0,
      "00:11:22:??:??:??": 123456
    }
    

The optional log section below includes the following entries:

{
  "log": {
    "host": "224.0.0.200",
    "port": 5000
  }
}
  • host - The hostname or IP address to send the logs to. In case of an IP address, this may be a unicast, broadcast or multicast address
  • port - The destination UDP port

OTA

It is possible to upgrade both firmware and configuration file over-the-air once an initial version was flashed via serial interface. To do so, execute: idf.py upload or idf.py upload-config accordingly. The above will upgrade all BLE2MQTT devices connected to the MQTT broker defined in the configuration file. It is also possible to upgrade a specific device by adding the OTA_TARGET variable to the above command set to the host name of the requested device, e.g.:

OTA_TARGET=BLE2MQTT-470C idf.py upload

Note: In order to avoid unneeded upgrades, there is a mechanism in place to compare the new version with the one that resides on the flash. For the firmware image it's based on the git tag and for the configuration file it's an MD5 hash of its contents. In order to force an upgrade regardless of the currently installed version, run idf.py force-upload or idf.py force-upload-config respectively.

Board Compatibility

The sdkconfig.defaults included in this project covers common configurations.

Olimex ESP32-POE

A number of minor changes are required to support this board:

  • Set the eth section as follows:
    {
      "eth": {
        "phy": "LAN8720",
        "phy_power_pin": 12
      }
    }
    
  • Run idf.py menuconfig and modify the Ethernet configuration to:
    • RMII_CLK_OUTPUT=y
    • RMII_CLK_OUT_GPIO=17
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].