Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <BLEDevice.h>
- #include <BLEUtils.h>
- #include <BLEServer.h>
- // Define the UUID for the beacon
- #define BEACON_UUID "12345678-1234-5678-1234-56789abcdef0"
- void setup() {
- Serial.begin(115200);
- BLEDevice::init(""); // Initialize BLE with an empty name
- // Create the BLE Server
- BLEServer *pServer = BLEDevice::createServer();
- // Create the BLE Service (we use a custom UUID here)
- BLEService *pService = pServer->createService(BEACON_UUID);
- // Create a BLE Characteristic
- BLECharacteristic *pCharacteristic = pService->createCharacteristic(
- BLEUUID("12345678-1234-5678-1234-56789abcdef1"),
- BLECharacteristic::PROPERTY_READ
- );
- // Set the value of the characteristic (this will be broadcasted)
- pCharacteristic->setValue("ESP32 Beacon");
- // Start the service
- pService->start();
- // Create the BLE Advertising object
- BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
- pAdvertising->addServiceUUID(BEACON_UUID);
- pAdvertising->setScanResponse(true);
- // Set advertising parameters
- pAdvertising->setMinPreferred(0x06); // Function to change advertising interval
- pAdvertising->setMaxPreferred(0x12); // Function to change advertising interval
- // Start advertising
- pAdvertising->start();
- Serial.println("BLE Beacon is now advertising...");
- }
- void loop() {
- // Nothing to do here
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement