Skip to content

Commit 2bfcfe8

Browse files
authored
Update ESP32 example (#660)
Co-authored-by: Florian <[email protected]>
1 parent a56e987 commit 2bfcfe8

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,3 @@ jobs:
125125
run: cmake --build .
126126
- name: Test
127127
run: ctest --output-on-failure -V -C Debug .
128-
129-

examples/ESP32/ScanAndDecode/ScanAndDecode.ino

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ TheengsDecoder decoder;
1212

1313
StaticJsonDocument<512> doc;
1414

15-
class MyAdvertisedDeviceCallbacks: public NimBLEAdvertisedDeviceCallbacks {
15+
class scanCallbacks : public NimBLEScanCallbacks {
1616

1717
std::string convertServiceData(std::string deviceServiceData) {
1818
int serviceDataLength = (int)deviceServiceData.length();
@@ -33,13 +33,11 @@ class MyAdvertisedDeviceCallbacks: public NimBLEAdvertisedDeviceCallbacks {
3333
BLEdata["name"] = (char*)advertisedDevice->getName().c_str();
3434

3535
if (advertisedDevice->haveManufacturerData()) {
36-
char* manufacturerdata = BLEUtils::buildHexData(NULL, (uint8_t*)advertisedDevice->getManufacturerData().data(), advertisedDevice->getManufacturerData().length());
36+
std::string manufacturerdata = advertisedDevice->getManufacturerData();
3737
BLEdata["manufacturerdata"] = manufacturerdata;
38-
free(manufacturerdata);
3938
}
4039

41-
if (advertisedDevice->haveRSSI())
42-
BLEdata["rssi"] = (int)advertisedDevice->getRSSI();
40+
BLEdata["rssi"] = (int)advertisedDevice->getRSSI();
4341

4442
if (advertisedDevice->haveTXPower())
4543
BLEdata["txpower"] = (int8_t)advertisedDevice->getTXPower();
@@ -68,7 +66,7 @@ class MyAdvertisedDeviceCallbacks: public NimBLEAdvertisedDeviceCallbacks {
6866
Serial.println("");
6967
}
7068
}
71-
};
69+
} scanCallbacks;
7270

7371
void setup() {
7472
Serial.begin(115200);
@@ -79,7 +77,7 @@ void setup() {
7977

8078
pBLEScan = NimBLEDevice::getScan(); //create new scan
8179
// Set the callback for when devices are discovered, no duplicates.
82-
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks(), false);
80+
pBLEScan->setScanCallbacks(&scanCallbacks, false);
8381
pBLEScan->setActiveScan(true); // Set active scanning, this will get more data from the advertiser.
8482
pBLEScan->setInterval(97); // How often the scan occurs / switches channels; in milliseconds,
8583
pBLEScan->setWindow(37); // How long to scan during the interval; in milliseconds.
@@ -90,7 +88,7 @@ void loop() {
9088
// If an error occurs that stops the scan, it will be restarted here.
9189
if(pBLEScan->isScanning() == false) {
9290
// Start scan with: duration = 0 seconds(forever), no scan end callback, not a continuation of a previous scan.
93-
pBLEScan->start(0, nullptr, false);
91+
pBLEScan->start(0, false, false);
9492
}
9593

9694
delay(2000);

examples/ESP32/ScanAndDecode/platformio.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
src_dir = .
33

44
[libraries]
5-
arduinojson = [email protected].3
6-
ble = https://github.com/h2zero/NimBLE-Arduino.git#1.3.1
5+
arduinojson = [email protected].5
6+
ble = https://github.com/h2zero/NimBLE-Arduino.git#2.3.4
77

88
[env]
99
lib_extra_dirs = ../../../

0 commit comments

Comments
 (0)