new lib BLE, чуть меньше расходует памяти

This commit is contained in:
Mit4el
2025-01-13 19:19:02 +03:00
parent 130dd038c6
commit a6e4617b30
6 changed files with 73 additions and 52 deletions

View File

@@ -181,7 +181,7 @@ void scanEndedCB(NimBLEScanResults results)
//#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
//class BleScan : public IoTItem, NimBLEScanCallbacks
//#else
class BleScan : public IoTItem, BLEAdvertisedDeviceCallbacks
class BleScan : public IoTItem, BLEAdvertisedDeviceCallbacks //NimBLEScanCallbacks
//#endif
{
private:
@@ -218,13 +218,20 @@ public:
}
if (advertisedDevice->haveManufacturerData())
{
#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
char *manufacturerdata = BLEUtils::buildHexData(NULL, (uint8_t *)advertisedDevice->getManufacturerData().data(), advertisedDevice->getManufacturerData().length());
BLEdata["manufacturerdata"] = manufacturerdata;
free(manufacturerdata);
}
#if !defined (esp32c6_4mb) && !defined (esp32c6_8mb)
if (advertisedDevice->haveRSSI())
#else
std::string manufacturerdata = NimBLEUtils::dataToHexString((uint8_t *)advertisedDevice->getManufacturerData().data(), advertisedDevice->getManufacturerData().length());
#endif
BLEdata["manufacturerdata"] = manufacturerdata;
#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
free(manufacturerdata);
#endif
}
//#if !defined (esp32c6_4mb) && !defined (esp32c6_8mb) //&& !defined (esp32_4mb3f)
// if (advertisedDevice->haveRSSI())
//#endif
BLEdata["rssi"] = (int)advertisedDevice->getRSSI();
if (advertisedDevice->haveTXPower())
BLEdata["txpower"] = (int8_t)advertisedDevice->getTXPower();
@@ -302,11 +309,11 @@ public:
BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); // create new scan
#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
//#if defined (esp32c6_4mb) || defined (esp32c6_8mb) //|| defined (esp32_4mb3f)
pBLEScan->setScanCallbacks(this);
#else
pBLEScan->setAdvertisedDeviceCallbacks(this);
#endif
//#else
// pBLEScan->setAdvertisedDeviceCallbacks(this);
//#endif
pBLEScan->setActiveScan(false); // active scan uses more power, but get results faster
pBLEScan->setInterval(100);
pBLEScan->setWindow(99); // less or equal setInterval value
@@ -321,11 +328,11 @@ public:
if (_scanDuration > 0)
{
SerialPrint("i", F("BLE"), "Start Scanning...");
#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
//#if defined (esp32c6_4mb) || defined (esp32c6_8mb) //|| defined (esp32_4mb3f)
pBLEScan->start(_scanDuration, false);
#else
pBLEScan->start(_scanDuration, scanEndedCB, false);
#endif
//#else
// pBLEScan->start(_scanDuration, scanEndedCB, false);
//#endif
}
}
}

View File

@@ -65,13 +65,13 @@
"defActive": false,
"usedLibs": {
"esp32c6_4mb": [
"https://github.com/h2zero/NimBLE-Arduino#c6-build"
"https://github.com/Mit4el/NimBLE-Arduino.git#c6-build"
],
"esp32c6_8mb": [
"https://github.com/h2zero/NimBLE-Arduino#c6-build"
"https://github.com/Mit4el/NimBLE-Arduino.git#c6-build"
],
"esp32_4mb3f": [
"https://github.com/Mit4el/NimBLE-Arduino.git"
"esp32*": [
"https://github.com/Mit4el/NimBLE-Arduino.git#release/2.2"
],
"esp32s2_4mb": [
"exclude"

View File

@@ -181,7 +181,7 @@ void scanEndedCB(NimBLEScanResults results)
//#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
//class BleScan : public IoTItem, NimBLEScanCallbacks
//#else
class BleScan : public IoTItem, BLEAdvertisedDeviceCallbacks
class BleScan : public IoTItem, BLEAdvertisedDeviceCallbacks //NimBLEScanCallbacks
//#endif
{
private:
@@ -218,13 +218,20 @@ public:
}
if (advertisedDevice->haveManufacturerData())
{
#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
char *manufacturerdata = BLEUtils::buildHexData(NULL, (uint8_t *)advertisedDevice->getManufacturerData().data(), advertisedDevice->getManufacturerData().length());
BLEdata["manufacturerdata"] = manufacturerdata;
free(manufacturerdata);
}
#if !defined (esp32c6_4mb) && !defined (esp32c6_8mb)
if (advertisedDevice->haveRSSI())
#else
std::string manufacturerdata = NimBLEUtils::dataToHexString((uint8_t *)advertisedDevice->getManufacturerData().data(), advertisedDevice->getManufacturerData().length());
#endif
BLEdata["manufacturerdata"] = manufacturerdata;
#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
free(manufacturerdata);
#endif
}
//#if !defined (esp32c6_4mb) && !defined (esp32c6_8mb) //&& !defined (esp32_4mb3f)
// if (advertisedDevice->haveRSSI())
//#endif
BLEdata["rssi"] = (int)advertisedDevice->getRSSI();
if (advertisedDevice->haveTXPower())
BLEdata["txpower"] = (int8_t)advertisedDevice->getTXPower();
@@ -302,11 +309,11 @@ public:
BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); // create new scan
#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
//#if defined (esp32c6_4mb) || defined (esp32c6_8mb) //|| defined (esp32_4mb3f)
pBLEScan->setScanCallbacks(this);
#else
pBLEScan->setAdvertisedDeviceCallbacks(this);
#endif
//#else
// pBLEScan->setAdvertisedDeviceCallbacks(this);
//#endif
pBLEScan->setActiveScan(false); // active scan uses more power, but get results faster
pBLEScan->setInterval(100);
pBLEScan->setWindow(99); // less or equal setInterval value
@@ -321,11 +328,11 @@ public:
if (_scanDuration > 0)
{
SerialPrint("i", F("BLE"), "Start Scanning...");
#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
//#if defined (esp32c6_4mb) || defined (esp32c6_8mb) //|| defined (esp32_4mb3f)
pBLEScan->start(_scanDuration, false);
#else
pBLEScan->start(_scanDuration, scanEndedCB, false);
#endif
//#else
// pBLEScan->start(_scanDuration, scanEndedCB, false);
//#endif
}
}
}
@@ -335,13 +342,13 @@ public:
//=======================================================================================================
void *getAPI_Ble_part1(String subtype, String param)
void *getAPI_Ble(String subtype, String param)
{
if (subtype == F("BleScan_p1"))
if (subtype == F("BleScan"))
{
return new BleScan(param);
}
else if (subtype == F("BleSens_p1"))
else if (subtype == F("BleSens"))
{
return new BleSens(param);
}

View File

@@ -65,13 +65,13 @@
"defActive": false,
"usedLibs": {
"esp32c6_4mb": [
"https://github.com/h2zero/NimBLE-Arduino#c6-build"
"https://github.com/Mit4el/NimBLE-Arduino.git#c6-build"
],
"esp32c6_8mb": [
"https://github.com/h2zero/NimBLE-Arduino#c6-build"
"https://github.com/Mit4el/NimBLE-Arduino.git#c6-build"
],
"esp32*": [
"https://github.com/Mit4el/NimBLE-Arduino.git"
"https://github.com/Mit4el/NimBLE-Arduino.git#release/2.2"
],
"esp32s2_4mb": [
"exclude"

View File

@@ -181,7 +181,7 @@ void scanEndedCB(NimBLEScanResults results)
//#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
//class BleScan : public IoTItem, NimBLEScanCallbacks
//#else
class BleScan : public IoTItem, BLEAdvertisedDeviceCallbacks
class BleScan : public IoTItem, BLEAdvertisedDeviceCallbacks //NimBLEScanCallbacks
//#endif
{
private:
@@ -218,13 +218,20 @@ public:
}
if (advertisedDevice->haveManufacturerData())
{
#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
char *manufacturerdata = BLEUtils::buildHexData(NULL, (uint8_t *)advertisedDevice->getManufacturerData().data(), advertisedDevice->getManufacturerData().length());
BLEdata["manufacturerdata"] = manufacturerdata;
free(manufacturerdata);
}
#if !defined (esp32c6_4mb) && !defined (esp32c6_8mb)
if (advertisedDevice->haveRSSI())
#else
std::string manufacturerdata = NimBLEUtils::dataToHexString((uint8_t *)advertisedDevice->getManufacturerData().data(), advertisedDevice->getManufacturerData().length());
#endif
BLEdata["manufacturerdata"] = manufacturerdata;
#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
free(manufacturerdata);
#endif
}
//#if !defined (esp32c6_4mb) && !defined (esp32c6_8mb) //&& !defined (esp32_4mb3f)
// if (advertisedDevice->haveRSSI())
//#endif
BLEdata["rssi"] = (int)advertisedDevice->getRSSI();
if (advertisedDevice->haveTXPower())
BLEdata["txpower"] = (int8_t)advertisedDevice->getTXPower();
@@ -302,11 +309,11 @@ public:
BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); // create new scan
#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
//#if defined (esp32c6_4mb) || defined (esp32c6_8mb) //|| defined (esp32_4mb3f)
pBLEScan->setScanCallbacks(this);
#else
pBLEScan->setAdvertisedDeviceCallbacks(this);
#endif
//#else
// pBLEScan->setAdvertisedDeviceCallbacks(this);
//#endif
pBLEScan->setActiveScan(false); // active scan uses more power, but get results faster
pBLEScan->setInterval(100);
pBLEScan->setWindow(99); // less or equal setInterval value
@@ -321,11 +328,11 @@ public:
if (_scanDuration > 0)
{
SerialPrint("i", F("BLE"), "Start Scanning...");
#if defined (esp32c6_4mb) || defined (esp32c6_8mb)
//#if defined (esp32c6_4mb) || defined (esp32c6_8mb) //|| defined (esp32_4mb3f)
pBLEScan->start(_scanDuration, false);
#else
pBLEScan->start(_scanDuration, scanEndedCB, false);
#endif
//#else
// pBLEScan->start(_scanDuration, scanEndedCB, false);
//#endif
}
}
}
@@ -335,13 +342,13 @@ public:
//=======================================================================================================
void *getAPI_Ble_part2(String subtype, String param)
void *getAPI_Ble(String subtype, String param)
{
if (subtype == F("BleScan_p2"))
if (subtype == F("BleScan"))
{
return new BleScan(param);
}
else if (subtype == F("BleSens_p2"))
else if (subtype == F("BleSens"))
{
return new BleSens(param);
}

View File

@@ -65,13 +65,13 @@
"defActive": false,
"usedLibs": {
"esp32c6_4mb": [
"https://github.com/h2zero/NimBLE-Arduino#c6-build"
"https://github.com/Mit4el/NimBLE-Arduino.git#c6-build"
],
"esp32c6_8mb": [
"https://github.com/h2zero/NimBLE-Arduino#c6-build"
"https://github.com/Mit4el/NimBLE-Arduino.git#c6-build"
],
"esp32*": [
"https://github.com/Mit4el/NimBLE-Arduino.git"
"https://github.com/Mit4el/NimBLE-Arduino.git#release/2.2"
],
"esp32s2_4mb": [
"exclude"