Error 507 while connecting bluetooth

Requirement:
Upon pressing "Choose Bluetooth Device," I need to display a list of both available and paired Bluetooth devices. After establishing a connection, I require bidirectional data transfer with the selected device.

What I Have Implemented:
As shown in the attached image, I have attempted to implement the above requirement. However, I am currently only able to retrieve a list of already paired devices. When I attempt to connect to any of these devices, I encounter an Error 507 (Unable to connect. Is the device turned on?).

Questions:

  1. How can I display a list of all available Bluetooth devices, in addition to paired devices?
  2. How can I resolve the Error 507 issue?
  3. Are there any suggestions or references for implementing bidirectional data transfer?

Thank you in advance for your assistance.

bluetooth
errors

Dear @thejas_b,
it's just a bit foggy ( :grin:) your question: in other words, what is your intended BT device to connect ?
An Arduino board ? A pair of earphones ? Whatever ?
Depending on which the solution can be different.

Is your BT device a BLE or a classic BT ? In the first case you shall use the most updated extension to make it working (You can find it in @ewpatton posts). If classic (like HC05/06 or ESP32 -not in BLE mode) what you have posted is almost right, but please follow @ABG's hints about the use of delimiters.

Therefore: first of all, you can have a look to the answers that @ABG has posted in many topics.

Then, there are many web sites where you can find a huge amount of hints and samples, like KIO4.com and professorcad.co.uk.

Or simply digging the forum.

In any case: Error 507 means that the intended BT device is not responding (but, I agree, this last information is not helping you so much...)

Best wishes.