forked from h2zero/esp-nimble-cpp
Build with idf v5.1
This commit is contained in:
@@ -56,7 +56,7 @@ class MyClientCallback : public BLEClientCallbacks {
|
||||
return 123456;
|
||||
}
|
||||
bool onConfirmPIN(uint32_t pass_key){
|
||||
printf("The passkey YES/NO number: %d\n", pass_key);
|
||||
printf("The passkey YES/NO number: %" PRIu32"\n", pass_key);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ uint32_t value = 0;
|
||||
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
|
||||
|
||||
/** None of these are required as they will be handled by the library with defaults. **
|
||||
** Remove as you see fit for your needs */
|
||||
** Remove as you see fit for your needs */
|
||||
class MyServerCallbacks: public BLEServerCallbacks {
|
||||
void onConnect(BLEServer* pServer, BLEConnInfo& connInfo) {
|
||||
deviceConnected = true;
|
||||
@@ -59,12 +59,12 @@ class MyServerCallbacks: public BLEServerCallbacks {
|
||||
****** Note: these are the same return values as defaults ********/
|
||||
uint32_t onPassKeyRequest(){
|
||||
printf("Server PassKeyRequest\n");
|
||||
return 123456;
|
||||
return 123456;
|
||||
}
|
||||
|
||||
bool onConfirmPIN(uint32_t pass_key){
|
||||
printf("The passkey YES/NO number: %d\n", pass_key);
|
||||
return true;
|
||||
printf("The passkey YES/NO number: %" PRIu32"\n", pass_key);
|
||||
return true;
|
||||
}
|
||||
|
||||
void onAuthenticationComplete(BLEConnInfo& connInfo){
|
||||
@@ -94,13 +94,13 @@ void connectedTask (void * parameter){
|
||||
// do stuff here on connecting
|
||||
oldDeviceConnected = deviceConnected;
|
||||
}
|
||||
|
||||
|
||||
vTaskDelay(10/portTICK_PERIOD_MS); // Delay between loops to reset watchdog timer
|
||||
}
|
||||
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
|
||||
void app_main(void) {
|
||||
// Create the BLE Device
|
||||
BLEDevice::init("ESP32");
|
||||
@@ -115,13 +115,13 @@ void app_main(void) {
|
||||
// Create a BLE Characteristic
|
||||
pCharacteristic = pService->createCharacteristic(
|
||||
CHARACTERISTIC_UUID,
|
||||
/******* Enum Type NIMBLE_PROPERTY now *******
|
||||
/******* Enum Type NIMBLE_PROPERTY now *******
|
||||
BLECharacteristic::PROPERTY_READ |
|
||||
BLECharacteristic::PROPERTY_WRITE |
|
||||
BLECharacteristic::PROPERTY_NOTIFY |
|
||||
BLECharacteristic::PROPERTY_INDICATE
|
||||
);
|
||||
**********************************************/
|
||||
**********************************************/
|
||||
NIMBLE_PROPERTY::READ |
|
||||
NIMBLE_PROPERTY::WRITE |
|
||||
NIMBLE_PROPERTY::NOTIFY |
|
||||
@@ -130,11 +130,11 @@ void app_main(void) {
|
||||
|
||||
// https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
|
||||
// Create a BLE Descriptor
|
||||
/***************************************************
|
||||
NOTE: DO NOT create a 2902 descriptor.
|
||||
it will be created automatically if notifications
|
||||
/***************************************************
|
||||
NOTE: DO NOT create a 2902 descriptor.
|
||||
it will be created automatically if notifications
|
||||
or indications are enabled on a characteristic.
|
||||
|
||||
|
||||
pCharacteristic->addDescriptor(new BLE2902());
|
||||
****************************************************/
|
||||
// Start the service
|
||||
@@ -147,9 +147,9 @@ void app_main(void) {
|
||||
/** This method had been removed **
|
||||
pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter
|
||||
**/
|
||||
|
||||
|
||||
xTaskCreate(connectedTask, "connectedTask", 5000, NULL, 1, NULL);
|
||||
|
||||
|
||||
BLEDevice::startAdvertising();
|
||||
printf("Waiting a client connection to notify...\n");
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
Create a BLE server that, once we receive a connection, will send periodic notifications.
|
||||
The service advertises itself as: 6E400001-B5A3-F393-E0A9-E50E24DCCA9E
|
||||
Has a characteristic of: 6E400002-B5A3-F393-E0A9-E50E24DCCA9E - used for receiving data with "WRITE"
|
||||
Has a characteristic of: 6E400002-B5A3-F393-E0A9-E50E24DCCA9E - used for receiving data with "WRITE"
|
||||
Has a characteristic of: 6E400003-B5A3-F393-E0A9-E50E24DCCA9E - used to send data with "NOTIFY"
|
||||
|
||||
The design of creating the BLE server is:
|
||||
@@ -18,7 +18,7 @@
|
||||
6. Start advertising.
|
||||
|
||||
In this example rxValue is the data received (only accessible inside that function).
|
||||
And txValue is the data to be sent, in this example just a byte incremented every second.
|
||||
And txValue is the data to be sent, in this example just a byte incremented every second.
|
||||
*/
|
||||
|
||||
/** NimBLE differences highlighted in comment blocks **/
|
||||
@@ -48,7 +48,7 @@ uint8_t txValue = 0;
|
||||
|
||||
|
||||
/** None of these are required as they will be handled by the library with defaults. **
|
||||
** Remove as you see fit for your needs */
|
||||
** Remove as you see fit for your needs */
|
||||
class MyServerCallbacks: public BLEServerCallbacks {
|
||||
void onConnect(BLEServer* pServer, BLEConnInfo& connInfo) {
|
||||
deviceConnected = true;
|
||||
@@ -61,12 +61,12 @@ class MyServerCallbacks: public BLEServerCallbacks {
|
||||
****** Note: these are the same return values as defaults ********/
|
||||
uint32_t onPassKeyRequest(){
|
||||
printf("Server PassKeyRequest\n");
|
||||
return 123456;
|
||||
return 123456;
|
||||
}
|
||||
|
||||
bool onConfirmPIN(uint32_t pass_key){
|
||||
printf("The passkey YES/NO number: %d\n", pass_key);
|
||||
return true;
|
||||
printf("The passkey YES/NO number: %" PRIu32"\n", pass_key);
|
||||
return true;
|
||||
}
|
||||
|
||||
void onAuthenticationComplete(BLEConnInfo& connInfo){
|
||||
@@ -84,7 +84,7 @@ class MyCallbacks: public BLECharacteristicCallbacks {
|
||||
printf("Received Value: ");
|
||||
for (int i = 0; i < rxValue.length(); i++)
|
||||
printf("%d", rxValue[i]);
|
||||
|
||||
|
||||
printf("\n*********\n");
|
||||
}
|
||||
}
|
||||
@@ -109,10 +109,10 @@ void connectedTask (void * parameter){
|
||||
// do stuff here on connecting
|
||||
oldDeviceConnected = deviceConnected;
|
||||
}
|
||||
|
||||
|
||||
vTaskDelay(10/portTICK_PERIOD_MS); // Delay between loops to reset watchdog timer
|
||||
}
|
||||
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
@@ -130,27 +130,27 @@ void app_main(void) {
|
||||
// Create a BLE Characteristic
|
||||
pTxCharacteristic = pService->createCharacteristic(
|
||||
CHARACTERISTIC_UUID_TX,
|
||||
/******* Enum Type NIMBLE_PROPERTY now *******
|
||||
/******* Enum Type NIMBLE_PROPERTY now *******
|
||||
BLECharacteristic::PROPERTY_NOTIFY
|
||||
);
|
||||
**********************************************/
|
||||
**********************************************/
|
||||
NIMBLE_PROPERTY::NOTIFY
|
||||
);
|
||||
|
||||
/***************************************************
|
||||
NOTE: DO NOT create a 2902 descriptor
|
||||
it will be created automatically if notifications
|
||||
|
||||
/***************************************************
|
||||
NOTE: DO NOT create a 2902 descriptor
|
||||
it will be created automatically if notifications
|
||||
or indications are enabled on a characteristic.
|
||||
|
||||
|
||||
pCharacteristic->addDescriptor(new BLE2902());
|
||||
****************************************************/
|
||||
****************************************************/
|
||||
|
||||
BLECharacteristic * pRxCharacteristic = pService->createCharacteristic(
|
||||
CHARACTERISTIC_UUID_RX,
|
||||
/******* Enum Type NIMBLE_PROPERTY now *******
|
||||
/******* Enum Type NIMBLE_PROPERTY now *******
|
||||
BLECharacteristic::PROPERTY_WRITE
|
||||
);
|
||||
*********************************************/
|
||||
*********************************************/
|
||||
NIMBLE_PROPERTY::WRITE
|
||||
);
|
||||
|
||||
@@ -160,7 +160,7 @@ void app_main(void) {
|
||||
pService->start();
|
||||
|
||||
xTaskCreate(connectedTask, "connectedTask", 5000, NULL, 1, NULL);
|
||||
|
||||
|
||||
// Start advertising
|
||||
pServer->getAdvertising()->start();
|
||||
printf("Waiting a client connection to notify...\n");
|
||||
|
||||
Reference in New Issue
Block a user