Skip to content

Commit 4fbed5a

Browse files
committed
Add service data advertising example.
1 parent 6aea9a1 commit 4fbed5a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/** NimBLE_Service_Data_Advertiser Demo:
2+
*
3+
* Simple demo of advertising service data that changes every 5 seconds
4+
*
5+
* Created: on February 7 2021
6+
* Author: H2zero
7+
*
8+
*/
9+
10+
#include <NimBLEDevice.h>
11+
12+
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
13+
14+
static NimBLEUUID dataUuid(SERVICE_UUID);
15+
static NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising();
16+
static uint32_t count = 0;
17+
18+
void setup() {
19+
Serial.begin(115200);
20+
Serial.println("Starting BLE work!");
21+
22+
NimBLEDevice::init("svc data");
23+
}
24+
25+
void loop() {
26+
pAdvertising->stop();
27+
pAdvertising->setServiceData(dataUuid, std::string((char*)&count, sizeof(count)));
28+
pAdvertising->start();
29+
30+
Serial.printf("Advertising count = %d\n", count);
31+
count++;
32+
delay(5000);
33+
}

0 commit comments

Comments
 (0)