This is causing me grief.
I can't iterate through the BLE 'devicelist' because it isn't a 'list' - The blocks don't connect.
I tried to make a new 'List' and add items from the BLE 'devicelist' whenever a device was found but failed.
I'd sooner not use a clock - - and still would need to do as above ( which I haven't worked out how).
Is there an example anywhere of achieving this since it would appear to be a reasonable thing to do instead of having the user keep pressing buttons.
And I'm still in the dark as to what's happening to the device list when I try to connect to a specific device.
Help appreciated BTW.
- stop the scan sooner.
That depends on what devices might already exist in your customer's premises and all other circumstances that can affect the BT radio signal between your device and your App, but in ideal conditions you do not need a Device List at all because the "unknowns" are already known by you.
Let's wait for Evan's response concerning the direct connection Blocks. He is an extremely busy chap so patience is required.
First news snippet:
The 'ConnectToDeviceType' Block should not be used.
OK, I do not have confirmation as to what the Device Name should comprise in terms of what gets fed into the 'ConnectToDeviceWithServiceAndName' name parameter - should it be the whole device list item collected or should we extract the name from that list item.
If the mac address is to be used in other BLE Blocks, we are not required to extract that from the device list item, the Block function does that for us. So, I'm expecting the same kind of thing for device name, but awaiting Evan to confirm.
Concerning the UUID and Name - are those going to be identical for every customer or unique? That obviously affects how the App is coded. If values are identical for every customer, they can be hard-coded in the App (they can be encrypted if required but relying on Android security is reasonable in most cases). If however the values will be unique to each customer, the code will have to pick the values up first via the ESP32 BT advertising.
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.
BLE_ConnectToKnownDevice.aia (192.8 KB)
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.
I'll continue playing.
OK, So I got it connected by extracting the Mac address ( which will be the unknown) from the device that matched.
It then connected )
Then replaced the connect block to use the Address.
BLE_ConnectToKnownDevice (1).aia (193.4 KB)
Hi rowifi
- Good to see progress!
- 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.
Hello sangarfe
Thank you for taking the time to contribute your efforts. It probably won't surprise you to learn that a level of automation has been done before
HC-05 Modules however are not specifically BLE (they are Bluetooth version v2 + EDR).
See my website for a tabulation of Modules:
https://www.professorcad.co.uk/appinventortips#TipsBluetooth
Two posts by joao_ramires_diafuco deleted as they are part of a separate Topic.
I have Micropython code that works with the "Serial Bluetooth Terminal" app which is great for getting started but it is very limited.. I downloaded the BLE_ConnectToKnownDevice.aia code and tried "filling in the blanks" for the global variables device name, service UUID and the Rx and Tx UUID's.
In ble_simple_peripheral.py I found what appears to be
device name "mpy-uart".
service UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
Rx UUID "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
Tx UUID "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
I entered these into the KnownDevice code but it doesn't connect or find the device.
Any help would be appreciated.
Thanks,
Pat
Update the BLE extension to the latest version and try again
If you still have issues, provide a screenshot of your relevant blocks
Taifun
I loaded the latest extension earlier this week when I found Chris' code blocks (from 2022?). Based on your advice, I dragged another ble component (ble2) onto screen1 and replaced all the ble1 references with ble2.
Everything works fine now. Thank you so much for your help!
I spoke too soon. The code blocks with the updated ble extension work but the success rate for connecting is about 1 out of every 5 tries. The Micropython code connects 5 out of 5 with the Serial Bluetooth Terminal app. As I stated before, I am using @ChrisWard 's "Connect to a Known Device" blocks. Any suggestions?
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.
To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.
Taifun
Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.