@@ -12,7 +12,7 @@ TheengsDecoder decoder;
1212
1313StaticJsonDocument<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
7371void 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 );
0 commit comments