Skip to content

Commit 48a70e4

Browse files
committed
Fix BT5 examples for non-esp devices.
1 parent eb909e6 commit 48a70e4

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

examples/Bluetooth_5/NimBLE_extended_client/NimBLE_extended_client.ino

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
*
99
*/
1010

11-
/****************************************************
12-
* For use with ESP32C3, ESP32S3, ESP32H2 ONLY! *
13-
/**************************************************/
1411

1512
#include <NimBLEDevice.h>
1613
#if !CONFIG_BT_NIMBLE_EXT_ADV

examples/Bluetooth_5/NimBLE_extended_server/NimBLE_extended_server.ino

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
*
1313
*/
1414

15-
/****************************************************
16-
* For use with ESP32C3, ESP32S3, ESP32H2 ONLY! *
17-
/**************************************************/
18-
1915
#include "NimBLEDevice.h"
2016
#if !CONFIG_BT_NIMBLE_EXT_ADV
2117
# error Must enable extended advertising, see nimconfig.h file.
2218
#endif
2319

20+
#ifdef ESP_PLATFORM
2421
#include "esp_sleep.h"
22+
#endif
2523

2624
#define SERVICE_UUID "ABCD"
2725
#define CHARACTERISTIC_UUID "1234"
@@ -49,7 +47,11 @@ class ServerCallbacks: public NimBLEServerCallbacks {
4947

5048
void onDisconnect(NimBLEServer* pServer) {
5149
Serial.printf("Client disconnected - sleeping for %u seconds\n", sleepSeconds);
50+
#ifdef ESP_PLATFORM
5251
esp_deep_sleep_start();
52+
#else
53+
systemRestart(); // nRF platforms restart then sleep via delay in setup.
54+
#endif
5355
};
5456
};
5557

@@ -63,18 +65,24 @@ class advertisingCallbacks: public NimBLEExtAdvertisingCallbacks {
6365
printf("Client connecting\n");
6466
return;
6567
case BLE_HS_ETIMEOUT:
66-
printf("Time expired - sleeping for %u seconds\n", sleepSeconds);
68+
printf("Time expired - sleeping for %" PRIu32 "seconds\n", sleepSeconds);
6769
break;
6870
default:
6971
break;
7072
}
71-
73+
#ifdef ESP_PLATFORM
7274
esp_deep_sleep_start();
75+
#else
76+
systemRestart(); // nRF platforms restart then sleep via delay in setup.
77+
#endif
7378
}
7479
};
7580

7681
void setup () {
7782
Serial.begin(115200);
83+
#ifndef ESP_PLATFORM
84+
delay(sleepSeconds * 1000); // system ON sleep mode for nRF platforms to simulate the esp deep sleep with timer wakeup
85+
#endif
7886

7987
NimBLEDevice::init("Extended advertiser");
8088

@@ -143,8 +151,10 @@ void setup () {
143151
Serial.printf("Failed to register advertisment data\n");
144152
}
145153

154+
#ifdef ESP_PLATFORM
146155
esp_sleep_enable_timer_wakeup(sleepSeconds * 1000000);
156+
#endif
147157
}
148158

149159
void loop () {
150-
}
160+
}

examples/Bluetooth_5/NimBLE_multi_advertiser/NimBLE_multi_advertiser.ino

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
*
1313
*/
1414

15-
/****************************************************
16-
* For use with ESP32C3, ESP32S3, ESP32H2 ONLY! *
17-
/**************************************************/
18-
1915
#include <NimBLEDevice.h>
2016
#if !CONFIG_BT_NIMBLE_EXT_ADV
2117
# error Must enable extended advertising, see nimconfig.h file.
2218
#endif
2319

20+
#ifdef ESP_PLATFORM
2421
#include "esp_sleep.h"
22+
#endif
2523

2624
#define SERVICE_UUID "ABCD"
2725
#define CHARACTERISTIC_UUID "1234"
@@ -52,7 +50,11 @@ class ServerCallbacks: public NimBLEServerCallbacks {
5250
// if still advertising we won't sleep yet.
5351
if (!pServer->getAdvertising()->isAdvertising()) {
5452
Serial.printf("Sleeping for %u seconds\n", sleepTime);
53+
#ifdef ESP_PLATFORM
5554
esp_deep_sleep_start();
55+
#else
56+
systemRestart(); // nRF platforms restart then sleep via delay in setup.
57+
#endif
5658
}
5759
};
5860
};
@@ -72,8 +74,11 @@ class advCallbacks: public NimBLEExtAdvertisingCallbacks {
7274
default:
7375
break;
7476
}
75-
77+
#ifdef ESP_PLATFORM
7678
esp_deep_sleep_start();
79+
#else
80+
systemRestart(); // nRF platforms restart then sleep via delay in setup.
81+
#endif
7782
}
7883

7984
bool m_updatedSR = false;
@@ -174,7 +179,9 @@ void setup () {
174179
Serial.printf("Failed to register advertisment data\n");
175180
}
176181

177-
esp_sleep_enable_timer_wakeup(sleepTime * 1000000);
182+
#ifdef ESP_PLATFORM
183+
esp_sleep_enable_timer_wakeup(sleepSeconds * 1000000);
184+
#endif
178185
}
179186

180187
void loop(){

0 commit comments

Comments
 (0)