ESP32 BLE Bonding | PassKey over WiFi

csabanagy
Posts: 1
Joined: Fri May 10, 2019 2:16 am

ESP32 BLE Bonding | PassKey over WiFi

Postby csabanagy » Fri May 10, 2019 2:30 am

Hello,

Working on a project where I'm connecting an ESP32 to a BLE Device.

The BLE device requires secure connection using passkey, when you connect to it, there is a 6 digit password you must use to complete the bonding.

My ESP32 does not have a keyboard or display, so I want to use the dual mode of the ESP32 and use WiFi SOFT-AP to let a smartphone connect to ESP32, let user type in the password displayed on the screen and send to ESP32 when doing bonding.

However this has proven tricky and cant figure out how or if this is even possible.

Im using this example code for the BLE connection https://github.com/nkolban/esp32-snippe ... asskey.ino

For my onPassKeyRequest() I want to put a delay so I can connect to my smartphone, open the input form and type in the password.
Then when I submit form, my webserver will grab the value and put it into my code global variable and return.

But when I do this vTaskDelay is freeze my Wifi functionality too, so when the delay is done the value isn't updated and the bonding fails.

Is there way to just pause the BLE connection and let the Wifi continue working for this process???

I tried vTaskSuspend/Resume but this didnt work either.

Any advice or suggestions is very appreciated! :)


Code: Select all


long code = 0;

class MySecurity : public BLESecurityCallbacks {

	uint32_t onPassKeyRequest(){
		vTaskDelay(15000); 
		return code;
	}
	void onPassKeyNotify(uint32_t pass_key){
        ESP_LOGE(LOG_TAG, "The passkey Notify number:%d", pass_key);
	}
	bool onConfirmPIN(uint32_t pass_key){
        ESP_LOGI(LOG_TAG, "The passkey YES/NO number:%d", pass_key);
	    vTaskDelay(5000);
		return true;
	}
	bool onSecurityRequest(){
		ESP_LOGI(LOG_TAG, "Security Request");
		return true;
	}
	void onAuthenticationComplete(esp_ble_auth_cmpl_t auth_cmpl){
		if(auth_cmpl.success){
			ESP_LOGI(LOG_TAG, "remote BD_ADDR:");
			esp_log_buffer_hex(LOG_TAG, auth_cmpl.bd_addr, sizeof(auth_cmpl.bd_addr));
			ESP_LOGI(LOG_TAG, "address type = %d", auth_cmpl.addr_type);
		}
        ESP_LOGI(LOG_TAG, "pair status = %s", auth_cmpl.success ? "success" : "fail");
	}
};
Last edited by csabanagy on Fri May 10, 2019 6:59 pm, edited 1 time in total.

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: ESP32 BLE Bonding | PassKey over WiFi

Postby chegewara » Fri May 10, 2019 3:41 pm

It is just theory, but its how you could do:
- add xQueueReceive or xEventGroupWaitBits in this callback:

Code: Select all

	uint32_t onPassKeyRequest(){
		vTaskDelay(15000); 
		return code;
	}
- open website to enter pin (before you start pairing),
- start pairing,
- send pin from website.

Who is online

Users browsing this forum: Baidu [Spider] and 59 guests