ESP32 BLE Beacon

Introduction

This is an example of a BLE Beacon type environmental sensor application using ESP32. By adding sensor data to the Attribute of the GATT Server, it can act as a beacon that broadcasts the data. When a connection request is received from the outside, the GATT Server will communicate with the server client and exchange log data with the Characteristic.

The loss of data due to packet reception failure that occurs in the Beacon type is prevented by leaving the sensor data in the non-volatile memory in the ESP32. Users can connect and read log data at any time, and the system will immediately switch to Beacon mode after data transfer is completed, greatly reducing power consumption.

Sample app’s source code

The source code for the sketches and tools used can be viewed in the repository below.

Sample-Sketches/ESP32_BLE_Beacon at master · Leafony/Sample-Sketches

What to prepare

  • Leafony ESP32 Wi-Fi Kit
  • Leafony Basic Kit
  • Raspberry Pi
  • Android Smartphone
  • USB micro cable

Leaf to use

Type Name Q’ty
AP02 ESP32 MCU 1
AI01 4-Sensors 1
M2 screw 2

Action Method

This section describes the steps to run the sample project. If you want to understand how each source code works, please refer to Mechanism described below.

1. Writing a sketch to an ESP32 leaf

Connect the ESP32 leaf to the PC via USB and write the ino file using the Arduino IDE.

The sample code uses the ESP32 Logging Library. The sample code uses the ESP32 Logging Library.
By setting the ToolsCode Debug Level in the Arduino IDE to the desired level, debug messages will be displayed on the serial monitor.

2. Run the beacon scanner app.

For scanning Advertising packets, use an app that runs on Node.js.
Any environment can be used as long as it runs Node.js, but this time we will assume that it will be a Beacon receiver set up at a fixed point outdoors, and we will explain how to run the application using a Raspberry Pi 4. In this article, we will explain how to run the application using a Raspberry Pi 4.

Install the necessary packages and run the application.

cd ./tools/node-scanner
npm install
npm start

3. Run the logging application.

A web application is used to retrieve log data and display graphs.

ESP32 Sensors Logger

Structure

How BLE Beacon works

GATT

Advertising

Characteristic

Back to previous page


Last modified 15.03.2021