I put this code together but at this moment I have no devices to test it. I think it explains the basic idea better than a description. As-is, it always scans to check that the device is available, which is probably best.
The UUID and name will be the same for each customer, ( It's flashed into the ESP device ), however I've yet to work out how devices get 'bonded' to the phone or how to prevent anyone with the app simply connecting and controlling some other persons devices.
I'm sure it's all explained somewhere.
I'll check out your code.
Couple of things noticed in the program. I did extend the timer time to 8 seconds and disabled the 'not found' message so I could see the displayed list. ( I could have appended it of course )
If the target device isn't active, then it does end with the message target device not found.
If it is active, then we don't get the message, ( it is therefore 'found' by the code ) but it doesn't actually connect.
The displayed list quite often has duplicates.
I added the 'connecting message' - which does run.
We have had the 'ConnectWithAddress' Block for a long time, but it very much depends on how dependant the device is on Service UUIDs. It also has to be found every time if the MAC Address is dynamic.
The reason for duplicates - nothing in my code to remove them! (not important)
Making the unit unique for each customer - much depends on the number of customers. It's relatively easy to make Scripts with a unique variable, but not easy to make an App that 'knows' the same value unless it is in a hard-coded List, because the App of course is compiled.
I'm going to keep working on this for a while.
The BLE devices will have a fixed MAC address as they are ESP32 modules, so I assume they are reasonably unique and permanent. I haven't examined where the MAC is defined, but hey -- it's there for now.
I'm going be working on the security aspect which means working with local storage blocks.
I'll post an update when worthwhile. But I did note ( and in another thread ) that the RSSI value does not update itself - so that looks like a bug.
Yes, it probably is, but there are many issues with Bluetooth itself, mostly brought about by manufacturers not implementing the standards correctly. If you buy the cheaper ESP32 modules from the open markets, overall they are good performers and can save a lot of money, but the devil is in the details......
Since this topic has been very useful to me in my first project with MIT App. Even though it's been a long time since it opened, I want to contribute with the solution that I have found.
The typical mechanism proposed for the extension MIT BLE, although it works perfectly, I find it very inelegant if it is to connect a known device and it is not a simple experiment. Also, the number of keystrokes and the entire connection process, it is very cumbersome and only understandable to someone who knows how BLEs work.
My intention is that the App, just start, connect automatically and without user intervention to the known BLE device whose NAME has been previously configured. Of course, since the connection is not made instantly, The App should be giving simple messages that allow to know in which stage the connection is: start SCAN, stop SCAN, connect ... And, of course, give the corresponding OK or error messages.
Attached is a small test that I have used, isolating only the connection process.
I have carried out tests with HC-05 modules from different manufacturers until it works in all of them.
In the building where I live, the number of neighbors is huge and the number of BLE devices that appear when doing the SCAN, it is surprisingly high. It even depends a lot from the room where you run the App. This also created certain problems for me, but this version has worked correctly.
I have used the BLE extension 20200828 and the 20201223. With both it works. PrbaConexBLE.aia (409.7 KB)
If anyone finds it useful, I would be very happy to have been able to contribute to the MIT App community.