Skip to content

Commit a99ebb7

Browse files
authored
Merge branch 'master' into v1.4.2-adv-data-refresh
2 parents 26bb4a1 + ca26070 commit a99ebb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4384
-3826
lines changed

.clang-format

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
BasedOnStyle: Google
2+
Language: Cpp
3+
ColumnLimit: 120
4+
IndentWidth: 4
5+
TabWidth: 4
6+
UseTab: Never
7+
SortIncludes: Never
8+
PPIndentWidth : 1
9+
IndentPPDirectives: AfterHash
10+
ReflowComments: true
11+
SpacesBeforeTrailingComments: 1
12+
AlignTrailingComments: true
13+
AlignAfterOpenBracket: Align
14+
AlignConsecutiveMacros:
15+
Enabled: true
16+
AcrossEmptyLines: true
17+
AcrossComments: true
18+
AlignConsecutiveAssignments:
19+
Enabled: true
20+
AcrossEmptyLines: false
21+
AcrossComments: true
22+
AlignCompound: true
23+
PadOperators: true
24+
AlignConsecutiveDeclarations:
25+
Enabled: true
26+
AcrossEmptyLines: false
27+
AcrossComments: true
28+
AlignEscapedNewlines: Left
29+
AccessModifierOffset: -2
30+
AlignArrayOfStructures: Right
31+
AlignOperands: Align
32+
AllowAllArgumentsOnNextLine: false
33+
AllowShortFunctionsOnASingleLine: Inline
34+
AllowShortBlocksOnASingleLine: Empty
35+
BreakBeforeBinaryOperators: None
36+
BinPackArguments: false
37+
BinPackParameters: false
38+
DerivePointerAlignment: false
39+
PenaltyBreakAssignment: 4
40+
PenaltyExcessCharacter: 4
41+
PenaltyBreakBeforeFirstCallParameter: 1
42+
PointerAlignment: Left

.github/workflows/build.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: Build
22

3-
on: [push, pull_request]
3+
on:
4+
workflow_dispatch: # Start a workflow
5+
pull_request:
6+
push:
7+
branches:
8+
- master
49

510
jobs:
611
build_esp_pio:

docs/Migration_guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ The security callback methods are now incorporated in the `NimBLEServerCallbacks
383383

384384
The callback methods are:
385385

386-
> `bool onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pin)`
386+
> `bool onConfirmPasskey(NimBLEConnInfo& connInfo, uint32_t pin)`
387387
388388
Receives the pin when using numeric comparison authentication.
389389
Call `NimBLEDevice::injectConfirmPasskey(connInfo, true);` to accept or `NimBLEDevice::injectConfirmPasskey(connInfo, false);` to reject.

examples/BLE_EddystoneTLM_Beacon/BLE_EddystoneTLM_Beacon.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
4. wait
1313
5. Stop advertising.
1414
6. deep sleep
15-
15+
1616
*/
1717

1818
#include "NimBLEDevice.h"
@@ -26,7 +26,7 @@
2626
#define GPIO_DEEP_SLEEP_DURATION 10 // sleep x seconds and then wake up
2727

2828
// UUID 1 128-Bit (may use linux tool uuidgen or random numbers via https://www.uuidgenerator.net/)
29-
#define BEACON_UUID "8ec76ea3-6668-48da-9866-75be8bc86f4d"
29+
#define BEACON_UUID "8ec76ea3-6668-48da-9866-75be8bc86f4d"
3030

3131
RTC_DATA_ATTR static time_t last; // remember last boot in RTC Memory
3232
RTC_DATA_ATTR static uint32_t bootcount; // remember number of boots in RTC Memory
@@ -96,6 +96,7 @@ void setup()
9696
BLEDevice::setPower(ESP_PWR_LVL_N12);
9797

9898
pAdvertising = BLEDevice::getAdvertising();
99+
pAdvertising->enableScanResponse(true);
99100

100101
setBeacon();
101102
// Start advertising

examples/BLE_EddystoneURL_Beacon/BLE_EddystoneURL_Beacon.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define GPIO_DEEP_SLEEP_DURATION 10 // sleep x seconds and then wake up
2727

2828
// UUID 1 128-Bit (may use linux tool uuidgen or random numbers via https://www.uuidgenerator.net/)
29-
#define BEACON_UUID "8ec76ea3-6668-48da-9866-75be8bc86f4d"
29+
#define BEACON_UUID "8ec76ea3-6668-48da-9866-75be8bc86f4d"
3030

3131
RTC_DATA_ATTR static time_t last; // remember last boot in RTC Memory
3232
RTC_DATA_ATTR static uint32_t bootcount; // remember number of boots in RTC Memory
@@ -168,6 +168,7 @@ void setup()
168168
BLEDevice::setPower(ESP_PWR_LVL_N12);
169169

170170
pAdvertising = BLEDevice::getAdvertising();
171+
pAdvertising->enableScanResponse(true);
171172

172173
setBeacon();
173174
// Start advertising

examples/Bluetooth_5/NimBLE_extended_client/NimBLE_extended_client.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define SERVICE_UUID "ABCD"
1717
#define CHARACTERISTIC_UUID "1234"
1818

19-
static NimBLEAdvertisedDevice* advDevice;
19+
static const NimBLEAdvertisedDevice* advDevice;
2020
static bool doConnect = false;
2121
static uint32_t scanTime = 10 * 1000; // In milliseconds, 0 = scan forever
2222

@@ -40,7 +40,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {
4040
/* Define a class to handle the callbacks when advertisements are received */
4141
class scanCallbacks: public NimBLEScanCallbacks {
4242

43-
void onResult(NimBLEAdvertisedDevice* advertisedDevice) {
43+
void onResult(const NimBLEAdvertisedDevice* advertisedDevice) {
4444
Serial.printf("Advertised Device found: %s\n", advertisedDevice->toString().c_str());
4545
if(advertisedDevice->isAdvertisingService(NimBLEUUID("ABCD")))
4646
{
@@ -55,8 +55,8 @@ class scanCallbacks: public NimBLEScanCallbacks {
5555
}
5656

5757
/** Callback to process the results of the completed scan or restart it */
58-
void onScanEnd(NimBLEScanResults results) {
59-
Serial.println("Scan Ended");
58+
void onScanEnd(const NimBLEScanResults& results, int reason) {
59+
Serial.print("Scan Ended; reason = "); Serial.println(reason);
6060
}
6161
};
6262

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* NimBLE Extended Scanner Demo:
3+
*
4+
* Demonstrates the Bluetooth 5.x scanning capabilities of the NimBLE library.
5+
*
6+
* Created: on November 28, 2024
7+
* Author: H2zero
8+
*
9+
*/
10+
11+
#include <Arduino.h>
12+
#include <NimBLEDevice.h>
13+
14+
static uint32_t scanTime = 10 * 1000; // In milliseconds, 0 = scan forever
15+
static NimBLEScan::Phy scanPhy = NimBLEScan::Phy::SCAN_ALL;
16+
17+
// Define a class to handle the callbacks when advertisements are received
18+
class scanCallbacks: public NimBLEScanCallbacks {
19+
void onResult(const NimBLEAdvertisedDevice* advertisedDevice) {
20+
Serial.printf("Advertised Device found: %s\n PHY1: %d\n PHY2: %d\n", advertisedDevice->toString().c_str(),
21+
advertisedDevice->getPrimaryPhy(), advertisedDevice->getSecondaryPhy());
22+
}
23+
24+
// Callback to process the results of the completed scan or restart it
25+
void onScanEnd(const NimBLEScanResults& scanResults, int reason) {
26+
Serial.printf("Scan Ended, reason: %d; found %d devices\n", reason, scanResults.getCount());
27+
28+
// Try Different PHY's
29+
switch (scanPhy) {
30+
case NimBLEScan::Phy::SCAN_ALL:
31+
Serial.prinln("Scanning only 1M PHY");
32+
scanPhy = NimBLEScan::Phy::SCAN_1M;
33+
break;
34+
case NimBLEScan::Phy::SCAN_1M:
35+
Serial.println("Scanning only CODED PHY");
36+
scanPhy = NimBLEScan::Phy::SCAN_CODED;
37+
break;
38+
case NimBLEScan::Phy::SCAN_CODED:
39+
Serial.println("Scanning all PHY's");
40+
scanPhy = NimBLEScan::Phy::SCAN_ALL;
41+
break;
42+
}
43+
44+
NimBLEScan* pScan = NimBLEDevice::getScan();
45+
pScan->setPhy(scanPhy);
46+
pScan->start(scanTime);
47+
}
48+
} scanCb;
49+
50+
void setup() {
51+
Serial.begin(115200);
52+
Serial.printf("Starting Extended Scanner\n");
53+
54+
// Initialize NimBLE, no device name specified as we are not advertising
55+
NimBLEDevice::init("");
56+
NimBLEScan* pScan = NimBLEDevice::getScan();
57+
58+
// Set the callbacks that the scanner will call on events.
59+
pScan->setScanCallbacks(&scanCb);
60+
61+
// Use active scanning to obtain scan response data from advertisers
62+
pScan->setActiveScan(true);
63+
64+
// Set the initial PHY's to scan on, default is SCAN_ALL
65+
pScan->setPhy(scanPhy);
66+
67+
// Start scanning for scanTime, 0 = forever
68+
pScan->start(scanTime);
69+
Serial.println("Scanning for peripherals");
70+
}
71+
72+
void loop() {
73+
delay(2000);
74+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
/**
3+
* NimBLE_Async_client Demo:
4+
*
5+
* Demonstrates asynchronous client operations.
6+
*
7+
* Created: on November 4, 2024
8+
* Author: H2zero
9+
*
10+
*/
11+
12+
#include <NimBLEDevice.h>
13+
14+
static constexpr uint32_t scanTimeMs = 5 * 1000;
15+
16+
class ClientCallbacks : public NimBLEClientCallbacks {
17+
void onConnect(NimBLEClient* pClient) {
18+
Serial.printf("Connected to: %s\n", pClient->getPeerAddress().toString().c_str());
19+
}
20+
21+
void onDisconnect(NimBLEClient* pClient, int reason) {
22+
Serial.printf("%s Disconnected, reason = %d - Starting scan\n", pClient->getPeerAddress().toString().c_str(), reason);
23+
NimBLEDevice::getScan()->start(scanTimeMs);
24+
}
25+
} clientCB;
26+
27+
class scanCallbacks : public NimBLEScanCallbacks {
28+
void onResult(const NimBLEAdvertisedDevice* advertisedDevice) {
29+
Serial.printf("Advertised Device found: %s\n", advertisedDevice->toString().c_str());
30+
if (advertisedDevice->haveName() && advertisedDevice->getName() == "NimBLE-Server") {
31+
Serial.println("Found Our Device");
32+
33+
auto pClient = NimBLEDevice::getDisconnectedClient();
34+
if (!pClient) {
35+
pClient = NimBLEDevice::createClient(advertisedDevice->getAddress());
36+
if (!pClient) {
37+
Serial.println("Failed to create client");
38+
return;
39+
}
40+
}
41+
42+
pClient->setClientCallbacks(&clientCB, false);
43+
if (!pClient->connect(true, true, false)) { // delete attributes, async connect, no MTU exchange
44+
NimBLEDevice::deleteClient(pClient);
45+
Serial.println("Failed to connect");
46+
return;
47+
}
48+
}
49+
}
50+
51+
void onScanEnd(const NimBLEScanResults& results, int reason) {
52+
Serial.print("Scan Ended; reason = "); Serial.println(reason);
53+
NimBLEDevice::getScan()->start(scanTimeMs);
54+
}
55+
};
56+
57+
void setup() {
58+
Serial.begin(115200);
59+
Serial.println("Starting NimBLE Client");
60+
NimBLEDevice::init("");
61+
NimBLEDevice::setPower(3); /** +3db */
62+
63+
NimBLEScan* pScan = NimBLEDevice::getScan();
64+
pScan->setScanCallbacks(new scanCallbacks());
65+
pScan->setInterval(45);
66+
pScan->setWindow(15);
67+
pScan->setActiveScan(true);
68+
pScan->start(scanTimeMs);
69+
}
70+
71+
void loop() {
72+
delay(1000);
73+
auto pClients = NimBLEDevice::getConnectedClients();
74+
if (pClients.size() == 0) {
75+
return;
76+
}
77+
78+
for (auto& pClient : pClients) {
79+
Serial.println(pClient->toString().c_str());
80+
NimBLEDevice::deleteClient(pClient);
81+
}
82+
83+
NimBLEDevice::getScan()->start(scanTimeMs);
84+
}

examples/NimBLE_Client/NimBLE_Client.ino

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <NimBLEDevice.h>
1212

13-
static NimBLEAdvertisedDevice* advDevice;
13+
static const NimBLEAdvertisedDevice* advDevice;
1414

1515
static bool doConnect = false;
1616
static uint32_t scanTime = 0 * 1000; // In milliseconds, 0 = scan forever
@@ -64,7 +64,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {
6464
NimBLEDevice::injectPassKey(connInfo, 123456);
6565
};
6666

67-
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
67+
void onConfirmPasskey(NimBLEConnInfo& connInfo, uint32_t pass_key){
6868
Serial.print("The passkey YES/NO number: ");Serial.println(pass_key);
6969
/** Inject false if passkeys don't match. */
7070
NimBLEDevice::injectConfirmPasskey(connInfo, true);
@@ -85,7 +85,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {
8585
/** Define a class to handle the callbacks when advertisments are received */
8686
class scanCallbacks: public NimBLEScanCallbacks {
8787

88-
void onResult(NimBLEAdvertisedDevice* advertisedDevice) {
88+
void onResult(const NimBLEAdvertisedDevice* advertisedDevice) {
8989
Serial.print("Advertised Device found: ");
9090
Serial.println(advertisedDevice->toString().c_str());
9191
if(advertisedDevice->isAdvertisingService(NimBLEUUID("DEAD")))
@@ -101,8 +101,8 @@ class scanCallbacks: public NimBLEScanCallbacks {
101101
}
102102

103103
/** Callback to process the results of the completed scan or restart it */
104-
void onScanEnd(NimBLEScanResults results) {
105-
Serial.println("Scan Ended");
104+
void onScanEnd(const NimBLEScanResults& results, int reason) {
105+
Serial.print("Scan Ended; reason = "); Serial.println(reason);
106106
}
107107
};
108108

@@ -352,9 +352,6 @@ void setup (){
352352
NimBLEDevice::setPower(9); /** +9db */
353353
#endif
354354

355-
/** Optional: set any devices you don't want to get advertisments from */
356-
// NimBLEDevice::addIgnored(NimBLEAddress ("aa:bb:cc:dd:ee:ff"));
357-
358355
/** create new scan */
359356
NimBLEScan* pScan = NimBLEDevice::getScan();
360357

0 commit comments

Comments
 (0)