ESP32 BLE With Physical Switch - Not able to access Relay pin using BLE App

Hello Everyone,
I am working on a ESP32 BLE project. In this project actually I need to control (ON/OFF) relay using android app and with Physical Switches also. In attached code, I have tried to control relay using mobile app and store their current status in EEPROM. Then, tried to read last relay pin status stored in EEPROM and change their value using Physical button.

PROBLEM AM FACING: I can control relay pin using Physical switch without any problem, Mobile app (BLE IO)also gets connected successfully. But as I try to turn ON/OFF Relay, it blinks only. Not properly turning ON/OFF using mobile app.

Might be problem is here (inside void loop): if(Serial.available()>0){value =;}

Please Help

ESP32_BLE_with_Button.ino (9.09 KB)

Your guessing is right.
There are two main possabilities how you wrote this code:

Copy & paste a working example just as is
or copy & paste a working example starting to modifiy it on multiple places how you think it might work.

There is a pretty basic misunderstanding about how this command works.
If you would have wrote this code from scratch you would have so much knowledge that you would'nt have to ask
this question.

Modifing an existing code longer than 5 lines of code requires to understand what the code is doing to a certain level.
Your program is a task that is a bit bigger than asking for a 64 character-long cheatcode of a PC-game.
So study how the command works

best regards Stefan