BLE restore settings after restart?

Dork507
Posts: 17
Joined: Wed Dec 14, 2022 7:35 pm

BLE restore settings after restart?

Postby Dork507 » Wed Mar 08, 2023 12:37 pm

Hello, I use the following code to use the ESP32 BLE PIN/Pairing.
That works quite well so far.

Code: Select all

class MySecurity : public BLESecurityCallbacks {
  
  bool onConfirmPIN(uint32_t pin){
    return false;
  }
  
	uint32_t onPassKeyRequest(){
        //ESP_LOGI(LOG_TAG, "PassKeyRequest");
		return 123456;
	}

	void onPassKeyNotify(uint32_t pass_key){
       // ESP_LOGI(LOG_TAG, "On passkey Notify number:%d", pass_key);
	}

	bool onSecurityRequest(){
	    //ESP_LOGI(LOG_TAG, "On Security Request");
		return true;
	}

	void onAuthenticationComplete(esp_ble_auth_cmpl_t cmpl){
		//ESP_LOGI(LOG_TAG, "Starting BLE work!");
		if(cmpl.success){
			uint16_t length;
			esp_ble_gap_get_whitelist_size(&length);
			//ESP_LOGD(LOG_TAG, "size: %d", length);
     	}
	}
};

//inside BLE init
BLESecurity *pSecurity = new BLESecurity();
pSecurity->setStaticPIN(000000);
I use the Arduino Framework in IDF.
However, when the ESP32 restarts. The phone ask again for the PIN. How can I restore the pairing settings after the restart? I know I have to safe something in the NVS. But what and how can I restore this?

Many thanks

Dork507
Posts: 17
Joined: Wed Dec 14, 2022 7:35 pm

Re: BLE restore settings after restart?

Postby Dork507 » Fri Mar 10, 2023 10:10 am

nobody? :?:


Dork507
Posts: 17
Joined: Wed Dec 14, 2022 7:35 pm

Re: BLE restore settings after restart?

Postby Dork507 » Sat Mar 11, 2023 10:51 pm

hello,

thanks for your reply. But I really don't know what I have to do with this information.
I think for this stack I'm too stupid.

The following codes works worse than the code before. :oops:

Code: Select all

  BLEDevice::setEncryptionLevel(ESP_BLE_SEC_ENCRYPT_NO_MITM);
  BLESecurity *pSecurity = new BLESecurity();
 pSecurity->setStaticPIN(000000);
 pSecurity->setKeySize();
pSecurity->setAuthenticationMode(ESP_LE_AUTH_REQ_SC_ONLY);
pSecurity->setCapability(ESP_IO_CAP_IO);
pSecurity->setInitEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK);
I guess I have to safe the encryption key? Can I restore it with this

Code: Select all

pSecurity->setInitEncryptionKey(ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK);

Who is online

Users browsing this forum: No registered users and 76 guests