Skip to content

Commit 9d10331

Browse files
committed
change BLE lib to watch cust old
1 parent caef400 commit 9d10331

Some content is hidden

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

51 files changed

+244
-844
lines changed

libraries/BLE/examples/BLE_client/BLE_client.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ bool connectToServer() {
5454
// Connect to the remove BLE Server.
5555
pClient->connect(myDevice); // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private)
5656
Serial.println(" - Connected to server");
57-
pClient->setMTU(517); //set client to request maximum MTU from server (default is 23 otherwise)
58-
57+
5958
// Obtain a reference to the service we are after in the remote BLE server.
6059
BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
6160
if (pRemoteService == nullptr) {

libraries/BLE/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ESP32 BLE Arduino
2-
version=2.0.0
2+
version=1.0.1
33
author=Neil Kolban <kolban1@kolban.com>
44
maintainer=Dariusz Krempa <esp32@esp32.eu.org>
55
sentence=BLE functions for ESP32

libraries/BLE/src/BLE2902.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
1111
*/
1212
#include "sdkconfig.h"
13-
#if defined(CONFIG_BLUEDROID_ENABLED)
13+
#if defined(CONFIG_BT_ENABLED)
1414

1515
#include "BLE2902.h"
1616

libraries/BLE/src/BLE2902.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef COMPONENTS_CPP_UTILS_BLE2902_H_
99
#define COMPONENTS_CPP_UTILS_BLE2902_H_
1010
#include "sdkconfig.h"
11-
#if defined(CONFIG_BLUEDROID_ENABLED)
11+
#if defined(CONFIG_BT_ENABLED)
1212

1313
#include "BLEDescriptor.h"
1414

@@ -30,5 +30,5 @@ class BLE2902: public BLEDescriptor {
3030

3131
}; // BLE2902
3232

33-
#endif /* CONFIG_BLUEDROID_ENABLED */
33+
#endif /* CONFIG_BT_ENABLED */
3434
#endif /* COMPONENTS_CPP_UTILS_BLE2902_H_ */

libraries/BLE/src/BLE2904.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.characteristic_presentation_format.xml
1111
*/
1212
#include "sdkconfig.h"
13-
#if defined(CONFIG_BLUEDROID_ENABLED)
13+
#if defined(CONFIG_BT_ENABLED)
1414

1515
#include "BLE2904.h"
1616

libraries/BLE/src/BLE2904.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef COMPONENTS_CPP_UTILS_BLE2904_H_
99
#define COMPONENTS_CPP_UTILS_BLE2904_H_
1010
#include "sdkconfig.h"
11-
#if defined(CONFIG_BLUEDROID_ENABLED)
11+
#if defined(CONFIG_BT_ENABLED)
1212

1313
#include "BLEDescriptor.h"
1414

@@ -70,5 +70,5 @@ class BLE2904: public BLEDescriptor {
7070
BLE2904_Data m_data;
7171
}; // BLE2904
7272

73-
#endif /* CONFIG_BLUEDROID_ENABLED */
73+
#endif /* CONFIG_BT_ENABLED */
7474
#endif /* COMPONENTS_CPP_UTILS_BLE2904_H_ */

libraries/BLE/src/BLEAddress.cpp

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Author: kolban
66
*/
77
#include "sdkconfig.h"
8-
#if defined(CONFIG_BLUEDROID_ENABLED)
8+
#if defined(CONFIG_BT_ENABLED)
99

1010
#include "BLEAddress.h"
1111
#include <string>
@@ -59,37 +59,14 @@ BLEAddress::BLEAddress(std::string stringAddress) {
5959
* @return True if the addresses are equal.
6060
*/
6161
bool BLEAddress::equals(BLEAddress otherAddress) {
62-
return memcmp(otherAddress.getNative(), m_address, ESP_BD_ADDR_LEN) == 0;
62+
return memcmp(otherAddress.getNative(), m_address, 6) == 0;
6363
} // equals
6464

65-
bool BLEAddress::operator==(const BLEAddress& otherAddress) const {
66-
return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) == 0;
67-
}
68-
69-
bool BLEAddress::operator!=(const BLEAddress& otherAddress) const {
70-
return !(*this == otherAddress);
71-
}
72-
73-
bool BLEAddress::operator<(const BLEAddress& otherAddress) const {
74-
return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) < 0;
75-
}
76-
77-
bool BLEAddress::operator<=(const BLEAddress& otherAddress) const {
78-
return !(*this > otherAddress);
79-
}
80-
81-
bool BLEAddress::operator>=(const BLEAddress& otherAddress) const {
82-
return !(*this < otherAddress);
83-
}
84-
85-
bool BLEAddress::operator>(const BLEAddress& otherAddress) const {
86-
return memcmp(otherAddress.m_address, m_address, ESP_BD_ADDR_LEN) > 0;
87-
}
8865

8966
/**
9067
* @brief Return the native representation of the address.
9168
* @return The native representation of the address.
92-
*/
69+
*/
9370
esp_bd_addr_t *BLEAddress::getNative() {
9471
return &m_address;
9572
} // getNative

libraries/BLE/src/BLEAddress.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef COMPONENTS_CPP_UTILS_BLEADDRESS_H_
99
#define COMPONENTS_CPP_UTILS_BLEADDRESS_H_
1010
#include "sdkconfig.h"
11-
#if defined(CONFIG_BLUEDROID_ENABLED)
11+
#if defined(CONFIG_BT_ENABLED)
1212
#include <esp_gap_ble_api.h> // ESP32 BLE
1313
#include <string>
1414

@@ -23,18 +23,12 @@ class BLEAddress {
2323
BLEAddress(esp_bd_addr_t address);
2424
BLEAddress(std::string stringAddress);
2525
bool equals(BLEAddress otherAddress);
26-
bool operator==(const BLEAddress& otherAddress) const;
27-
bool operator!=(const BLEAddress& otherAddress) const;
28-
bool operator<(const BLEAddress& otherAddress) const;
29-
bool operator<=(const BLEAddress& otherAddress) const;
30-
bool operator>(const BLEAddress& otherAddress) const;
31-
bool operator>=(const BLEAddress& otherAddress) const;
3226
esp_bd_addr_t* getNative();
3327
std::string toString();
3428

3529
private:
3630
esp_bd_addr_t m_address;
3731
};
3832

39-
#endif /* CONFIG_BLUEDROID_ENABLED */
33+
#endif /* CONFIG_BT_ENABLED */
4034
#endif /* COMPONENTS_CPP_UTILS_BLEADDRESS_H_ */

libraries/BLE/src/BLEAdvertisedDevice.cpp

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Author: kolban
1313
*/
1414
#include "sdkconfig.h"
15-
#if defined(CONFIG_BLUEDROID_ENABLED)
15+
#if defined(CONFIG_BT_ENABLED)
1616
#include <sstream>
1717
#include "BLEAdvertisedDevice.h"
1818
#include "BLEUtils.h"
@@ -25,7 +25,6 @@ BLEAdvertisedDevice::BLEAdvertisedDevice() {
2525
m_manufacturerData = "";
2626
m_name = "";
2727
m_rssi = -9999;
28-
m_serviceUUIDs = {};
2928
m_serviceData = {};
3029
m_serviceDataUUIDs = {};
3130
m_txPower = 0;
@@ -35,6 +34,8 @@ BLEAdvertisedDevice::BLEAdvertisedDevice() {
3534
m_haveManufacturerData = false;
3635
m_haveName = false;
3736
m_haveRSSI = false;
37+
m_haveServiceData = false;
38+
m_haveServiceUUID = false;
3839
m_haveTXPower = false;
3940

4041
} // BLEAdvertisedDevice
@@ -106,15 +107,19 @@ BLEScan* BLEAdvertisedDevice::getScan() {
106107
* @return Number of service data discovered.
107108
*/
108109
int BLEAdvertisedDevice::getServiceDataCount() {
109-
return m_serviceData.size();
110+
if (m_haveServiceData)
111+
return m_serviceData.size();
112+
else
113+
return 0;
114+
110115
} //getServiceDataCount
111116

112117
/**
113118
* @brief Get the service data.
114119
* @return The ServiceData of the advertised device.
115120
*/
116121
std::string BLEAdvertisedDevice::getServiceData() {
117-
return m_serviceData.empty() ? std::string() : m_serviceData.front();
122+
return m_serviceData[0];
118123
} //getServiceData
119124

120125
/**
@@ -125,20 +130,12 @@ std::string BLEAdvertisedDevice::getServiceData(int i) {
125130
return m_serviceData[i];
126131
} //getServiceData
127132

128-
/**
129-
* @brief Get the number of service data UUIDs.
130-
* @return Number of service data UUIDs discovered.
131-
*/
132-
int BLEAdvertisedDevice::getServiceDataUUIDCount() {
133-
return m_serviceDataUUIDs.size();
134-
} //getServiceDataUUIDCount
135-
136133
/**
137134
* @brief Get the service data UUID.
138135
* @return The service data UUID.
139136
*/
140137
BLEUUID BLEAdvertisedDevice::getServiceDataUUID() {
141-
return m_serviceDataUUIDs.empty() ? BLEUUID() : m_serviceDataUUIDs.front();
138+
return m_serviceDataUUIDs[0];
142139
} // getServiceDataUUID
143140

144141
/**
@@ -149,20 +146,12 @@ BLEUUID BLEAdvertisedDevice::getServiceDataUUID(int i) {
149146
return m_serviceDataUUIDs[i];
150147
} // getServiceDataUUID
151148

152-
/**
153-
* @brief Get the number of service UUIDs.
154-
* @return Number of service UUIDs discovered.
155-
*/
156-
int BLEAdvertisedDevice::getServiceUUIDCount() {
157-
return m_serviceUUIDs.size();
158-
} //getServiceUUIDCount
159-
160149
/**
161150
* @brief Get the Service UUID.
162151
* @return The Service UUID of the advertised device.
163152
*/
164153
BLEUUID BLEAdvertisedDevice::getServiceUUID() {
165-
return m_serviceUUIDs.empty() ? BLEUUID() : m_serviceUUIDs.front();
154+
return m_serviceUUIDs[0];
166155
} // getServiceUUID
167156

168157
/**
@@ -178,7 +167,7 @@ BLEUUID BLEAdvertisedDevice::getServiceUUID(int i) {
178167
* @return Return true if service is advertised
179168
*/
180169
bool BLEAdvertisedDevice::isAdvertisingService(BLEUUID uuid){
181-
for (int i = 0; i < getServiceUUIDCount(); i++) {
170+
for (int i = 0; i < m_serviceUUIDs.size(); i++) {
182171
if (m_serviceUUIDs[i].equals(uuid)) return true;
183172
}
184173
return false;
@@ -235,7 +224,7 @@ bool BLEAdvertisedDevice::haveRSSI() {
235224
* @return True if there is a service data value present.
236225
*/
237226
bool BLEAdvertisedDevice::haveServiceData() {
238-
return !m_serviceData.empty();
227+
return m_haveServiceData;
239228
} // haveServiceData
240229

241230

@@ -244,7 +233,7 @@ bool BLEAdvertisedDevice::haveServiceData() {
244233
* @return True if there is a service UUID value present.
245234
*/
246235
bool BLEAdvertisedDevice::haveServiceUUID() {
247-
return !m_serviceUUIDs.empty();
236+
return m_haveServiceUUID;
248237
} // haveServiceUUID
249238

250239

@@ -497,6 +486,7 @@ void BLEAdvertisedDevice::setServiceUUID(const char* serviceUUID) {
497486
*/
498487
void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
499488
m_serviceUUIDs.push_back(serviceUUID);
489+
m_haveServiceUUID = true;
500490
log_d("- addServiceUUID(): serviceUUID: %s", serviceUUID.toString().c_str());
501491
} // setServiceUUID
502492

@@ -506,6 +496,7 @@ void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
506496
* @param [in] data ServiceData value.
507497
*/
508498
void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
499+
m_haveServiceData = true; // Set the flag that indicates we have service data.
509500
m_serviceData.push_back(serviceData); // Save the service data that we received.
510501
} //setServiceData
511502

@@ -515,6 +506,7 @@ void BLEAdvertisedDevice::setServiceData(std::string serviceData) {
515506
* @param [in] data ServiceDataUUID value.
516507
*/
517508
void BLEAdvertisedDevice::setServiceDataUUID(BLEUUID uuid) {
509+
m_haveServiceData = true; // Set the flag that indicates we have service data.
518510
m_serviceDataUUIDs.push_back(uuid);
519511
log_d("- addServiceDataUUID(): serviceDataUUID: %s", uuid.toString().c_str());
520512
} // setServiceDataUUID
@@ -550,12 +542,12 @@ std::string BLEAdvertisedDevice::toString() {
550542
free(pHex);
551543
}
552544
if (haveServiceUUID()) {
553-
for (int i=0; i < getServiceUUIDCount(); i++) {
545+
for (int i=0; i < m_serviceUUIDs.size(); i++) {
554546
res += ", serviceUUID: " + getServiceUUID(i).toString();
555547
}
556548
}
557549
if (haveTXPower()) {
558-
char val[6];
550+
char val[4];
559551
snprintf(val, sizeof(val), "%d", getTXPower());
560552
res += ", txPower: ";
561553
res += val;
@@ -579,5 +571,5 @@ size_t BLEAdvertisedDevice::getPayloadLength() {
579571
return m_payloadLength;
580572
}
581573

582-
#endif /* CONFIG_BLUEDROID_ENABLED */
574+
#endif /* CONFIG_BT_ENABLED */
583575

libraries/BLE/src/BLEAdvertisedDevice.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef COMPONENTS_CPP_UTILS_BLEADVERTISEDDEVICE_H_
99
#define COMPONENTS_CPP_UTILS_BLEADVERTISEDDEVICE_H_
1010
#include "sdkconfig.h"
11-
#if defined(CONFIG_BLUEDROID_ENABLED)
11+
#if defined(CONFIG_BT_ENABLED)
1212
#include <esp_gattc_api.h>
1313

1414
#include <map>
@@ -42,8 +42,6 @@ class BLEAdvertisedDevice {
4242
BLEUUID getServiceUUID();
4343
BLEUUID getServiceUUID(int i);
4444
int getServiceDataCount();
45-
int getServiceDataUUIDCount();
46-
int getServiceUUIDCount();
4745
int8_t getTXPower();
4846
uint8_t* getPayload();
4947
size_t getPayloadLength();
@@ -85,6 +83,8 @@ class BLEAdvertisedDevice {
8583
bool m_haveManufacturerData;
8684
bool m_haveName;
8785
bool m_haveRSSI;
86+
bool m_haveServiceData;
87+
bool m_haveServiceUUID;
8888
bool m_haveTXPower;
8989

9090

@@ -124,20 +124,5 @@ class BLEAdvertisedDeviceCallbacks {
124124
virtual void onResult(BLEAdvertisedDevice advertisedDevice) = 0;
125125
};
126126

127-
#ifdef CONFIG_BT_BLE_50_FEATURES_SUPPORTED
128-
class BLEExtAdvertisingCallbacks {
129-
public:
130-
virtual ~BLEExtAdvertisingCallbacks() {}
131-
/**
132-
* @brief Called when a new scan result is detected.
133-
*
134-
* As we are scanning, we will find new devices. When found, this call back is invoked with a reference to the
135-
* device that was found. During any individual scan, a device will only be detected one time.
136-
*/
137-
virtual void onResult(esp_ble_gap_ext_adv_reprot_t report) = 0;
138-
};
139-
#endif // CONFIG_BT_BLE_50_FEATURES_SUPPORTED
140-
141-
142-
#endif /* CONFIG_BLUEDROID_ENABLED */
127+
#endif /* CONFIG_BT_ENABLED */
143128
#endif /* COMPONENTS_CPP_UTILS_BLEADVERTISEDDEVICE_H_ */

0 commit comments

Comments
 (0)