-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBleepingCustomBLE.ino
More file actions
executable file
·65 lines (50 loc) · 2.03 KB
/
Copy pathBleepingCustomBLE.ino
File metadata and controls
executable file
·65 lines (50 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
BleepingCustomBLE
An example ESP32 sketch using the Bleep App and Library
This example will start a BLE server allowing a user to configure WiFi credentials.
It uses methods exposed by the BleepingLibrary to implement custom BLE callbacks.
Read more in the Getting Started guide.
https://github.com/MClarkDev/BleepingLibrary/blob/master/GettingStarted.md
*/
#include "BleepingLibrary.h"
#include <BLEDevice.h>
BleepingLibrary bLib;
class MyBleepingCallback: public BLECharacteristicCallbacks {
void onRead(BLECharacteristic* characteristic) {
std::string key = characteristic->getUUID().toString();
std::string val = characteristic->getValue();
ESP_LOGD(_BLib, "Read: %s :: %s", key.c_str(), val.c_str());
}
void onWrite(BLECharacteristic *characteristic) {
std::string key = characteristic->getUUID().toString();
std::string val = characteristic->getValue();
ESP_LOGD(_BLib, "Write: %s :: %s", key.c_str(), val.c_str());
}
};
void setup() {
// Initialize
int boots = bLib.init();
ESP_LOGI(_BLib, "Boots: %d", boots);
// Setup BLE server
BleepingServer* server = bLib.getServer();
server->startServer();
// Add Custom Service
MyBleepingCallback* myCallback = new MyBleepingCallback();
BLEService* myService = server->createService(BleepingUUID("00000000-0000-beef-003f-000000000000"), 7);
server->createCharacteristic(myService, BleepingUUID("00000000-0000-beef-003f-000001000000"), myCallback);
server->createCharacteristic(myService, BleepingUUID("00000000-0000-beef-003f-000002000000"), myCallback);
server->createCharacteristic(myService, BleepingUUID("00000000-0000-beef-003f-000003000000"), myCallback);
myService->start();
/**
Implement your code below!
*/
ESP_LOGI(_BLib, "Now running my Bleeping App!");
ESP_LOGI(_BLib, "Setup mode is still running!");
int timeout = millis() + (2 * 60 * 1000);
while (millis() < timeout) {
delay(10);
}
ESP.restart();
}
void loop() {
}