99
1010 Note that ESP32 uses Bluedroid by default and the other SoCs use NimBLE.
1111 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
1313 the passkey. This is not possible in Bluedroid.
1414
1515 Also, the SoC stores the authentication info in the NVS memory. After a successful
2626// The remote service we wish to connect to.
2727static BLEUUID serviceUUID (" 4fafc201-1fb5-459e-8fcc-c5c9c331914b" );
2828// 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" );
3030static BLEUUID secureCharUUID (" ff1d2614-e2d6-4c87-9154-6625d39ca7f8" );
3131
3232// This must match the server's passkey
@@ -35,7 +35,7 @@ static BLEUUID secureCharUUID("ff1d2614-e2d6-4c87-9154-6625d39ca7f8");
3535static boolean doConnect = false ;
3636static boolean connected = false ;
3737static boolean doScan = false ;
38- static BLERemoteCharacteristic *pRemoteUnsecureCharacteristic ;
38+ static BLERemoteCharacteristic *pRemoteInsecureCharacteristic ;
3939static BLERemoteCharacteristic *pRemoteSecureCharacteristic;
4040static BLEAdvertisedDevice *myDevice;
4141
@@ -87,15 +87,15 @@ bool connectToServer() {
8787 }
8888 Serial.println (" - Found our service" );
8989
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 ());
9595 pClient->disconnect ();
9696 return false ;
9797 }
98- Serial.println (" - Found unsecure characteristic" );
98+ Serial.println (" - Found insecure characteristic" );
9999
100100 // Obtain a reference to the secure characteristic
101101 pRemoteSecureCharacteristic = pRemoteService->getCharacteristic (secureCharUUID);
@@ -107,10 +107,10 @@ bool connectToServer() {
107107 }
108108 Serial.println (" - Found secure characteristic" );
109109
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: " );
114114 Serial.println (value.c_str ());
115115 }
116116
@@ -127,9 +127,9 @@ bool connectToServer() {
127127 }
128128
129129 // 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" );
133133 }
134134
135135 if (pRemoteSecureCharacteristic->canNotify ()) {
@@ -173,7 +173,7 @@ void setup() {
173173 BLESecurity *pSecurity = new BLESecurity ();
174174
175175 // Set security parameters
176- // Deafult parameters:
176+ // Default parameters:
177177 // - IO capability is set to NONE
178178 // - Initiator and responder key distribution flags are set to both encryption and identity keys.
179179 // - Passkey is set to BLE_SM_DEFAULT_PASSKEY (123456). It will warn if you don't change it.
@@ -213,11 +213,11 @@ void loop() {
213213
214214 // If we are connected to a peer BLE Server, demonstrate secure communication
215215 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 );
221221 }
222222
223223 // Write to the secure characteristic
0 commit comments