9
9
10
10
Note that ESP32 uses Bluedroid by default and the other SoCs use NimBLE.
11
11
Bluedroid initiates security on-connect, while NimBLE initiates security on-demand.
12
- This means that in NimBLE you can read the unsecure characteristic without entering
12
+ This means that in NimBLE you can read the insecure characteristic without entering
13
13
the passkey. This is not possible in Bluedroid.
14
14
15
15
Also, the SoC stores the authentication info in the NVS memory. After a successful
26
26
// The remote service we wish to connect to.
27
27
static BLEUUID serviceUUID (" 4fafc201-1fb5-459e-8fcc-c5c9c331914b" );
28
28
// The characteristics of the remote service we are interested in.
29
- static BLEUUID unsecureCharUUID (" beb5483e-36e1-4688-b7f5-ea07361b26a8" );
29
+ static BLEUUID insecureCharUUID (" beb5483e-36e1-4688-b7f5-ea07361b26a8" );
30
30
static BLEUUID secureCharUUID (" ff1d2614-e2d6-4c87-9154-6625d39ca7f8" );
31
31
32
32
// This must match the server's passkey
@@ -35,7 +35,7 @@ static BLEUUID secureCharUUID("ff1d2614-e2d6-4c87-9154-6625d39ca7f8");
35
35
static boolean doConnect = false ;
36
36
static boolean connected = false ;
37
37
static boolean doScan = false ;
38
- static BLERemoteCharacteristic *pRemoteUnsecureCharacteristic ;
38
+ static BLERemoteCharacteristic *pRemoteInsecureCharacteristic ;
39
39
static BLERemoteCharacteristic *pRemoteSecureCharacteristic;
40
40
static BLEAdvertisedDevice *myDevice;
41
41
@@ -87,15 +87,15 @@ bool connectToServer() {
87
87
}
88
88
Serial.println (" - Found our service" );
89
89
90
- // Obtain a reference to the unsecure characteristic
91
- pRemoteUnsecureCharacteristic = pRemoteService->getCharacteristic (unsecureCharUUID );
92
- if (pRemoteUnsecureCharacteristic == nullptr ) {
93
- Serial.print (" Failed to find unsecure characteristic UUID: " );
94
- Serial.println (unsecureCharUUID .toString ().c_str ());
90
+ // Obtain a reference to the insecure characteristic
91
+ pRemoteInsecureCharacteristic = pRemoteService->getCharacteristic (insecureCharUUID );
92
+ if (pRemoteInsecureCharacteristic == nullptr ) {
93
+ Serial.print (" Failed to find insecure characteristic UUID: " );
94
+ Serial.println (insecureCharUUID .toString ().c_str ());
95
95
pClient->disconnect ();
96
96
return false ;
97
97
}
98
- Serial.println (" - Found unsecure characteristic" );
98
+ Serial.println (" - Found insecure characteristic" );
99
99
100
100
// Obtain a reference to the secure characteristic
101
101
pRemoteSecureCharacteristic = pRemoteService->getCharacteristic (secureCharUUID);
@@ -107,10 +107,10 @@ bool connectToServer() {
107
107
}
108
108
Serial.println (" - Found secure characteristic" );
109
109
110
- // Read the value of the unsecure characteristic (should work without authentication)
111
- if (pRemoteUnsecureCharacteristic ->canRead ()) {
112
- String value = pRemoteUnsecureCharacteristic ->readValue ();
113
- Serial.print (" Unsecure characteristic value: " );
110
+ // Read the value of the insecure characteristic (should work without authentication)
111
+ if (pRemoteInsecureCharacteristic ->canRead ()) {
112
+ String value = pRemoteInsecureCharacteristic ->readValue ();
113
+ Serial.print (" Insecure characteristic value: " );
114
114
Serial.println (value.c_str ());
115
115
}
116
116
@@ -127,9 +127,9 @@ bool connectToServer() {
127
127
}
128
128
129
129
// Register for notifications on both characteristics if they support it
130
- if (pRemoteUnsecureCharacteristic ->canNotify ()) {
131
- pRemoteUnsecureCharacteristic ->registerForNotify (notifyCallback);
132
- Serial.println (" - Registered for unsecure characteristic notifications" );
130
+ if (pRemoteInsecureCharacteristic ->canNotify ()) {
131
+ pRemoteInsecureCharacteristic ->registerForNotify (notifyCallback);
132
+ Serial.println (" - Registered for insecure characteristic notifications" );
133
133
}
134
134
135
135
if (pRemoteSecureCharacteristic->canNotify ()) {
@@ -173,7 +173,7 @@ void setup() {
173
173
BLESecurity *pSecurity = new BLESecurity ();
174
174
175
175
// Set security parameters
176
- // Deafult parameters:
176
+ // Default parameters:
177
177
// - IO capability is set to NONE
178
178
// - Initiator and responder key distribution flags are set to both encryption and identity keys.
179
179
// - Passkey is set to BLE_SM_DEFAULT_PASSKEY (123456). It will warn if you don't change it.
@@ -213,11 +213,11 @@ void loop() {
213
213
214
214
// If we are connected to a peer BLE Server, demonstrate secure communication
215
215
if (connected) {
216
- // Write to the unsecure characteristic
217
- String unsecureValue = " Client time: " + String (millis () / 1000 );
218
- if (pRemoteUnsecureCharacteristic ->canWrite ()) {
219
- pRemoteUnsecureCharacteristic ->writeValue (unsecureValue .c_str (), unsecureValue .length ());
220
- Serial.println (" Wrote to unsecure characteristic: " + unsecureValue );
216
+ // Write to the insecure characteristic
217
+ String insecureValue = " Client time: " + String (millis () / 1000 );
218
+ if (pRemoteInsecureCharacteristic ->canWrite ()) {
219
+ pRemoteInsecureCharacteristic ->writeValue (insecureValue .c_str (), insecureValue .length ());
220
+ Serial.println (" Wrote to insecure characteristic: " + insecureValue );
221
221
}
222
222
223
223
// Write to the secure characteristic
0 commit comments