@@ -80,6 +80,9 @@ PairingResult NukiBle::pairNuki(AuthorizationIdType idType) {
80
80
PairingResult result = PairingResult::Pairing;
81
81
82
82
if (pairingServiceAvailable && bleAddress != BLEAddress (" " )) {
83
+ #ifdef DEBUG_NUKI_CONNECT
84
+ log_d (" Nuki in pairing mode found" );
85
+ #endif
83
86
if (connectBle (bleAddress)) {
84
87
crypto_box_keypair (myPublicKey, myPrivateKey);
85
88
@@ -108,7 +111,7 @@ PairingResult NukiBle::pairNuki(AuthorizationIdType idType) {
108
111
log_d (" pairing result %d" , result);
109
112
#endif
110
113
111
- isPaired = result == PairingResult::Success;
114
+ isPaired = ( result == PairingResult::Success) ;
112
115
return result;
113
116
}
114
117
@@ -121,6 +124,9 @@ void NukiBle::unPairNuki() {
121
124
}
122
125
123
126
bool NukiBle::connectBle (const BLEAddress bleAddress) {
127
+ #ifdef DEBUG_NUKI_CONNECT
128
+ log_d (" connecting within: %s" , pcTaskGetTaskName (xTaskGetCurrentTaskHandle ()));
129
+ #endif
124
130
connecting = true ;
125
131
bleScanner->enableScanning (false );
126
132
if (!pClient->isConnected ()) {
@@ -233,6 +239,8 @@ void NukiBle::onResult(BLEAdvertisedDevice* advertisedDevice) {
233
239
#endif
234
240
bleAddress = advertisedDevice->getAddress ();
235
241
pairingServiceAvailable = true ;
242
+ } else {
243
+ pairingServiceAvailable = false ;
236
244
}
237
245
}
238
246
}
@@ -597,11 +605,18 @@ bool NukiBle::retrieveCredentials() {
597
605
log_d (" PinCode: %d" , pinCode);
598
606
#endif
599
607
608
+ if (secretKeyK[0 ] == 0x00 || authorizationId[0 ] == 0x00 ) {
609
+ log_w (" secret key OR authorizationId is empty: not paired" );
610
+ giveNukiBleSemaphore ();
611
+ return false ;
612
+ }
613
+
600
614
if (pinCode == 0 ) {
601
615
log_w (" Pincode is 000000" );
602
616
}
603
617
604
618
} else {
619
+ log_e (" Getting data from NVS issue" );
605
620
giveNukiBleSemaphore ();
606
621
return false ;
607
622
}
@@ -613,8 +628,12 @@ bool NukiBle::retrieveCredentials() {
613
628
614
629
void NukiBle::deleteCredentials () {
615
630
if (takeNukiBleSemaphore (" del cred" )) {
616
- preferences.remove (SECRET_KEY_STORE_NAME);
617
- preferences.remove (AUTH_ID_STORE_NAME);
631
+ unsigned char emptySecretKeyK[32 ] = {0x00 };
632
+ unsigned char emptyAuthorizationId[4 ] = {0x00 };
633
+ preferences.putBytes (SECRET_KEY_STORE_NAME, emptySecretKeyK, 32 );
634
+ preferences.putBytes (AUTH_ID_STORE_NAME, emptyAuthorizationId, 4 );
635
+ // preferences.remove(SECRET_KEY_STORE_NAME);
636
+ // preferences.remove(AUTH_ID_STORE_NAME);
618
637
giveNukiBleSemaphore ();
619
638
}
620
639
#ifdef DEBUG_NUKI_CONNECT
0 commit comments