Bluetooth Scan

205 views
Skip to first unread message

RGeB

unread,
Sep 1, 2022, 11:18:27 PM9/1/22
to Automate
Thanks Henrik for the advice about Bluetooth 'profile' SPP.
Follow-up question: Is there any way to make Bluetooth Scan a Yes/No action block?

I am trying to make the flow go in different directions depending on whether a bluetooth device is on in range (you guessed it; an OBD device using Bluetooth 'profile' SPP, but that is probably not relevant as it is the only paired device and it does show in Android and in Automate).

RGeB

unread,
Sep 2, 2022, 3:00:58 AM9/2/22
to Automate
I worked some of it out, but not all. Here is what I have tried:
1. Add an Enable BT Block and a Delay 1s block (to avoid Java errors when BT device scan is run).
2. Add BT device scan, type btaddresses in the field called Array of device addresses. This creates a user variable called btaddresses. Try active discovery as the Scan Mode.
3. Add an Expression true? block, and type contains(btaddresses, "<the address of my BT device shown in an Automate BT device connect block after pressing PICK DEVICE>").

There are more blocks, (and flows works when these are used alone), but the Expression true? block always gives NO, even though Automate can find the BT device in a BT device connect block after pressing PICK DEVICE. I have tried Active low latency in Scan Mode, but it gives the same result (always NO). What am I doing wrong?

Henrik "The Developer" Lindqvist

unread,
Sep 2, 2022, 7:27:19 AM9/2/22
to Automate
To debug, insert an Log append block before the Expression true block to log the btaddresses variable so it actually contains the address you're looking for, also ensure it has the same letter case as logged.

RGeB

unread,
Sep 2, 2022, 6:06:21 PM9/2/22
to Automate
Thanks Henrik, I was wondering if there was a way to see a block output; so now I understand that is what Log append does.
I added a Log append block and typed btaddresses in the message box I was careful to use the same case as the user variable).
The log then shows an extra line (for Log append) but it just shows the word btaddresses, no array.
I also added a variable btnames in the BT device scan field called Array of device names, and tried typing btnames, btaddresses in the Log append message box: same effect, the Log just echoed 'btnames, btaddresses' and showed no arrays.
I tried it again with Scan modes Active low latency, Active low energy and Active discovery: all gave the same outcome.

Am I doing something wrong in use of Log append, or does this mean that Automate BT device scan can not see a BT device that is shown in Automate BT device connect?

RGeB

unread,
Sep 2, 2022, 6:26:38 PM9/2/22
to Automate
I guess it is a clue that Automate BT device connect block PICK DEVICE shows the paired BT device whether or not that paired device is powered.
So probably Automate BT device scan can not see that paired BT device, even when it is powered and broadcasting (blue light flashing) using profile SPP?

RGeB

unread,
Sep 3, 2022, 3:04:00 AM9/3/22
to Automate
Just out of interest, the Bluetooth Scanner app (by Zoltan Pallagi) does find the BT device (only when the device is waiting for pairing, not while waiting for connection), but Automate does not find it at exactly the same time. I guess Automate can not do what I hoped, but I really appreciate the app and the willingness of Henrik the developer to advise people who do not know the inner workings of the OS or the app.

Henrik "The Developer" Lindqvist

unread,
Sep 3, 2022, 6:31:38 AM9/3/22
to Automate
You need to click the fx icon to write an expression, e.g.  a variable name, please read:

Henrik "The Developer" Lindqvist

unread,
Sep 3, 2022, 6:38:42 AM9/3/22
to Automate
Automate should be able to scan any old-style "discoverable" Bluetooth device, or Low-energy "advertising" BT device.
But i guess the "Scanner" app is only running in the foreground while the screen is turned-on, which always works.
In contrasts Automate is running in the background all the time, even when the screen is turned off, some phones don't support that.

RGeB

unread,
Sep 3, 2022, 6:51:52 PM9/3/22
to Automate
If I understand:

1. In the Bluetooth scan block one does not click the fx icon (it is not mentioned in the documentation).
2. In the Log append block one does click the fx icon (even though it is not mentioned in the documentation). Anyhow, it makes no difference, the block now shows "btaddresses" but the log still just shows btaddresses and no array (even when the device has been found, as in * below).
3. The Expression true? block is automatically an expression (there is no fx icon to click).

* I must correct something from a post above: Automate does find the device (only when the device is waiting for pairing, not while waiting for connection) in Automate Active Discovery Scan Mode (but not in any other Active Scan Mode). Sorry, I did not try all these permutations before.

Bluetooth profile SSP may not be hard-coded in Android (yet), but it is certainly not precluded from use in Android. Every Android OBD app that I know can connect to a bluetooth OBD interface device that uses only SPP. Automate includes many capabilities not hard-coded in Android but not (yet) ability to detect an SPP bluetooth device that is on and waiting for connection.

Even though Automate does not do everything I hoped, it is still useful.
I hope this thread helps other users (who may not be developers, but are also likely not idiots - they just need instructions that are clear to non-developers).
Thanks again to Henrik (the developer) for all the help.

Henrik "The Developer" Lindqvist

unread,
Sep 4, 2022, 6:41:04 AM9/4/22
to Automate
  1. If the field has an = prefix, and the fx button itself isn't crossed/stroked, then it's in "expression mode", accepting an expression, as mentioned in the documentation. Trivia, this is inspired by how Microsoft Excel works.
  2. Every input argument field has an "expression" mode, so does Log append, see #2. Your block actually logging the variable name "btaddresses" is most likely caused by you writing the name in "constant" (text) mode, not "expression" mode.
  3. Indeed, it's always in "expression" mode as a convenience, since evaluating a constant expression will always have the same result, i.e. pointless so none should even need it.
If the device is only found in "discovery" then probably doesn't support Bluetooth Low-Energy (BLE).

Agreed, individual app can likely implement SPP atop existing APIs, but as said, there's no way for a third-party app, e.g. Automate, to detect nor manage such connections.

RGeB

unread,
Sep 4, 2022, 6:57:56 PM9/4/22
to Automate
2. No, the problem is most likely a bug in Automate. Try it and you might see.

Henrik "The Developer" Lindqvist

unread,
Sep 5, 2022, 4:51:15 AM9/5/22
to Automate
Very unlikely, as such a severe issue would have be reported.
Please post the flow so i can investigate.

cartler

unread,
Jan 3, 2023, 12:48:22 PM1/3/23
to Automate
Try using a 'for each' block to loop through every address in the output array and compare it with the address you are checking for.
And if that doesn't work, also make sure you have 'scan mode' set to 'active discovery' and uncheck 'only include paired devices,' as that's what I have confirmed works.
Reply all
Reply to author
Forward
0 new messages