8000 BLE upgrades (#8724) · blackhack/arduino-esp32@822f252 · GitHub
[go: up one dir, main page]

Skip to content

Commit 822f252

Browse files
me-no-devPilnyTomaslucasssvaz
authored
BLE upgrades (espressif#8724)
* Renamed library description * Updated Eddystone URL (not complete) * Updated Eddystone URL * Updated Eddystone classes and beacon scanner * Renamed examples - removing prefix BLE_ * Renamed Beacon_Scanner * Updated TLM * Changed std::string to Arduino String * More std::string -> String * Changed String in forgotten file * Changed .data to .c_str * Reverting single String type change * Few more fixes related to the String transition * Fixed URL and Utils error * Added and modified compatibility safeguards for BLE5 examples * Added #include WString.h * Fixed Beacon_Scanner * Remove commented include Co-authored-by: Lucas Saavedra Vaz <lucassvaz@yahoo.com.br> --------- Co-authored-by: Tomas Pilny <tomas.pilny@espressif.com> Co-authored-by: Lucas Saavedra Vaz <lucassvaz@yahoo.com.br>
1 parent 02e7fd8 commit 822f252
  • Some content is hidden

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

    81 files changed

    +2078
    -1732
    lines changed

    libraries/BLE/examples/BLE5_extended_scan/BLE5_extended_scan.ino

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -8,8 +8,9 @@
    88
    author: chegewara
    99
    */
    1010
    #ifndef SOC_BLE_50_SUPPORTED
    11-
    #warning "Not compatible hardware"
    11+
    #warning "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
    1212
    #else
    13+
    1314
    #include <BLEDevice.h>
    1415
    #include <BLEUtils.h>
    1516
    #include <BLEScan.h>

    libraries/BLE/examples/BLE5_multi_advertising/BLE5_multi_advertising.ino

    Lines changed: 5 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -6,6 +6,10 @@
    66
    author: chegewara
    77
    */
    88

    9+
    #ifndef CONFIG_BT_BLE_50_FEATURES_SUPPORTED
    10+
    #error "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
    11+
    #else
    12+
    913
    #include <BLEDevice.h>
    1014
    #include <BLEAdvertising.h>
    1115

    @@ -152,3 +156,4 @@ void setup() {
    152156
    void loop() {
    153157
    delay(2000);
    154158
    }
    159+
    #endif

    libraries/BLE/examples/BLE5_periodic_advertising/BLE5_periodic_advertising.ino

    Lines changed: 4 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -5,6 +5,9 @@
    55
    author: chegewara
    66
    */
    77

    8+
    #ifndef CONFIG_BT_BLE_50_FEATURES_SUPPORTED
    9+
    #error "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
    10+
    #else
    811
    #include <BLEDevice.h>
    912
    #include <BLEAdvertising.h>
    1013

    @@ -73,3 +76,4 @@ void setup() {
    7376
    void loop() {
    7477
    delay(2000);
    7578
    }
    79+
    #endif

    libraries/BLE/examples/BLE5_periodic_sync/BLE5_periodic_sync.ino

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -8,7 +8,7 @@
    88
    author: chegewara
    99
    */
    1010
    #ifndef SOC_BLE_50_SUPPORTED
    11-
    #warning "Not compatible hardware"
    11+
    #warning "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
    1212
    #else
    1313
    #include <BLEDevice.h>
    1414
    #include <BLEUtils.h>

    libraries/BLE/examples/BLE_EddystoneURL_Beacon/BLE_EddystoneURL_Beacon.ino

    Lines changed: 0 additions & 192 deletions
    This file was deleted.

    libraries/BLE/examples/BLE_Beacon_Scanner/BLE_Beacon_Scanner.ino renamed to libraries/BLE/examples/Beacon_Scanner/Beacon_Scanner.ino

    Lines changed: 23 additions & 50 deletions
    Original file line numberDiff line numberDiff line change
    @@ -2,6 +2,7 @@
    22
    Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
    33
    Ported to Arduino ESP32 by Evandro Copercini
    44
    Changed to a beacon scanner to report iBeacon, EddystoneURL and EddystoneTLM beacons by beegee-tokyo
    5+
    Upgraded Eddystone part by Tomas Pilny on Feb 20, 2023
    56
    */
    67

    78
    #include <Arduino.h>
    @@ -38,10 +39,10 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
    3839

    3940
    if (advertisedDevice.haveManufacturerData() == true)
    4041
    {
    41-
    std::string strManufacturerData = advertisedDevice.getManufacturerData();
    42+
    String strManufacturerData = advertisedDevice.getManufacturerData();
    4243

    4344
    uint8_t cManufacturerData[100];
    44-
    strManufacturerData.copy((char *)cManufacturerData, strManufacturerData.length(), 0);
    45+
    memcpy(cManufacturerData, strManufacturerData.c_str(), strManufacturerData.length());
    4546

    4647
    if (strManufacturerData.length() == 25 && cManufacturerData[0] == 0x4C && cManufacturerData[1] == 0x00)
    4748
    {
    @@ -63,62 +64,34 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks
    6364
    }
    6465
    }
    6566

    66-
    uint8_t *payLoad = advertisedDevice.getPayload();
    67-
    // search for Eddystone Service Data in the advertising payload
    68-
    // *payload shall point to eddystone data or to its end when not found
    69-
    const uint8_t serviceDataEddystone[3] = {0x16, 0xAA, 0xFE}; // it has Eddystone BLE UUID
    70-
    const size_t payLoadLen = advertisedDevice.getPayloadLength();
    71-
    uint8_t *payLoadEnd = payLoad + payLoadLen - 1; // address of the end of payLoad space
    72-
    while (payLoad < payLoadEnd) {
    73-
    if (payLoad[1] == serviceDataEddystone[0] && payLoad[2] == serviceDataEddystone[1] && payLoad[3] == serviceDataEddystone[2]) {
    74-
    // found!
    75-
    payLoad += 4;
    76-
    break;
    67+
    if (advertisedDevice.getFrameType() == BLE_EDDYSTONE_URL_FRAME)
    68+
    {
    69+
    Serial.println("Found an EddystoneURL beacon!");
    70+
    BLEEddystoneURL EddystoneURL = BLEEddystoneURL(&advertisedDevice);
    71+
    Serial.printf("URL bytes: 0x");
    72+
    String url = EddystoneURL.getURL();
    73+
    for(auto byte : url){
    74+
    Serial.printf("%02X", byte);
    7775
    }
    78-
    payLoad += *payLoad + 1; // payLoad[0] has the field Length
    76+
    Serial.printf("\n");
    77+
    Serial.printf("Decoded URL: %s\n", EddystoneURL.getDecodedURL().c_str());
    78+
    Serial.printf("EddystoneURL.getDecodedURL(): %s\n", EddystoneURL.getDecodedURL().c_str());
    79+
    Serial.printf("TX power %d (Raw 0x%02X)\n", EddystoneURL.getPower(), EddystoneURL.getPower());
    80+
    Serial.println("\n");
    7981
    }
    8082

    81-
    if (payLoad < payLoadEnd) // Eddystone Service Data and respective BLE UUID were found
    83+
    if (advertisedDevice.getFrameType() == BLE_EDDYSTONE_TLM_FRAME)
    8284
    {
    83-
    if (*payLoad == 0x10)
    84-
    {
    85-
    Serial.println("Found an EddystoneURL beacon!");
    86-
    BLEEddystoneURL foundEddyURL = BLEEddystoneURL();
    87-
    uint8_t URLLen = *(payLoad - 4) - 3; // Get Field Length less 3 bytes (type and UUID)
    88-
    foundEddyURL.setData(std::string((char*)payLoad, URLLen));
    89-
    std::string bareURL = foundEddyURL.getURL();
    90-
    if (bareURL[0] == 0x00)
    91-
    {
    92-
    // dumps all bytes in advertising payload
    93-
    Serial.println("DATA-->");
    94-
    uint8_t *payLoad = advertisedDevice.getPayload();
    95-
    for (int idx = 0; idx < payLoadLen; idx++)
    96-
    {
    97-
    Serial.printf("0x%02X ", payLoad[idx]);
    98-
    }
    99-
    Serial.println("\nInvalid Data");
    100-
    return;
    101-
    }
    102-
    103-
    Serial.printf("Found URL: %s\n", foundEddyURL.getURL().c_str());
    104-
    Serial.printf("Decoded URL: %s\n", foundEddyURL.getDecodedURL().c_str());
    105-
    Serial.printf("TX power %d\n", foundEddyURL.getPower());
    106-
    Serial.println("\n");
    107-
    }
    108-
    else if (*payLoad == 0x20)
    109 10000 -
    {
    11085
    Serial.println("Found an EddystoneTLM beacon!");
    111-
    BLEEddystoneTLM eddystoneTLM;
    112-
    eddystoneTLM.setData(std::string((char*)payLoad, 14));
    113-
    Serial.printf("Reported battery voltage: %dmV\n", eddystoneTLM.getVolt());
    114-
    Serial.printf("Reported temperature: %.2f°C (raw data=0x%04X)\n", eddystoneTLM.getTemp(), eddystoneTLM.getRawTemp());
    115-
    Serial.printf("Reported advertise count: %lu\n", eddystoneTLM.getCount());
    116-
    Serial.printf("Reported time since last reboot: %lus\n", eddystoneTLM.getTime());
    86+
    BLEEddystoneTLM EddystoneTLM(&advertisedDevice);
    87+
    Serial.printf("Reported battery voltage: %dmV\n", EddystoneTLM.getVolt());
    88+
    Serial.printf("Reported temperature: %.2f°C (raw data=0x%04X)\n", EddystoneTLM.getTemp(), EddystoneTLM.getRawTemp());
    89+
    Serial.printf("Reported advertise count: %lu\n", EddystoneTLM.getCount());
    90+
    Serial.printf("Reported time since last reboot: %lus\n", EddystoneTLM.getTime());
    11791
    Serial.println("\n");
    118-
    Serial.print(eddystoneTLM.toString().c_str());
    92+
    Serial.print(EddystoneTLM.toString().c_str());
    11993
    Serial.println("\n");
    12094
    }
    121-
    }
    12295
    }
    12396
    };
    12497

    libraries/BLE/examples/BLE_client/BLE_client.ino renamed to libraries/BLE/examples/Client/Client.ino

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -80,7 +80,7 @@ bool connectToServer() {
    8080

    8181
    // Read the value of the characteristic.
    8282
    if(pRemoteCharacteristic->canRead()) {
    83-
    std::string value = pRemoteCharacteristic->readValue();
    83+
    String value = pRemoteCharacteristic->readValue();
    8484
    Serial.print("The characteristic value was: ");
    8585
    Serial.println(value.c_str());
    8686
    }

    0 commit comments

    Comments
     (0)
    0