-
-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathNimBLE_Secure_Server.ino
More file actions
41 lines (35 loc) · 1.83 KB
/
Copy pathNimBLE_Secure_Server.ino
File metadata and controls
41 lines (35 loc) · 1.83 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
/**
* NimBLE_Secure_Server Demo:
*
* This example demonstrates the secure passkey protected conenction and communication between an esp32 server and an
* esp32 client. Please note that esp32 stores auth info in nvs memory. After a successful connection it is possible
* that a passkey change will be ineffective. To avoid this clear the memory of the esp32's between security testings.
* esptool.py is capable of this, example: esptool.py --port /dev/ttyUSB0 erase_flash.
*
* Created: on Jan 08 2021
* Author: mblasee
*/
#include <Arduino.h>
#include <NimBLEDevice.h>
void setup() {
Serial.begin(115200);
Serial.println("Starting NimBLE Server");
NimBLEDevice::init("NimBLE");
NimBLEDevice::setPower(3); /** +3db */
NimBLEDevice::setSecurityAuth(true, true, false); /** bonding, MITM, don't need BLE secure connections as we are using passkey pairing */
NimBLEDevice::setSecurityPasskey(123456);
NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_ONLY); /** Display only passkey */
NimBLEServer* pServer = NimBLEDevice::createServer();
NimBLEService* pService = pServer->createService("ABCD");
NimBLECharacteristic* pNonSecureCharacteristic = pService->createCharacteristic("1234", NIMBLE_PROPERTY::READ);
NimBLECharacteristic* pSecureCharacteristic =
pService->createCharacteristic("1235",
NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::READ_AUTHEN);
pService->start();
pNonSecureCharacteristic->setValue("Hello Non Secure BLE");
pSecureCharacteristic->setValue("Hello Secure BLE");
NimBLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising();
pAdvertising->addServiceUUID("ABCD");
pAdvertising->start();
}
void loop() {}