Skip to content

Commit

Permalink
BLE upgrades (#8724)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Oct 6, 2023
1 parent 02e7fd8 commit 822f252
Show file tree
Hide file tree
Showing 81 changed files with 2,078 additions and 1,732 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
author: chegewara
*/
#ifndef SOC_BLE_50_SUPPORTED
#warning "Not compatible hardware"
#warning "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
#else

#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
author: chegewara
*/

#ifndef CONFIG_BT_BLE_50_FEATURES_SUPPORTED
#error "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
#else

#include <BLEDevice.h>
#include <BLEAdvertising.h>

Expand Down Expand Up @@ -152,3 +156,4 @@ void setup() {
void loop() {
delay(2000);
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
author: chegewara
*/

#ifndef CONFIG_BT_BLE_50_FEATURES_SUPPORTED
#error "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
#else
#include <BLEDevice.h>
#include <BLEAdvertising.h>

Expand Down Expand Up @@ -73,3 +76,4 @@ void setup() {
void loop() {
delay(2000);
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
author: chegewara
*/
#ifndef SOC_BLE_50_SUPPORTED
#warning "Not compatible hardware"
#warning "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
#else
#include <BLEDevice.h>
#include <BLEUtils.h>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
Ported to Arduino ESP32 by Evandro Copercini
Changed to a beacon scanner to report iBeacon, EddystoneURL and EddystoneTLM beacons by beegee-tokyo
Upgraded Eddystone part by Tomas Pilny on Feb 20, 2023
*/

#include <Arduino.h>
Expand Down Expand Up @@ -38,10 +39,10 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks

if (advertisedDevice.haveManufacturerData() == true)
{
std::string strManufacturerData = advertisedDevice.getManufacturerData();
String strManufacturerData = advertisedDevice.getManufacturerData();

uint8_t cManufacturerData[100];
strManufacturerData.copy((char *)cManufacturerData, strManufacturerData.length(), 0);
memcpy(cManufacturerData, strManufacturerData.c_str(), strManufacturerData.length());

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

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

if (payLoad < payLoadEnd) // Eddystone Service Data and respective BLE UUID were found
if (advertisedDevice.getFrameType() == BLE_EDDYSTONE_TLM_FRAME)
{
if (*payLoad == 0x10)
{
Serial.println("Found an EddystoneURL beacon!");
BLEEddystoneURL foundEddyURL = BLEEddystoneURL();
uint8_t URLLen = *(payLoad - 4) - 3; // Get Field Length less 3 bytes (type and UUID)
foundEddyURL.setData(std::string((char*)payLoad, URLLen));
std::string bareURL = foundEddyURL.getURL();
if (bareURL[0] == 0x00)
{
// dumps all bytes in advertising payload
Serial.println("DATA-->");
uint8_t *payLoad = advertisedDevice.getPayload();
for (int idx = 0; idx < payLoadLen; idx++)
{
Serial.printf("0x%02X ", payLoad[idx]);
}
Serial.println("\nInvalid Data");
return;
}

Serial.printf("Found URL: %s\n", foundEddyURL.getURL().c_str());
Serial.printf("Decoded URL: %s\n", foundEddyURL.getDecodedURL().c_str());
Serial.printf("TX power %d\n", foundEddyURL.getPower());
Serial.println("\n");
}
else if (*payLoad == 0x20)
{
Serial.println("Found an EddystoneTLM beacon!");
BLEEddystoneTLM eddystoneTLM;
eddystoneTLM.setData(std::string((char*)payLoad, 14));
Serial.printf("Reported battery voltage: %dmV\n", eddystoneTLM.getVolt());
Serial.printf("Reported temperature: %.2f°C (raw data=0x%04X)\n", eddystoneTLM.getTemp(), eddystoneTLM.getRawTemp());
Serial.printf("Reported advertise count: %lu\n", eddystoneTLM.getCount());
Serial.printf("Reported time since last reboot: %lus\n", eddystoneTLM.getTime());
BLEEddystoneTLM EddystoneTLM(&advertisedDevice);
Serial.printf("Reported battery voltage: %dmV\n", EddystoneTLM.getVolt());
Serial.printf("Reported temperature: %.2f°C (raw data=0x%04X)\n", EddystoneTLM.getTemp(), EddystoneTLM.getRawTemp());
Serial.printf("Reported advertise count: %lu\n", EddystoneTLM.getCount());
Serial.printf("Reported time since last reboot: %lus\n", EddystoneTLM.getTime());
Serial.println("\n");
Serial.print(eddystoneTLM.toString().c_str());
Serial.print(EddystoneTLM.toString().c_str());
Serial.println("\n");
}
}
}
};

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool connectToServer() {

// Read the value of the characteristic.
if(pRemoteCharacteristic->canRead()) {
std::string value = pRemoteCharacteristic->readValue();
String value = pRemoteCharacteristic->readValue();
Serial.print("The characteristic value was: ");
Serial.println(value.c_str());
}
Expand Down
Loading

0 comments on commit 822f252

Please sign in to comment.