EasyManuals Logo

SunFounder ESP32 User Manual

Default Icon
771 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #147 background imageLoading...
Page #147 background image
SunFounder ESP32 Starter Kit
(continued from previous page)
if (pServer == nullptr) {
Serial.println("Error creating BLE server");
return;
}
pServer->setCallbacks(new MyServerCallbacks()); // Set the BLE server
˓callbacks
// Create the BLE service
BLEService *pService = pServer->createService(SERVICE_UUID);
// Print the error message if the BLE service creation fails
if (pService == nullptr) {
Serial.println("Error creating BLE service");
return;
}
// Create the BLE characteristic for sending notifications
pCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID_TX,
˓ BLECharacteristic::PROPERTY_NOTIFY);
pCharacteristic->addDecodeor(new BLE2902()); // Add the decodeor
// Create the BLE characteristic for receiving data
BLECharacteristic *pCharacteristicRX = pService->
˓createCharacteristic(CHARACTERISTIC_UUID_RX, BLECharacteristic::PROPERTY_
˓WRITE);
pCharacteristicRX->setCallbacks(new MyCharacteristicCallbacks()); //
˓Set the BLE characteristic callbacks
pService->start(); //
˓Start the BLE service
pServer->getAdvertising()->start(); //
˓Start advertising
Serial.println("Waiting for a client connection..."); //
˓Wait for a client connection
}
Please note that this code allows for bidirectional communication - it can send and receive data via BLE. However, to
interact with specific hardware like turning on/off an LED, additional code should be added to process the received
strings and act accordingly.
1.39 7.2 Bluetooth Control RGB LED
This project is an extension of a previous project(7.1 Bluetooth), adding RGB LED configurations and custom com-
mands such as “led_off”, “red”, “green”, etc. These commands allow the RGB LED to be controlled by sending
commands from a mobile device using LightBlue.
Required Components
In this project, we need the following components.
Its definitely convenient to buy a whole kit, heres the link:
Name ITEMS IN THIS KIT LINK
ESP32 Starter Kit 320+
1.39. 7.2 Bluetooth Control RGB LED 141

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the SunFounder ESP32 and is the answer not in the manual?

SunFounder ESP32 Specifications

General IconGeneral
BrandSunFounder
ModelESP32
CategoryController
LanguageEnglish