From 7685c3134b0e3fc4d61cd7bd69aa5b3078c14e0c Mon Sep 17 00:00:00 2001 From: h2zero Date: Fri, 29 Nov 2024 12:01:07 -0700 Subject: [PATCH] [BREAKING] Remove Eddystone URL Removed Eddystone URL as it has been shutdown by google since 2021. --- .../BLE_EddystoneURL_Beacon.ino | 186 ---------------- .../BLE_EddystoneURL_Beacon.md | 14 -- src/NimBLEEddystoneURL.cpp | 208 ------------------ src/NimBLEEddystoneURL.h | 52 ----- 4 files changed, 460 deletions(-) delete mode 100644 examples/BLE_EddystoneURL_Beacon/BLE_EddystoneURL_Beacon.ino delete mode 100644 examples/BLE_EddystoneURL_Beacon/BLE_EddystoneURL_Beacon.md delete mode 100644 src/NimBLEEddystoneURL.cpp delete mode 100644 src/NimBLEEddystoneURL.h diff --git a/examples/BLE_EddystoneURL_Beacon/BLE_EddystoneURL_Beacon.ino b/examples/BLE_EddystoneURL_Beacon/BLE_EddystoneURL_Beacon.ino deleted file mode 100644 index 0648b357..00000000 --- a/examples/BLE_EddystoneURL_Beacon/BLE_EddystoneURL_Beacon.ino +++ /dev/null @@ -1,186 +0,0 @@ -/* - EddystoneURL beacon for NimBLE by BeeGee - EddystoneURL frame specification https://github.com/google/eddystone/blob/master/eddystone-url/README.md - -*/ - -/* - Create a BLE server that will send periodic Eddystone URL frames. - The design of creating the BLE server is: - 1. Create a BLE Server - 2. Create advertising data - 3. Start advertising. - 4. wait - 5. Stop advertising. - 6. deep sleep - -*/ - -#include "NimBLEDevice.h" -#include "NimBLEBeacon.h" -#include "NimBLEEddystoneURL.h" - -#include "sys/time.h" -#include "esp_sleep.h" - -#define GPIO_DEEP_SLEEP_DURATION 10 // sleep x seconds and then wake up - -// UUID 1 128-Bit (may use linux tool uuidgen or random numbers via https://www.uuidgenerator.net/) -#define BEACON_UUID "8ec76ea3-6668-48da-9866-75be8bc86f4d" - -RTC_DATA_ATTR static time_t last; // remember last boot in RTC Memory -RTC_DATA_ATTR static uint32_t bootcount; // remember number of boots in RTC Memory - -BLEAdvertising *pAdvertising; -struct timeval now; - -static const char *eddystone_url_prefix_subs[] = { - "http://www.", - "https://www.", - "http://", - "https://", - "urn:uuid:", - NULL -}; - -static const char *eddystone_url_suffix_subs[] = { - ".com/", - ".org/", - ".edu/", - ".net/", - ".info/", - ".biz/", - ".gov/", - ".com", - ".org", - ".edu", - ".net", - ".info", - ".biz", - ".gov", - NULL -}; - -static int string_begin_with(const char *str, const char *prefix) -{ - int prefix_len = strlen(prefix); - if (strncmp(prefix, str, prefix_len) == 0) - { - return prefix_len; - } - return 0; -} - -void setBeacon() -{ - BLEAdvertisementData oAdvertisementData = BLEAdvertisementData(); - BLEAdvertisementData oScanResponseData = BLEAdvertisementData(); - - const char url[] = "https://d.giesecke.tk"; - - int scheme_len, ext_len = 1, i, idx, url_idx; - char *ret_data; - int url_len = strlen(url); - - ret_data = (char *)calloc(1, url_len + 13); - - ret_data[0] = 2; // Len - ret_data[1] = 0x01; // Type Flags - ret_data[2] = 0x06; // GENERAL_DISC_MODE 0x02 | BR_EDR_NOT_SUPPORTED 0x04 - ret_data[3] = 3; // Len - ret_data[4] = 0x03; // Type 16-Bit UUID - ret_data[5] = 0xAA; // Eddystone UUID 2 -> 0xFEAA LSB - ret_data[6] = 0xFE; // Eddystone UUID 1 MSB - ret_data[7] = 19; // Length of Beacon Data - ret_data[8] = 0x16; // Type Service Data - ret_data[9] = 0xAA; // Eddystone UUID 2 -> 0xFEAA LSB - ret_data[10] = 0xFE; // Eddystone UUID 1 MSB - ret_data[11] = 0x10; // Eddystone Frame Type - ret_data[12] = 0xF4; // Beacons TX power at 0m - - i = 0, idx = 13, url_idx = 0; - - //replace prefix - scheme_len = 0; - while (eddystone_url_prefix_subs[i] != NULL) - { - if ((scheme_len = string_begin_with(url, eddystone_url_prefix_subs[i])) > 0) - { - ret_data[idx] = i; - idx++; - url_idx += scheme_len; - break; - } - i++; - } - while (url_idx < url_len) - { - i = 0; - ret_data[idx] = url[url_idx]; - ext_len = 1; - while (eddystone_url_suffix_subs[i] != NULL) - { - if ((ext_len = string_begin_with(&url[url_idx], eddystone_url_suffix_subs[i])) > 0) - { - ret_data[idx] = i; - break; - } - else - { - ext_len = 1; //inc 1 - } - i++; - } - url_idx += ext_len; - idx++; - } - ret_data[7] = idx - 8; - - Serial.printf("struct size %d url size %d reported len %d\n", - url_len + 13, - url_len, ret_data[7]); - - Serial.printf("URL in data %s\n", &ret_data[13]); - - std::string eddyStoneData(ret_data); - - oAdvertisementData.addData(eddyStoneData); - oScanResponseData.setName("MeBeacon"); - pAdvertising->setAdvertisementData(oAdvertisementData); - pAdvertising->setScanResponseData(oScanResponseData); -} - -void setup() -{ - - Serial.begin(115200); - gettimeofday(&now, NULL); - - Serial.printf("start ESP32 %d\n", bootcount++); - - Serial.printf("deep sleep (%lds since last reset, %lds since last boot)\n", now.tv_sec, now.tv_sec - last); - - last = now.tv_sec; - - // Create the BLE Device - BLEDevice::init("MeBeacon"); - - BLEDevice::setPower(ESP_PWR_LVL_N12); - - pAdvertising = BLEDevice::getAdvertising(); - pAdvertising->enableScanResponse(true); - - setBeacon(); - // Start advertising - pAdvertising->start(); - Serial.println("Advertizing started..."); - delay(10000); - pAdvertising->stop(); - Serial.printf("enter deep sleep\n"); - esp_deep_sleep(1000000LL * GPIO_DEEP_SLEEP_DURATION); - Serial.printf("in deep sleep\n"); -} - -void loop() -{ -} diff --git a/examples/BLE_EddystoneURL_Beacon/BLE_EddystoneURL_Beacon.md b/examples/BLE_EddystoneURL_Beacon/BLE_EddystoneURL_Beacon.md deleted file mode 100644 index 2baf1cc5..00000000 --- a/examples/BLE_EddystoneURL_Beacon/BLE_EddystoneURL_Beacon.md +++ /dev/null @@ -1,14 +0,0 @@ -## Eddystone URL beacon -EddystoneURL beacon by BeeGee based on -[pcbreflux ESP32 Eddystone URL deepsleep](https://github.com/pcbreflux/espressif/tree/master/esp32/arduino/sketchbook/ESP32_Eddystone_URL_deepsleep) - -[EddystoneURL frame specification](https://github.com/google/eddystone/blob/master/eddystone-url/README.md) - - Create a BLE server that will send periodic Eddystone URL frames. - The design of creating the BLE server is: - 1. Create a BLE Server - 2. Create advertising data - 3. Start advertising. - 4. wait - 5. Stop advertising. - 6. deep sleep diff --git a/src/NimBLEEddystoneURL.cpp b/src/NimBLEEddystoneURL.cpp deleted file mode 100644 index 73fcb33d..00000000 --- a/src/NimBLEEddystoneURL.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* - * NimBLEEddystoneURL.cpp - * - * Created: on March 15 2020 - * Author H2zero - * - * Originally: - * - * BLEEddystoneURL.cpp - * - * Created on: Mar 12, 2018 - * Author: pcbreflux - */ -#include "nimconfig.h" -#if defined(CONFIG_BT_ENABLED) - -#include "NimBLEEddystoneURL.h" -#include "NimBLELog.h" - -#include - -static const char LOG_TAG[] = "NimBLEEddystoneURL"; - - -/** - * @brief Construct a default EddystoneURL beacon object. - */ -NimBLEEddystoneURL::NimBLEEddystoneURL() { - beaconUUID = 0xFEAA; - lengthURL = 0; - m_eddystoneData.frameType = EDDYSTONE_URL_FRAME_TYPE; - m_eddystoneData.advertisedTxPower = 0; - memset(m_eddystoneData.url, 0, sizeof(m_eddystoneData.url)); -} // BLEEddystoneURL - - -/** - * @brief Retrieve the data that is being advertised. - * @return The advertised data. - */ -std::string NimBLEEddystoneURL::getData() { - return std::string((char*) &m_eddystoneData, sizeof(m_eddystoneData)); -} // getData - - -/** - * @brief Get the UUID being advertised. - * @return The UUID advertised. - */ -NimBLEUUID NimBLEEddystoneURL::getUUID() { - return NimBLEUUID(beaconUUID); -} // getUUID - - -/** - * @brief Get the transmit power being advertised. - * @return The transmit power. - */ -int8_t NimBLEEddystoneURL::getPower() { - return m_eddystoneData.advertisedTxPower; -} // getPower - - -/** - * @brief Get the raw URL being advertised. - * @return The raw URL. - */ -std::string NimBLEEddystoneURL::getURL() { - return std::string((char*) &m_eddystoneData.url, sizeof(m_eddystoneData.url)); -} // getURL - - -/** - * @brief Get the full URL being advertised. - * @return The full URL. - */ -std::string NimBLEEddystoneURL::getDecodedURL() { - std::string decodedURL = ""; - - switch (m_eddystoneData.url[0]) { - case 0x00: - decodedURL += "http://www."; - break; - case 0x01: - decodedURL += "https://www."; - break; - case 0x02: - decodedURL += "http://"; - break; - case 0x03: - decodedURL += "https://"; - break; - default: - decodedURL += m_eddystoneData.url[0]; - } - - for (int i = 1; i < lengthURL; i++) { - if (m_eddystoneData.url[i] > 33 && m_eddystoneData.url[i] < 127) { - decodedURL += m_eddystoneData.url[i]; - } else { - switch (m_eddystoneData.url[i]) { - case 0x00: - decodedURL += ".com/"; - break; - case 0x01: - decodedURL += ".org/"; - break; - case 0x02: - decodedURL += ".edu/"; - break; - case 0x03: - decodedURL += ".net/"; - break; - case 0x04: - decodedURL += ".info/"; - break; - case 0x05: - decodedURL += ".biz/"; - break; - case 0x06: - decodedURL += ".gov/"; - break; - case 0x07: - decodedURL += ".com"; - break; - case 0x08: - decodedURL += ".org"; - break; - case 0x09: - decodedURL += ".edu"; - break; - case 0x0A: - decodedURL += ".net"; - break; - case 0x0B: - decodedURL += ".info"; - break; - case 0x0C: - decodedURL += ".biz"; - break; - case 0x0D: - decodedURL += ".gov"; - break; - default: - break; - } - } - } - return decodedURL; -} // getDecodedURL - - - -/** - * @brief Set the raw data for the beacon advertisement. - * @param [in] data The raw data to advertise. - */ -void NimBLEEddystoneURL::setData(const std::string &data) { - if (data.length() > sizeof(m_eddystoneData)) { - NIMBLE_LOGE(LOG_TAG, "Unable to set the data ... length passed in was %d and max expected %d", - data.length(), sizeof(m_eddystoneData)); - return; - } - memset(&m_eddystoneData, 0, sizeof(m_eddystoneData)); - memcpy(&m_eddystoneData, data.data(), data.length()); - lengthURL = data.length() - (sizeof(m_eddystoneData) - sizeof(m_eddystoneData.url)); -} // setData - - -/** - * @brief Set the UUID to advertise. - * @param [in] l_uuid The UUID. - */ -void NimBLEEddystoneURL::setUUID(const NimBLEUUID &l_uuid) { - if (l_uuid.bitSize() != 16) { - NIMBLE_LOGE(LOG_TAG, "UUID must be 16 bits"); - return; - } - beaconUUID = *reinterpret_cast(l_uuid.getValue()); -} // setUUID - - -/** - * @brief Set the transmit power to advertise. - * @param [in] advertisedTxPower The transmit power level. - */ -void NimBLEEddystoneURL::setPower(int8_t advertisedTxPower) { - m_eddystoneData.advertisedTxPower = advertisedTxPower; -} // setPower - - -/** - * @brief Set the URL to advertise. - * @param [in] url The URL. - */ -void NimBLEEddystoneURL::setURL(const std::string &url) { - if (url.length() > sizeof(m_eddystoneData.url)) { - NIMBLE_LOGE(LOG_TAG, "Unable to set the url ... length passed in was %d and max expected %d", - url.length(), sizeof(m_eddystoneData.url)); - return; - } - memset(m_eddystoneData.url, 0, sizeof(m_eddystoneData.url)); - memcpy(m_eddystoneData.url, url.data(), url.length()); - lengthURL = url.length(); -} // setURL - - -#endif diff --git a/src/NimBLEEddystoneURL.h b/src/NimBLEEddystoneURL.h deleted file mode 100644 index 9c5f37f8..00000000 --- a/src/NimBLEEddystoneURL.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * NimBLEEddystoneURL.h - * - * Created: on March 15 2020 - * Author H2zero - * - * Originally: - * - * BLEEddystoneURL.h - * - * Created on: Mar 12, 2018 - * Author: pcbreflux - */ - -#ifndef _NIMBLEEddystoneURL_H_ -#define _NIMBLEEddystoneURL_H_ -#include "NimBLEUUID.h" - -#include - -#define EDDYSTONE_URL_FRAME_TYPE 0x10 - -/** - * @brief Representation of a beacon. - * See: - * * https://github.com/google/eddystone - */ -class NimBLEEddystoneURL { -public: - NimBLEEddystoneURL(); - std::string getData(); - NimBLEUUID getUUID(); - int8_t getPower(); - std::string getURL(); - std::string getDecodedURL(); - void setData(const std::string &data); - void setUUID(const NimBLEUUID &l_uuid); - void setPower(int8_t advertisedTxPower); - void setURL(const std::string &url); - -private: - uint16_t beaconUUID; - uint8_t lengthURL; - struct { - uint8_t frameType; - int8_t advertisedTxPower; - uint8_t url[16]; - } __attribute__((packed)) m_eddystoneData; - -}; // NIMBLEEddystoneURL - -#endif /* _NIMBLEEddystoneURL_H_ */