Bluetooth LE - Search only for devices with given names

582 views
Skip to first unread message

Uwe

unread,
May 6, 2019, 4:05:41 AM5/6/19
to MIT App Inventor Forum
Hi,

I already use Bluetooth LE and all works fine, but if I scan for BT devices I got a very big list of devices.
I only want to have devices in the devicelist with specific names. Is that possible?

Thanks,
Uwe

BodyMindPower

unread,
May 6, 2019, 4:59:59 AM5/6/19
to MIT App Inventor Forum
If you want to declare that your app is available to BLE-capable devices only, include the following in your app's manifest:
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>


Anke

TimAI2

unread,
May 6, 2019, 5:04:49 AM5/6/19
to MIT App Inventor Forum
If you know the names you want to see you can filter the list before display using list and text manipulation blocks

Uwe

unread,
May 6, 2019, 1:17:25 PM5/6/19
to MIT App Inventor Forum
Thanks Anke, but I only want to have the names I know in that list, not all BLE-devices.

Uwe

Uwe

unread,
May 6, 2019, 1:18:17 PM5/6/19
to MIT App Inventor Forum
Yes Tim thats exactly what I want to it to do.
Do you have an idea for me on how to do?

Uwe

TimAI2

unread,
May 6, 2019, 4:40:26 PM5/6/19
to MIT App Inventor Forum
You make a list of all your known devices
You get the known addresses back, as a list, from the BLE block
Remove any items in the second list that do not match items in the first list
Use the resulting list in your blocks


Test each item in the BLE returned list to see if it is a thing in your list of devices
If it is, do nothing, if it isn't remove it from the BLE list

Chris Ward

unread,
May 6, 2019, 9:09:07 PM5/6/19
to MIT App Inventor Forum
Hello Uwe

Code snippet on my website:
https://www.professorcad.co.uk/appinventorsnippets#ListFilterSpecific      Filter-Down to a Specific List Required

Uwe

unread,
May 10, 2019, 8:44:11 AM5/10/19
to MIT App Inventor Forum
Thanks all for your help. But it did not work as expected.

I tried the following:


But I always get an error that says:

Actually I do not understand the problem, everything *looks* quite ok.
I don´t undertand the error message.




Chris Ward

unread,
May 10, 2019, 12:58:08 PM5/10/19
to MIT App Inventor Forum
Hi

It is because your List consists of only one item, so the inner "For Each" is not required.

TimAI2

unread,
May 10, 2019, 1:30:01 PM5/10/19
to MIT App Inventor Forum
A bit easier ?

blocksgetknownitems.png


mariano millañanco

unread,
May 10, 2019, 4:39:31 PM5/10/19
to mitappinv...@googlegroups.com

Hola creo que te falta un paso. Proba poner una lista auxiliar quedaría algo así


blocks.png

Uwe

unread,
May 11, 2019, 6:19:49 AM5/11/19
to MIT App Inventor Forum
Hi Chris,

I removed the inner ForEach but get the same result:


Code:


My BLE Modul is called MODUL so I only want to find that one and add to the list.



Uwe

unread,
May 11, 2019, 6:29:00 AM5/11/19
to MIT App Inventor Forum
Hi TimAI2,

I also tried the easier solution but the result is almost the same:


Uwe

unread,
May 11, 2019, 9:04:16 AM5/11/19
to MIT App Inventor Forum
So I found the problem about the runtime error with the "forEach".

The problem is if I use this:
will causes the runtime errors!

If I use this for example (which is useless for me):
It works as expected.

It looks like the forEach didn´t accept the BluetoothLE1.DeviceList as a list.

Is there an chance to use it with the BluetoothLE1.DeviceList?

All others code which was posted here works fine WITHOUT the BluetoothLE1.DeviceList and with a preconfigured list with MakeList.


SteveJG

unread,
May 11, 2019, 9:08:32 AM5/11/19
to MIT App Inventor Forum
Perform a DoIt on the DeviceList Bluetooth Block to see what it contains.  Determine if that is a List or a JSON .

BodyMindPower

unread,
May 11, 2019, 10:19:42 AM5/11/19
to MIT App Inventor Forum



Anke

BodyMindPower

unread,
May 11, 2019, 1:55:02 PM5/11/19
to MIT App Inventor Forum
to get a list try this:

Uwe

unread,
May 12, 2019, 7:43:13 AM5/12/19
to MIT App Inventor Forum
Hi Anke,

thanks for your help. Finally I got this part working. I will only see my "Modul" in the list, BUT ... I cannot connect to it.


The "replace list item" must be used because if not it will lists the same "Module" with different RSSI in one list. To prevent this the "old" received Modul is replaced by the newest one.
But if I want to connect to it it doesn´t connect. I am not sure if this is because of the Index or not. I try to have the last known Index of the last entry of the "Modul" and try to connect
to it but it also doesn´t work. If I just use the ListView without any filtering it works perfect.






BodyMindPower

unread,
May 13, 2019, 2:40:02 PM5/13/19
to MIT App Inventor Forum
What method do you use to connect the BLE device? Show these blocks too or post the aia (upload it to Google Drive, because aia with extensions are not allowed here) .

Uwe

unread,
May 14, 2019, 12:34:30 AM5/14/19
to MIT App Inventor Forum
I just use the following, which works perfectly if I do not use the Filter and list all available BLE Devices in the list:


With the filter the Index is always 1 (because only 1 entry in the list)


BodyMindPower

unread,
May 15, 2019, 3:35:47 AM5/15/19
to MIT App Inventor Forum
The logic in the procedure would have to be adjusted. Esp. if condition <1 should be removed ...

try something like that:



and try to connect with:


Anke

Uwe

unread,
May 15, 2019, 3:45:41 AM5/15/19
to MIT App Inventor Forum
Hi Anke,

the list will show only 1 MODUL as expected, that´s great.
To connect with (changed) MacAdresses but with the same name I integrate the following code:


After that I just connect to the MODUL with


Now everything works the way I want it to work :-)

Thanks to all and specially to Anke for helping me.
Uwe



Reply all
Reply to author
Forward
0 new messages