File tree Expand file tree Collapse file tree 4 files changed +24
-3
lines changed Expand file tree Collapse file tree 4 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ bool initialized = false; // Have we been initialized?
45
45
esp_ble_sec_act_t BLEDevice::m_securityLevel = (esp_ble_sec_act_t )0 ;
46
46
BLESecurityCallbacks* BLEDevice::m_securityCallbacks = nullptr ;
47
47
uint16_t BLEDevice::m_localMTU = 23 ;
48
+ BLEAdvertising* BLEDevice::m_bleAdvertising = nullptr ;
48
49
49
50
/* *
50
51
* @brief Create a new instance of a client.
@@ -545,4 +546,21 @@ uint16_t BLEDevice::getMTU() {
545
546
bool BLEDevice::getInitialized () {
546
547
return initialized;
547
548
}
549
+
550
+ BLEAdvertising* BLEDevice::getAdvertising () {
551
+ if (m_bleAdvertising == nullptr )
552
+ {
553
+ m_bleAdvertising = new BLEAdvertising ();
554
+ ESP_LOGI (LOG_TAG, " create advertising" );
555
+ }
556
+ ESP_LOGD (LOG_TAG, " get advertising" );
557
+ return m_bleAdvertising;
558
+ }
559
+
560
+ void BLEDevice::startAdvertising () {
561
+ ESP_LOGD (LOG_TAG, " >> startAdvertising" );
562
+ getAdvertising ()->start ();
563
+ ESP_LOGD (LOG_TAG, " << startAdvertising" );
564
+ } // startAdvertising
565
+
548
566
#endif // CONFIG_BT_ENABLED
Original file line number Diff line number Diff line change @@ -43,6 +43,8 @@ class BLEDevice {
43
43
static esp_err_t setMTU (uint16_t mtu);
44
44
static uint16_t getMTU ();
45
45
static bool getInitialized (); // Returns the state of the device, is it initialized or not?
46
+ static BLEAdvertising* getAdvertising ();
47
+ static void startAdvertising ();
46
48
47
49
private:
48
50
static BLEServer *m_pServer;
@@ -51,6 +53,7 @@ class BLEDevice {
51
53
static esp_ble_sec_act_t m_securityLevel;
52
54
static BLESecurityCallbacks* m_securityCallbacks;
53
55
static uint16_t m_localMTU;
56
+ static BLEAdvertising *m_bleAdvertising;
54
57
55
58
static esp_gatt_if_t getGattcIF ();
56
59
Original file line number Diff line number Diff line change @@ -120,7 +120,7 @@ BLEService* BLEServer::getServiceByUUID(BLEUUID uuid) {
120
120
* @return An advertising object.
121
121
*/
122
122
BLEAdvertising* BLEServer::getAdvertising () {
123
- return &m_bleAdvertising ;
123
+ return BLEDevice::getAdvertising () ;
124
124
}
125
125
126
126
uint16_t BLEServer::getConnId () {
@@ -359,7 +359,7 @@ void BLEServer::removeService(BLEService *service) {
359
359
*/
360
360
void BLEServer::startAdvertising () {
361
361
ESP_LOGD (LOG_TAG, " >> startAdvertising" );
362
- m_bleAdvertising. start ();
362
+ BLEDevice::startAdvertising ();
363
363
ESP_LOGD (LOG_TAG, " << startAdvertising" );
364
364
} // startAdvertising
365
365
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ class BLEServer {
73
73
friend class BLEDevice ;
74
74
esp_ble_adv_data_t m_adv_data;
75
75
uint16_t m_appId;
76
- BLEAdvertising m_bleAdvertising;
76
+ // BLEAdvertising m_bleAdvertising;
77
77
uint16_t m_connId;
78
78
uint32_t m_connectedCount;
79
79
uint16_t m_gatts_if;
You can’t perform that action at this time.
0 commit comments