ble_beacon_mode.ino

PaperDIY Assembly Kit · File : ble_beacon_mode.ino · Language : C++ (Arduino) · Use case : Diffuser un signal Bluetooth Low Energy (BLE) en mode Beacon.

Passive BLE broadcasting to be detected by smartphones.

Install the standard ESP32 BLE library. Upload the code. Use an app like 'nRF Connect' on Android or iOS to scan for BLE devices. You should see 'PaperDIY' appear in the list of nearby devices.

ble_beacon_mode.ino

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEAdvertising.h>

BLEAdvertising *pAdvertising;

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE Beacon...");

  BLEDevice::init("PaperDIY-BLE");
  pAdvertising = BLEDevice::getAdvertising();
  
  // Configuration simple de diffusion
  BLEAdvertisementData oAdvertisementData = BLEAdvertisementData();
  oAdvertisementData.setName("PaperDIY");
  
  pAdvertising->setAdvertisementData(oAdvertisementData);
  pAdvertising->start();
  
  Serial.println("BLE Advertising started");
}

void loop() {
  // Le BLE fonctionne en arrière-plan
  delay(1000);
}

← Back to the board