Closed tbrek closed 4 years ago
Hi @tbrek, thanks for the issue. This is a bit weird.
The code where that notification is generated is in blt.sh
:
../blueutil --connect ${DEVICE}
if [[ $(../blueutil --is-connected ${DEVICE}) -eq 1 ]]
then
./notify.sh -m "Connected to ${TITLE}" -i success
else
./notify.sh -m "Failed to connect to ${TITLE}. Click to retry." -i failure -c "blt.sh ${DEVICE} \"${TITLE}\""
fi
So blueutil apparently says that the device is not connected. Can you please check the following:
./blueutil --recent
./blueutil --is-connected <device_id>
Is the output 1
or 0
?
@./blueutil --recent
address: 88-64-40-e1-f8-5e, connected (master, -52 dBm), not favourite, paired, name: "Tom’s AirPods", recent access date: 2019-10-07 09:48:19 +0000
$ ./blueutil --is-connected 88-64-40-e1-f8-5e
1
It looks like blueutil sees it as connected.
I think I fixed it. Adding sleep 1
helps as the script seems to be too fast, so, if blt.sh
is:
#!/usr/bin/env bash
PARENT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)
cd "${PARENT_PATH}"
DEVICE=$1
TITLE=$2
if [[ $(../blueutil --is-connected ${DEVICE}) -eq 1 ]]
then
../blueutil --disconnect ${DEVICE}
if [[ $(../blueutil --is-connected ${DEVICE}) -eq 0 ]]
then
./notify.sh -m "Disconnected from ${TITLE}"
else
./notify.sh -m "Failed to disconnect ${TITLE}. Click to retry." -i failure -c "blt.sh ${DEVICE} \"${TITLE}\""
fi
else
../blueutil --connect ${DEVICE}
sleep 1
if [[ $(../blueutil --is-connected ${DEVICE}) -eq 1 ]]
then
./notify.sh -m "Connected to ${TITLE}" -i success
else
./notify.sh -m "Failed to connect to ${TITLE}. Click to retry." -i failure -c "blt.sh ${DEVICE} \"${TITLE}\""
fi
fi
It works fine for me.
@tbrek Hm that is interesting. If I am understanding the code behind blueutil correctly, it calls this API: IOBluetoothDevice.openConnection().
Quote from the documentation:
This method is synchronous and will not return until either a connection has been established or the create connection has failed (perhaps timed out).
Afterwards, IOBluetoothDevice.isConnected() is called, which theoretically should yield the same result.
Maybe I should try to not verify the connection via --is-connected
, but rather check the exit code of the --connect
command. It returns either 0 or 1, so should be easy to check. This would be a) faster, and b) hopefully more stable.
@tbrek Can you check if the following version does the trick (without any sleep)? :)
@tilmanginzel your archive complains regards etree.so and doesn't open.
@tbrek Can you check if the following version does the trick (without any sleep)? :)
Yes. That also fixed the issue. Thanks.
@tbrek don't you have issues with etree.so with the above workflow?
@webcoderkz no i don't. Could be Catalina related. I have not upgraded yet.
Ah, i see, i thought you're on Catalina already.
@tilmanginzel please, update your latest workflow for Catalina. Because older version of workflow works (i just updated it using workflow:update
to the latest). If i delete the old workflow, and download 0.5.0 it gives me etree.so error.
Yes. That also fixed the issue. Thanks.
Perfect! I have pushed the fix and released version 0.6.0 :)
@webcoderkz will comment in #9.
When trying to connect my AirPods I'm getting an error message, but they connect successfully: