RPI3 + Bluetooth

Hi all - I’m working on an application that needs the RPI3 Bluetooth chip enabled on startup. I’ve followed the example from here but am getting exceptionally mixed results.

Typically, the first time I deploy the Resin application to a device, it starts up correctly, but when I deploy updates to the device, the results start to get very mixed.

About 75% of the time, when I run /usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -, the result is:

12.04.17 13:17:59 (-0500) bcm43xx_init
12.04.17 13:18:29 (-0500) Initialization timed out.

If I restart the newly deployed application, it works about 75% of the time after the restart, and almost always works eventually with enough restarts.

Any idea what the root cause of this might be and how we might attempt to resolve?

Thanks

Hey @rmoore, we had some discussion on it here: https://github.com/resin-os/resinos/issues/199.

The thinking is to add this to the host, users don’t have to initialise it. However, I wasn’t aware that the example wasn’t working I thought it always worked the second attempt always caught it, we should update the example to only proceed after a success.

I’ll create an issue and try get it fixed asap. PRs welcome ofc :slight_smile:

Issue: https://github.com/resin-io-projects/rpi3-bluetooth/issues/3

Hi @rmoore,

I have never seen the command fail the second time round which is why we call it twice:

echo "Attaching hci0..."
if ! /usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -; then
    echo "First try failed. Let's try another time."
    /usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -
fi

Does the command fail the second time round for you?
Could you share the relevant section of code so that we can re-produce the issue?

Thanks

Hi Joe - yes, it does fail on the 2nd try fairly often for us.

We’ve tried adding a 3rd try - so far, so good:

echo "Attaching hci0..."
if ! sudo /usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -; then
    echo "trying again..."
    if ! sudo /usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -; then
        echo "trying again..."
        sudo /usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -
    fi
fi

With the 3rd try it does seem more reliable - we’ll continue to test.

@rmoore do you mind sharing more info, like the base image you are starting from and the Bluetooth related packages / dependencies you are installing in your Dockerfile?

I’ve used the following code to get bluetooth up and running:

until /usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -
do
    echo "Initializing bluetooth failed."
    sleep 5
done
hciconfig hci0 up

So more or less, run hciattach until it succeeds.

1 Like

Looks like a good solution, thanks kipe!

@rmoore @kipe you might want to add an escape mechanism if BT goes nuts in order to avoid an infinite loop tho :stuck_out_tongue:

@curcuz not if your application is dependent on BT :wink:

But yeah, if not, I suggest an escape mechanism also…