-
-
Notifications
You must be signed in to change notification settings - Fork 275
Access Protection Authentication
Phil Schatzmann edited this page Feb 19, 2022
·
9 revisions
I would have really liked to provide some password protection where the user would need to enter a password on the mobile phone, but somehow this does not fit with what's possible in Bluetooth. Here is a list of what you can do to protect your device somehow:
- You can activate Bluetooth Authentication by calling activate_pin_code(true). This forces the Mobile Phone to generate a pin code and send it to the ESP32. You need to confirm the password by calling confirm_pin_code(). You might want to provide a button to trigger this functionality.
BluetoothA2DPSink a2dp_sink;
void setup() {
a2dp_sink.activate_pin_code(true);
a2dp_sink.start("MyMusic", false);
}
void loop() {
// add logic which calls confirm_pin_code().
}
Here is a full working example
- You can provide a callback method which decides if a device is valid or not by calling set_address_validator()
BluetoothA2DPSink a2dp_sink;
bool check(esp_bd_addr_t adr){
// this will prevent all connections
return false;
}
void setup() {
a2dp_sink.set_address_validator(check);
a2dp_sink.start("MyMusic", false);
}
void loop() {
}
- You can call the method set_discoverability() to prevent that the device can be discovered. This function is however only available with ESP Arduino 2.0.0
a2dp_sink.set_discoverability(ESP_BT_NON_DISCOVERABLE);
Please let me know if you managed to find some better way in the following discussion...