Fix example / docs build

This commit is contained in:
h2zero 2022-10-30 09:28:50 -06:00
parent 629763ddaf
commit f63a6ddc61
5 changed files with 33 additions and 35 deletions

View file

@ -36,7 +36,7 @@ jobs:
container: espressif/idf:${{ matrix.idf_ver }} container: espressif/idf:${{ matrix.idf_ver }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v3
with: with:
path: components/esp-nimble-cpp path: components/esp-nimble-cpp
- name: Build examples - name: Build examples
@ -51,7 +51,7 @@ jobs:
build_docs: build_docs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Doxygen Action - name: Doxygen Action
uses: mattnotmitt/doxygen-action@v1.9.1 uses: mattnotmitt/doxygen-action@v1.9.1
with: with:

View file

@ -2,10 +2,10 @@
/** NimBLE_Server Demo: /** NimBLE_Server Demo:
* *
* Demonstrates many of the available features of the NimBLE server library. * Demonstrates many of the available features of the NimBLE server library.
* *
* Created: on March 22 2020 * Created: on March 22 2020
* Author: H2zero * Author: H2zero
* *
*/ */
#include "NimBLEDevice.h" #include "NimBLEDevice.h"
#include "NimBLELog.h" #include "NimBLELog.h"
@ -17,15 +17,15 @@ extern "C" {void app_main(void);}
static NimBLEServer* pServer; static NimBLEServer* pServer;
/** None of these are required as they will be handled by the library with defaults. ** /** 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 { class ServerCallbacks: public NimBLEServerCallbacks {
void onConnect(NimBLEServer* pServer) { void onConnect(NimBLEServer* pServer) {
printf("Client connected\n"); printf("Client connected\n");
NimBLEDevice::startAdvertising(); NimBLEDevice::startAdvertising();
}; };
/** Alternative onConnect() method to extract details of the connection. /** Alternative onConnect() method to extract details of the connection.
* See: src/ble_gap.h for the details of the ble_gap_conn_desc struct. * See: src/ble_gap.h for the details of the ble_gap_conn_desc struct.
*/ */
void onConnect(NimBLEServer* pServer, ble_gap_conn_desc* desc) { void onConnect(NimBLEServer* pServer, ble_gap_conn_desc* desc) {
printf("Client address: %s\n", NimBLEAddress(desc->peer_ota_addr).toString().c_str()); printf("Client address: %s\n", NimBLEAddress(desc->peer_ota_addr).toString().c_str());
/** We can use the connection handle here to ask for different connection parameters. /** We can use the connection handle here to ask for different connection parameters.
@ -33,7 +33,7 @@ class ServerCallbacks: public NimBLEServerCallbacks {
* latency, supervision timeout. * latency, supervision timeout.
* Units; Min/Max Intervals: 1.25 millisecond increments. * Units; Min/Max Intervals: 1.25 millisecond increments.
* Latency: number of intervals allowed to skip. * 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(desc->conn_handle, 24, 48, 0, 18); pServer->updateConnParams(desc->conn_handle, 24, 48, 0, 18);
}; };
@ -44,25 +44,25 @@ class ServerCallbacks: public NimBLEServerCallbacks {
void onMTUChange(uint16_t MTU, ble_gap_conn_desc* desc) { void onMTUChange(uint16_t MTU, ble_gap_conn_desc* desc) {
printf("MTU updated: %u for connection ID: %u\n", MTU, desc->conn_handle); printf("MTU updated: %u for connection ID: %u\n", MTU, desc->conn_handle);
}; };
/********************* Security handled here ********************** /********************* Security handled here **********************
****** Note: these are the same return values as defaults ********/ ****** Note: these are the same return values as defaults ********/
uint32_t onPassKeyRequest(){ uint32_t onPassKeyRequest(){
printf("Server Passkey Request\n"); 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. * or make your own static passkey as done here.
*/ */
return 123456; return 123456;
}; };
bool onConfirmPIN(uint32_t pass_key){ bool onConfirmPIN(uint32_t pass_key){
printf("The passkey YES/NO number: %d\n", pass_key); printf("The passkey YES/NO number: %d\n", pass_key);
/** Return false if passkeys don't match. */ /** Return false if passkeys don't match. */
return true; return true;
}; };
void onAuthenticationComplete(ble_gap_conn_desc* desc){ void onAuthenticationComplete(ble_gap_conn_desc* desc){
/** Check that encryption was successful, if not we disconnect the client */ /** Check that encryption was successful, if not we disconnect the client */
if(!desc->sec_state.encrypted) { if(!desc->sec_state.encrypted) {
/** NOTE: createServer returns the current server reference unless one is not already created */ /** NOTE: createServer returns the current server reference unless one is not already created */
NimBLEDevice::createServer()->disconnect(desc->conn_handle); NimBLEDevice::createServer()->disconnect(desc->conn_handle);
@ -76,17 +76,17 @@ class ServerCallbacks: public NimBLEServerCallbacks {
/** Handler class for characteristic actions */ /** Handler class for characteristic actions */
class CharacteristicCallbacks: public NimBLECharacteristicCallbacks { class CharacteristicCallbacks: public NimBLECharacteristicCallbacks {
void onRead(NimBLECharacteristic* pCharacteristic){ void onRead(NimBLECharacteristic* pCharacteristic){
printf("%s : onRead(), value: %s\n", printf("%s : onRead(), value: %s\n",
pCharacteristic->getUUID().toString().c_str(), pCharacteristic->getUUID().toString().c_str(),
pCharacteristic->getValue().c_str()); pCharacteristic->getValue().c_str());
}; };
void onWrite(NimBLECharacteristic* pCharacteristic) { void onWrite(NimBLECharacteristic* pCharacteristic) {
printf("%s : onWrite(), value: %s\n", printf("%s : onWrite(), value: %s\n",
pCharacteristic->getUUID().toString().c_str(), pCharacteristic->getUUID().toString().c_str(),
pCharacteristic->getValue().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. * the value can be changed here before sending if desired.
*/ */
void onNotify(NimBLECharacteristic* pCharacteristic) { void onNotify(NimBLECharacteristic* pCharacteristic) {
@ -104,11 +104,11 @@ class CharacteristicCallbacks: public NimBLECharacteristicCallbacks {
NimBLEUtils::returnCodeToString(code)); NimBLEUtils::returnCodeToString(code));
}; };
}; };
/** Handler class for descriptor actions */ /** Handler class for descriptor actions */
class DescriptorCallbacks : public NimBLEDescriptorCallbacks { class DescriptorCallbacks : public NimBLEDescriptorCallbacks {
void onWrite(NimBLEDescriptor* pDescriptor) { void onWrite(NimBLEDescriptor* pDescriptor) {
std::string dscVal((char*)pDescriptor->getValue(), pDescriptor->getLength()); std::string dscVal = pDescriptor->getValue();
printf("Descriptor witten value: %s\n", dscVal.c_str()); printf("Descriptor witten value: %s\n", dscVal.c_str());
}; };
@ -118,7 +118,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 DescriptorCallbacks dscCallbacks;
static CharacteristicCallbacks chrCallbacks; static CharacteristicCallbacks chrCallbacks;
@ -135,7 +135,7 @@ void notifyTask(void * parameter){
} }
vTaskDelay(2000/portTICK_PERIOD_MS); vTaskDelay(2000/portTICK_PERIOD_MS);
} }
vTaskDelete(NULL); vTaskDelete(NULL);
} }
@ -155,10 +155,10 @@ void app_main(void) {
/** 2 different ways to set security - both calls achieve the same result. /** 2 different ways to set security - both calls achieve the same result.
* no bonding, no man in the middle protection, secure connections. * no bonding, no man in the middle protection, secure connections.
* *
* These are the default values, only shown here for demonstration. * These are the default values, only shown here for demonstration.
*/ */
//NimBLEDevice::setSecurityAuth(false, false, true); //NimBLEDevice::setSecurityAuth(false, false, true);
NimBLEDevice::setSecurityAuth(/*BLE_SM_PAIR_AUTHREQ_BOND | BLE_SM_PAIR_AUTHREQ_MITM |*/ BLE_SM_PAIR_AUTHREQ_SC); NimBLEDevice::setSecurityAuth(/*BLE_SM_PAIR_AUTHREQ_BOND | BLE_SM_PAIR_AUTHREQ_MITM |*/ BLE_SM_PAIR_AUTHREQ_SC);
pServer = NimBLEDevice::createServer(); pServer = NimBLEDevice::createServer();
@ -173,7 +173,7 @@ void app_main(void) {
NIMBLE_PROPERTY::READ_ENC | // only allow reading if paired / encrypted NIMBLE_PROPERTY::READ_ENC | // only allow reading if paired / encrypted
NIMBLE_PROPERTY::WRITE_ENC // only allow writing if paired / encrypted NIMBLE_PROPERTY::WRITE_ENC // only allow writing if paired / encrypted
); );
pBeefCharacteristic->setValue("Burger"); pBeefCharacteristic->setValue("Burger");
pBeefCharacteristic->setCallbacks(&chrCallbacks); pBeefCharacteristic->setCallbacks(&chrCallbacks);
@ -182,10 +182,10 @@ void app_main(void) {
* and sizes. However we must cast the returned reference to the correct type as the method * 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. * 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->setFormat(NimBLE2904::FORMAT_UTF8);
pBeef2904->setCallbacks(&dscCallbacks); pBeef2904->setCallbacks(&dscCallbacks);
NimBLEService* pBaadService = pServer->createService("BAAD"); NimBLEService* pBaadService = pServer->createService("BAAD");
NimBLECharacteristic* pFoodCharacteristic = pBaadService->createCharacteristic( NimBLECharacteristic* pFoodCharacteristic = pBaadService->createCharacteristic(
@ -201,7 +201,7 @@ void app_main(void) {
/** Custom descriptor: Arguments are UUID, Properties, max length in bytes of the value */ /** Custom descriptor: Arguments are UUID, Properties, max length in bytes of the value */
NimBLEDescriptor* pC01Ddsc = pFoodCharacteristic->createDescriptor( NimBLEDescriptor* pC01Ddsc = pFoodCharacteristic->createDescriptor(
"C01D", "C01D",
NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::READ |
NIMBLE_PROPERTY::WRITE| NIMBLE_PROPERTY::WRITE|
NIMBLE_PROPERTY::WRITE_ENC, // only allow writing if paired / encrypted NIMBLE_PROPERTY::WRITE_ENC, // only allow writing if paired / encrypted
20 20
@ -209,7 +209,7 @@ void app_main(void) {
pC01Ddsc->setValue("Send it back!"); pC01Ddsc->setValue("Send it back!");
pC01Ddsc->setCallbacks(&dscCallbacks); 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(); pDeadService->start();
pBaadService->start(); pBaadService->start();
@ -224,6 +224,6 @@ void app_main(void) {
pAdvertising->start(); pAdvertising->start();
printf("Advertising Started\n"); printf("Advertising Started\n");
xTaskCreate(notifyTask, "notifyTask", 5000, NULL, 1, NULL); xTaskCreate(notifyTask, "notifyTask", 5000, NULL, 1, NULL);
} }

View file

@ -130,7 +130,6 @@ public:
/** /**
* @brief Called when disconnected from the server. * @brief Called when disconnected from the server.
* @param [in] pClient A pointer to the calling client object. * @param [in] pClient A pointer to the calling client object.
* @param [in] reason Contains the reason code for the disconnection.
*/ */
virtual void onDisconnect(NimBLEClient* pClient); virtual void onDisconnect(NimBLEClient* pClient);
@ -153,7 +152,7 @@ public:
/** /**
* @brief Called when the pairing procedure is complete. * @brief Called when the pairing procedure is complete.
* @param [in] connInfo A reference to a NimBLEConnInfo instance containing the peer info.\n * @param [in] desc A reference to a NimBLEConnInfo instance containing the peer info.\n
* This can be used to check the status of the connection encryption/pairing. * This can be used to check the status of the connection encryption/pairing.
*/ */
virtual void onAuthenticationComplete(ble_gap_conn_desc* desc); virtual void onAuthenticationComplete(ble_gap_conn_desc* desc);

View file

@ -285,7 +285,6 @@ NimBLEDescriptorCallbacks::~NimBLEDescriptorCallbacks() {}
/** /**
* @brief Callback function to support a read request. * @brief Callback function to support a read request.
* @param [in] pDescriptor The descriptor that is the source of the event. * @param [in] pDescriptor The descriptor that is the source of the event.
* @param [in] connInfo A reference to a NimBLEConnInfo instance containing the peer info.
*/ */
void NimBLEDescriptorCallbacks::onRead(NimBLEDescriptor* pDescriptor) { void NimBLEDescriptorCallbacks::onRead(NimBLEDescriptor* pDescriptor) {
(void)pDescriptor; (void)pDescriptor;
@ -296,7 +295,6 @@ void NimBLEDescriptorCallbacks::onRead(NimBLEDescriptor* pDescriptor) {
/** /**
* @brief Callback function to support a write request. * @brief Callback function to support a write request.
* @param [in] pDescriptor The descriptor that is the source of the event. * @param [in] pDescriptor The descriptor that is the source of the event.
* @param [in] connInfo A reference to a NimBLEConnInfo instance containing the peer info.
*/ */
void NimBLEDescriptorCallbacks::onWrite(NimBLEDescriptor* pDescriptor) { void NimBLEDescriptorCallbacks::onWrite(NimBLEDescriptor* pDescriptor) {
(void)pDescriptor; (void)pDescriptor;

View file

@ -624,6 +624,7 @@ bool NimBLERemoteCharacteristic::setNotify(uint16_t val, notify_callback notifyC
* @brief Subscribe for notifications or indications. * @brief Subscribe for notifications or indications.
* @param [in] notifications If true, subscribe for notifications, false subscribe for indications. * @param [in] notifications If true, subscribe for notifications, false subscribe for indications.
* @param [in] notifyCallback A callback to be invoked for a notification. * @param [in] notifyCallback A callback to be invoked for a notification.
* @param [in] response If true, require a write response from the descriptor write operation.
* If NULL is provided then no callback is performed. * If NULL is provided then no callback is performed.
* @return false if writing to the descriptor failed. * @return false if writing to the descriptor failed.
*/ */