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 BLE Service and Characteristic UUIDs
- #define SERVICE_UUID "12345678-1234-5678-1234-56789abcdef0"
- #define CHARACTERISTIC_UUID "12345678-1234-5678-1234-56789abcdef1"
- // Create a BLE Server and Characteristic
- BLEServer *pServer = nullptr;
- BLECharacteristic *pCharacteristic = nullptr;
- void setup() {
- Serial.begin(115200);
- BLEDevice::init("ESP32_BLE_Server"); // Initialize BLE with a name
- // Create the BLE Server
- pServer = BLEDevice::createServer();
- // Create the BLE Service
- BLEService *pService = pServer->createService(SERVICE_UUID);
- // Create the BLE Characteristic
- pCharacteristic = pService->createCharacteristic(
- CHARACTERISTIC_UUID,
- BLECharacteristic::PROPERTY_READ
- );
- // Set the initial value of the characteristic
- pCharacteristic->setValue("Hello from ESP32");
- // Start the service
- pService->start();
- // Start advertising
- BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
- pAdvertising->addServiceUUID(SERVICE_UUID);
- pAdvertising->start();
- Serial.println("BLE Server is running, waiting for clients to connect...");
- }
- void loop() {
- // Nothing to do here
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement