I need to put a password for BLE connection of ESP32. Namely, I need to create a password as an array, and every time I need to connect my phone I will enter it. System will check if password is correct and then let me make an action (for now it is just control over LED). I searched for a solution but couldn't find anything similar. I only know that I should somehow use EEPROM. I put basic code which includes actions appart from password.
const byte led_gpio = 32;
int LED_BUILTIN = 2;
void setup()
{
Serial.begin(115200);
pinMode(led_gpio, OUTPUT);
pinMode (LED_BUILTIN, OUTPUT);
}
void loop() {
if (ESP_BT.available()) //Check if we receive anything from Bluetooth
{
if (ESP_BT.read()== PASSWORD)
{
incoming = ESP_BT.read(); //Read what we recevive
Serial.print("Received:"); Serial.println(incoming);
if (incoming == 48)
{
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(led_gpio, HIGH);
ESP_BT.println("LED turned ON");
}
if (incoming == 49)
{
digitalWrite(LED_BUILTIN, LOW);
ESP_BT.println("LED turned OFF");
digitalWrite(led_gpio, LOW);
}
}
}
delay(20);
}