mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-21 20:50:55 +01:00
Build with idf v5.1
This commit is contained in:
parent
d0eaf6c1e0
commit
3145319581
8 changed files with 74 additions and 74 deletions
8
.github/workflows/build.yml
vendored
8
.github/workflows/build.yml
vendored
|
@ -12,7 +12,7 @@ jobs:
|
|||
# See https://hub.docker.com/r/espressif/idf/tags and
|
||||
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-docker-image.html
|
||||
# for details.
|
||||
idf_ver: ["release-v4.4"]
|
||||
idf_ver: ["release-v4.4", "release-v5.1"]
|
||||
idf_target: ["esp32", "esp32s3", "esp32c3"]
|
||||
example:
|
||||
- Advanced/NimBLE_Client
|
||||
|
@ -36,7 +36,7 @@ jobs:
|
|||
container: espressif/idf:${{ matrix.idf_ver }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
path: components/esp-nimble-cpp
|
||||
- name: Build examples
|
||||
|
@ -51,8 +51,8 @@ jobs:
|
|||
build_docs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: Doxygen Action
|
||||
uses: mattnotmitt/doxygen-action@v1.9.1
|
||||
uses: mattnotmitt/doxygen-action@v1.9.5
|
||||
with:
|
||||
working-directory: 'docs/'
|
||||
|
|
|
@ -46,7 +46,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {
|
|||
}
|
||||
|
||||
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 false if passkeys don't match. */
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
/** NimBLE_Server Demo:
|
||||
*
|
||||
* Demonstrates many of the available features of the NimBLE server library.
|
||||
*
|
||||
*
|
||||
* Created: on March 22 2020
|
||||
* Author: H2zero
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "NimBLEDevice.h"
|
||||
#include "NimBLELog.h"
|
||||
|
@ -17,21 +17,21 @@ extern "C" {void app_main(void);}
|
|||
static NimBLEServer* pServer;
|
||||
|
||||
/** 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 ServerCallbacks: public NimBLEServerCallbacks {
|
||||
void onConnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo) {
|
||||
printf("Client address: %s\n", connInfo.getAddress().toString().c_str());
|
||||
|
||||
|
||||
/** We can use the connection handle here to ask for different connection parameters.
|
||||
* Args: connection handle, min connection interval, max connection interval
|
||||
* latency, supervision timeout.
|
||||
* Units; Min/Max Intervals: 1.25 millisecond increments.
|
||||
* Latency: number of intervals allowed to skip.
|
||||
* Timeout: 10 millisecond increments, try for 3x interval time for best results.
|
||||
* Timeout: 10 millisecond increments, try for 3x interval time for best results.
|
||||
*/
|
||||
pServer->updateConnParams(connInfo.getConnHandle(), 24, 48, 0, 18);
|
||||
};
|
||||
|
||||
|
||||
void onDisconnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo, int reason) {
|
||||
printf("Client disconnected - start advertising\n");
|
||||
NimBLEDevice::startAdvertising();
|
||||
|
@ -41,25 +41,25 @@ class ServerCallbacks: public NimBLEServerCallbacks {
|
|||
printf("MTU updated: %u for connection ID: %u\n", MTU, connInfo.getConnHandle());
|
||||
pServer->updateConnParams(connInfo.getConnHandle(), 24, 48, 0, 60);
|
||||
};
|
||||
|
||||
|
||||
/********************* Security handled here **********************
|
||||
****** Note: these are the same return values as defaults ********/
|
||||
uint32_t onPassKeyRequest(){
|
||||
printf("Server Passkey Request\n");
|
||||
/** This should return a random 6 digit number for security
|
||||
/** This should return a random 6 digit number for security
|
||||
* or make your own static passkey as done here.
|
||||
*/
|
||||
return 123456;
|
||||
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 false if passkeys don't match. */
|
||||
return true;
|
||||
return true;
|
||||
};
|
||||
|
||||
void onAuthenticationComplete(NimBLEConnInfo& connInfo){
|
||||
/** Check that encryption was successful, if not we disconnect the client */
|
||||
/** Check that encryption was successful, if not we disconnect the client */
|
||||
if(!connInfo.isEncrypted()) {
|
||||
NimBLEDevice::getServer()->disconnect(connInfo.getConnHandle());
|
||||
printf("Encrypt connection failed - disconnecting client\n");
|
||||
|
@ -72,18 +72,18 @@ class ServerCallbacks: public NimBLEServerCallbacks {
|
|||
/** Handler class for characteristic actions */
|
||||
class CharacteristicCallbacks: public NimBLECharacteristicCallbacks {
|
||||
void onRead(NimBLECharacteristic* pCharacteristic, NimBLEConnInfo& connInfo) {
|
||||
printf("%s : onRead(), value: %s\n",
|
||||
printf("%s : onRead(), value: %s\n",
|
||||
pCharacteristic->getUUID().toString().c_str(),
|
||||
pCharacteristic->getValue().c_str());
|
||||
}
|
||||
|
||||
void onWrite(NimBLECharacteristic* pCharacteristic, NimBLEConnInfo& connInfo) {
|
||||
printf("%s : onWrite(), value: %s\n",
|
||||
printf("%s : onWrite(), value: %s\n",
|
||||
pCharacteristic->getUUID().toString().c_str(),
|
||||
pCharacteristic->getValue().c_str());
|
||||
}
|
||||
|
||||
/** Called before notification or indication is sent,
|
||||
/** Called before notification or indication is sent,
|
||||
* the value can be changed here before sending if desired.
|
||||
*/
|
||||
void onNotify(NimBLECharacteristic* pCharacteristic) {
|
||||
|
@ -117,8 +117,8 @@ class CharacteristicCallbacks: public NimBLECharacteristicCallbacks {
|
|||
printf("%s\n", str.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
/** Handler class for descriptor actions */
|
||||
|
||||
/** Handler class for descriptor actions */
|
||||
class DescriptorCallbacks : public NimBLEDescriptorCallbacks {
|
||||
void onWrite(NimBLEDescriptor* pDescriptor, NimBLEConnInfo& connInfo) {
|
||||
std::string dscVal = pDescriptor->getValue();
|
||||
|
@ -131,7 +131,7 @@ class DescriptorCallbacks : public NimBLEDescriptorCallbacks {
|
|||
};
|
||||
|
||||
|
||||
/** Define callback instances globally to use for multiple Charateristics \ Descriptors */
|
||||
/** Define callback instances globally to use for multiple Charateristics \ Descriptors */
|
||||
static DescriptorCallbacks dscCallbacks;
|
||||
static CharacteristicCallbacks chrCallbacks;
|
||||
|
||||
|
@ -148,7 +148,7 @@ void notifyTask(void * parameter){
|
|||
}
|
||||
vTaskDelay(2000/portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
|
@ -168,10 +168,10 @@ void app_main(void) {
|
|||
|
||||
/** 2 different ways to set security - both calls achieve the same result.
|
||||
* no bonding, no man in the middle protection, secure connections.
|
||||
*
|
||||
* These are the default values, only shown here for demonstration.
|
||||
*/
|
||||
//NimBLEDevice::setSecurityAuth(false, false, true);
|
||||
*
|
||||
* These are the default values, only shown here for demonstration.
|
||||
*/
|
||||
//NimBLEDevice::setSecurityAuth(false, false, true);
|
||||
NimBLEDevice::setSecurityAuth(/*BLE_SM_PAIR_AUTHREQ_BOND | BLE_SM_PAIR_AUTHREQ_MITM |*/ BLE_SM_PAIR_AUTHREQ_SC);
|
||||
|
||||
pServer = NimBLEDevice::createServer();
|
||||
|
@ -186,7 +186,7 @@ void app_main(void) {
|
|||
NIMBLE_PROPERTY::READ_ENC | // only allow reading if paired / encrypted
|
||||
NIMBLE_PROPERTY::WRITE_ENC // only allow writing if paired / encrypted
|
||||
);
|
||||
|
||||
|
||||
pBeefCharacteristic->setValue("Burger");
|
||||
pBeefCharacteristic->setCallbacks(&chrCallbacks);
|
||||
|
||||
|
@ -195,10 +195,10 @@ void app_main(void) {
|
|||
* and sizes. However we must cast the returned reference to the correct type as the method
|
||||
* only returns a pointer to the base NimBLEDescriptor class.
|
||||
*/
|
||||
NimBLE2904* pBeef2904 = (NimBLE2904*)pBeefCharacteristic->createDescriptor("2904");
|
||||
NimBLE2904* pBeef2904 = (NimBLE2904*)pBeefCharacteristic->createDescriptor("2904");
|
||||
pBeef2904->setFormat(NimBLE2904::FORMAT_UTF8);
|
||||
pBeef2904->setCallbacks(&dscCallbacks);
|
||||
|
||||
|
||||
|
||||
NimBLEService* pBaadService = pServer->createService("BAAD");
|
||||
NimBLECharacteristic* pFoodCharacteristic = pBaadService->createCharacteristic(
|
||||
|
@ -214,7 +214,7 @@ void app_main(void) {
|
|||
/** Custom descriptor: Arguments are UUID, Properties, max length in bytes of the value */
|
||||
NimBLEDescriptor* pC01Ddsc = pFoodCharacteristic->createDescriptor(
|
||||
"C01D",
|
||||
NIMBLE_PROPERTY::READ |
|
||||
NIMBLE_PROPERTY::READ |
|
||||
NIMBLE_PROPERTY::WRITE|
|
||||
NIMBLE_PROPERTY::WRITE_ENC, // only allow writing if paired / encrypted
|
||||
20
|
||||
|
@ -222,7 +222,7 @@ void app_main(void) {
|
|||
pC01Ddsc->setValue("Send it back!");
|
||||
pC01Ddsc->setCallbacks(&dscCallbacks);
|
||||
|
||||
/** Start the services when finished creating all Characteristics and Descriptors */
|
||||
/** Start the services when finished creating all Characteristics and Descriptors */
|
||||
pDeadService->start();
|
||||
pBaadService->start();
|
||||
|
||||
|
@ -237,6 +237,6 @@ void app_main(void) {
|
|||
pAdvertising->start();
|
||||
|
||||
printf("Advertising Started\n");
|
||||
|
||||
|
||||
xTaskCreate(notifyTask, "notifyTask", 5000, NULL, 1, NULL);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ class ServerCallbacks: public NimBLEServerCallbacks {
|
|||
};
|
||||
|
||||
void onDisconnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo, int reason) {
|
||||
printf("Client disconnected - sleeping for %u seconds\n", sleepSeconds);
|
||||
printf("Client disconnected - sleeping for %" PRIu32" seconds\n", sleepSeconds);
|
||||
esp_deep_sleep_start();
|
||||
};
|
||||
};
|
||||
|
@ -57,7 +57,7 @@ class advertisingCallbacks: public NimBLEExtAdvertisingCallbacks {
|
|||
printf("Client connecting\n");
|
||||
return;
|
||||
case BLE_HS_ETIMEOUT:
|
||||
printf("Time expired - sleeping for %u seconds\n", sleepSeconds);
|
||||
printf("Time expired - sleeping for %" PRIu32" seconds\n", sleepSeconds);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -45,7 +45,7 @@ class ServerCallbacks: public NimBLEServerCallbacks {
|
|||
printf("Client disconnected\n");
|
||||
// if still advertising we won't sleep yet.
|
||||
if (!pServer->getAdvertising()->isAdvertising()) {
|
||||
printf("Sleeping for %u seconds\n", sleepTime);
|
||||
printf("Sleeping for %" PRIu32" seconds\n", sleepTime);
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
};
|
||||
|
@ -61,7 +61,7 @@ class advCallbacks: public NimBLEExtAdvertisingCallbacks {
|
|||
printf(" client connecting\n");
|
||||
return;
|
||||
case BLE_HS_ETIMEOUT:
|
||||
printf("Time expired - sleeping for %u seconds\n", sleepTime);
|
||||
printf("Time expired - sleeping for %" PRIu32" seconds\n", sleepTime);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue