EasyManuals Logo

Freenove ESP32-S3 User Manual

Default Icon
142 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 #54 background imageLoading...
Page #54 background image
Any concerns? support@freenove.com
Chapter 3 Bluetooth
52
www.freenove.com
Write a Callback function for BLE server to manage connection of BLE.
17
18
19
20
21
22
23
24
class MyServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
};
void onDisconnect(BLEServer* pServer) {
deviceConnected = false;
}
};
Write Callback function with BLE features. When it is called, as the mobile terminal send data to ESP32-S3, it
will store them into reload.
26
27
28
29
30
31
32
33
34
35
36
class MyCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string rxValue = pCharacteristic->getValue();
if (rxValue.length() > 0) {
rxload="";
for (int i = 0; i < rxValue.length(); i++){
rxload +=(char)rxValue[i];
}
}
}
};
Initialize the BLE function and name it.
55
setupBLE("ESP32S3_Bluetooth");
When the mobile phone send data to ESP32-S3 via BLE Bluetooth, it will print them out with serial port;
When the serial port of ESP32-S3 receive data, it will send them to mobile via BLE Bluetooth.
59
60
61
62
63
64
65
66
67
68
69
70
71
72
long now = millis();
if (now - lastMsg > 1000) {
if (deviceConnected&&rxload.length()>0) {
Serial.println(rxload);
rxload="";
}
if(Serial.available()>0){
String str=Serial.readString();
const char *newValue=str.c_str();
pCharacteristic->setValue(newValue);
pCharacteristic->notify();
}
lastMsg = now;
}

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove ESP32-S3 and is the answer not in the manual?

Freenove ESP32-S3 Specifications

General IconGeneral
BrandFreenove
ModelESP32-S3
CategoryControl Unit
LanguageEnglish