Dear @Kampje ,
In addition to all that @ABG has already suggested, please take a look also here:
In my answer #6 you'll find an example containing a couple of codes: the .ino of an ESP32 connecetd via BLE to an app made by AI2 and its .aia.
You can take a sight and elaborate then for your needs.
Hoping it can help.
Cheers.