ESP32 - AirTag Documentation
|
ESP32 BLE Server with IMU integration and buzzer control. More...
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include "IMU.h"
#include "IMU_STRUCT.h"
#include "IMU_REGISTER_MAP.h"
#include <Wire.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
Classes | |
class | ServerCallbacks |
Handles BLE server connect/disconnect events. More... | |
class | ButtonCallbacks |
Handles write events to the Button characteristic. More... |
Macros | |
#define | BUZZER_PIN 2 |
GPIO pin for buzzer output. | |
#define | SERVICE_UUID "275dc6e0-dff5-4b56-9af0-584a5768a02a" |
BLE Service UUID. | |
#define | BUTTON_CHAR_UUID "b51bd845-2910-4f84-b062-d297ed286b1f" |
Button characteristic UUID. | |
#define | IMU_CHAR_UUID "0679c389-0d92-4604-aac4-664c43a51934" |
IMU characteristic UUID. |
Functions | |
void | IMUTask (void *pvParameters) |
Task that reads IMU data, processes orientation, and detects movement. | |
void | ButtonRelayTask (void *pvParameters) |
Task that relays button press signals from BLE writes. | |
void | BuzzerSetTask (void *pvParameters) |
Task that toggles buzzer on/off when button events occur. | |
void | setup () |
Arduino setup function. Initializes Serial, I2C, BLE, creates GATT server and tasks. | |
void | loop () |
Arduino loop function (unused, tasks handle logic). |
Variables | |
BLECharacteristic * | buttonChar |
Pointer to Button characteristic. | |
BLECharacteristic * | imuChar |
Pointer to IMU characteristic. | |
BLEServer * | server |
Pointer to BLE server object. | |
volatile bool | deviceConnected = false |
Flag indicating central connection status. | |
volatile bool | bleMessageReceived = false |
Flag indicating BLE message received. | |
SemaphoreHandle_t | xButtonSignalSemaphore |
Semaphore used to signal button events between tasks. |
ESP32 BLE Server with IMU integration and buzzer control.
Implements a BLE GATT server with two characteristics:
The system uses FreeRTOS tasks:
Includes orientation computation, linear acceleration processing, and movement detection with a smoothing filter.
#define BUTTON_CHAR_UUID "b51bd845-2910-4f84-b062-d297ed286b1f" |
Button characteristic UUID.
#define BUZZER_PIN 2 |
GPIO pin for buzzer output.
< Initializes BLE general functionality < Provides BLE server (peripheral role) functionality < BLE helper utilities such as UUID handling < Descriptor class for Client Characteristic Configuration Descriptor (CCCD) < Custom IMU driver < IMU data structure definition < IMU register map < I2C communication library
#define IMU_CHAR_UUID "0679c389-0d92-4604-aac4-664c43a51934" |
IMU characteristic UUID.
#define SERVICE_UUID "275dc6e0-dff5-4b56-9af0-584a5768a02a" |
BLE Service UUID.
void ButtonRelayTask | ( | void * | pvParameters | ) |
Task that relays button press signals from BLE writes.
pvParameters | FreeRTOS task parameter (unused). |
void BuzzerSetTask | ( | void * | pvParameters | ) |
Task that toggles buzzer on/off when button events occur.
pvParameters | FreeRTOS task parameter (unused). |
< Turn buzzer on
< Turn buzzer off
void IMUTask | ( | void * | pvParameters | ) |
Task that reads IMU data, processes orientation, and detects movement.
pvParameters | FreeRTOS task parameter (unused). |
void loop | ( | ) |
Arduino loop function (unused, tasks handle logic).
void setup | ( | ) |
Arduino setup function. Initializes Serial, I2C, BLE, creates GATT server and tasks.
< Configure buzzer PWM
< Increase MTU size for better throughput
volatile bool bleMessageReceived = false |
Flag indicating BLE message received.
BLECharacteristic* buttonChar |
Pointer to Button characteristic.
volatile bool deviceConnected = false |
Flag indicating central connection status.
BLECharacteristic* imuChar |
Pointer to IMU characteristic.
BLEServer* server |
Pointer to BLE server object.
SemaphoreHandle_t xButtonSignalSemaphore |
Semaphore used to signal button events between tasks.