Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tilt on Buster bluetooth issues? #414

Closed
KnoAll opened this issue Jan 7, 2020 · 22 comments
Closed

Tilt on Buster bluetooth issues? #414

KnoAll opened this issue Jan 7, 2020 · 22 comments

Comments

@KnoAll
Copy link

KnoAll commented Jan 7, 2020

I have been doing a lot of experimenting with Fermentrack and my new Tilt, and after a bit of head scratching, I believe I am running into bluetooth issues on Raspbian Buster. I am running the Dec 29th Fermentrack on two different rPi of the same hardware version 3B+. One has Stretch, and the other Buster. With the same setup/config (only one powered at a time) I see good connectivity in Stretch, and in Buster the Tilt stops logging after 5-15m. It appears to not be the hardware, I have switched the OS between the two different rPi and the issue sticks with the Buster OS version.

@lbussy
Copy link
Collaborator

lbussy commented Jan 8, 2020

@thorrak what I did here is lower the UART baud rate based on a convo with Noah.

do_aioblescan() {
    # Install aioblescan
    local blerepo device fast safe file
    echo -e "\nInstalling BLEacon support via aioblescan."
    blerepo="https://github.com/brewpi-remix/aioblescan.git"
    file="/usr/bin/btuart"
    fast="\$HCIATTACH \/dev\/serial1 bcm43xx 921600 noflow - \$BDADDR"
    safe="\$HCIATTACH \/dev\/serial1 bcm43xx 460800 noflow - \$BDADDR"
    rm -fr "$HOMEPATH/aioblescan"
    git clone "$blerepo" "$HOMEPATH/aioblescan"
    (cd "$HOMEPATH/aioblescan" || exit; python3 setup.py install)
    rm -fr "$HOMEPATH/aioblescan"
    # Slow down uart speeds on < Pi4
    if [ -f "$file" ]; then
        sed -i "s/$fast/$safe/g" "$file"
    fi
    device=$(hciconfig | grep "hci" | grep "UART" | tr -s ' ' | cut -d":" -f1)
    if [ -n "$device" ]; then
        if grep -vq "Pi 4" /proc/device-tree/model; then
            stty -F /dev/serial1 460800
        fi
    fi
}

@KnoAll
Copy link
Author

KnoAll commented Apr 14, 2020

Saw this on Stretch overnight. Rebooted and it re-connected to the Tilt.
(Also shows the spikes in SG from the Tilt)

EDIT: Also just realized that lost connection again around 11:15am.

image

@lbussy
Copy link
Collaborator

lbussy commented Apr 14, 2020

Sort of hard to see what you mean there. Do you mean the Tilt stopped responding? If so, some questions for you since I am seeing something similar in BPR:

  1. How far away from the fermenter is your Pi?
  2. Are you using a SS fermenter?
  3. Can you post the contents of your /usr/bin/btuart?
  4. What version of Pi?
  5. What version of Raspbian?

I believe this is in the Aioblescan, just not sure why yet. It does not happen often enough on my test system to really be able to catch it.

@KnoAll
Copy link
Author

KnoAll commented Apr 14, 2020

Yes sorry, Fermentrack stopped recording Tilt readings.

  1. The fermenter is a stainless conical inside an upright freezer. Originally the BrewPi/Fermentrack was directly on top of the freezer but was not getting any readings from the Tilt. I dangled the Pi/Fermentrack inside the door of the freezer and then started getting signal from the Tilt. So I would say 6" from the top of the conical roughly.
  2. Yes!
  3. fermentrack@raspberrypi:~ $ ls -al /usr/bin/btuart
    -rwxr-xr-x 1 root root 738 Oct 29 2018 /usr/bin/btuart
    fermentrack@raspberrypi:~ $
  4. 3b+
  5. Stretch..
    fermentrack@raspberrypi:~ $ cat /etc/os-release
    PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
    NAME="Raspbian GNU/Linux"
    VERSION_ID="9"
    VERSION="9 (stretch)"
    ID=raspbian
    ID_LIKE=debian
    HOME_URL="http://www.raspbian.org/"
    SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
    BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
    fermentrack@raspberrypi:~ $

@thorrak
Copy link
Owner

thorrak commented Apr 14, 2020

Hmm. Are you running the latest version of Fermentrack?

@lbussy
Copy link
Collaborator

lbussy commented Apr 14, 2020

Would you cat /usr/bun/btuart please?

@KnoAll
Copy link
Author

KnoAll commented Apr 14, 2020

fermentrack@raspberrypi:~ $ cat /usr/bin/btuart
#!/bin/sh

HCIATTACH=/usr/bin/hciattach
SERIAL=cat /proc/device-tree/serial-number | cut -c9-
B1=echo $SERIAL | cut -c3-4
B2=echo $SERIAL | cut -c5-6
B3=echo $SERIAL | cut -c7-8
BDADDR=printf b8:27:eb:%02x:%02x:%02x $((0x$B1 ^ 0xaa)) $((0x$B2 ^ 0xaa)) $((0x $B3 ^ 0xaa))

uart0="cat /proc/device-tree/aliases/uart0"
serial1="cat /proc/device-tree/aliases/serial1"

if [ "$uart0" = "$serial1" ] ; then
uart0_pins="wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\, pins | cut -f 1 -d ' '"
if [ "$uart0_pins" = "16" ] ; then
$HCIATTACH /dev/serial1 bcm43xx 3000000 flow - $BDADDR
else
$HCIATTACH /dev/serial1 bcm43xx 921600 noflow - $BDADDR
fi
else
$HCIATTACH /dev/serial1 bcm43xx 460800 noflow - $BDADDR
fi
fermentrack@raspberrypi:~ $

@KnoAll
Copy link
Author

KnoAll commented Apr 14, 2020

and yes, running the latest version of fermentrack from Master

@lbussy
Copy link
Collaborator

lbussy commented Apr 14, 2020

If this happens often enough that you would notice a difference, edit the usr/bin/btuart file to change the baud rates all to 115200. That would be the end of the file:

if [ "$uart0" = "$serial1" ] ; then
        uart0_pins="`wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' '`"
        if [ "$uart0_pins" = "16" ] ; then
                $HCIATTACH /dev/serial1 bcm43xx 115200 flow - $BDADDR
        else
                $HCIATTACH /dev/serial1 bcm43xx 115200 noflow - $BDADDR
        fi
else
        $HCIATTACH /dev/serial1 bcm43xx 115200 noflow - $BDADDR
fi

Then reboot since I've not bothered to figure out which systemd process it is. See if that helps.

If you are not comfortable making this change by hand, let me know and I can cobble together a command for you.

@KnoAll
Copy link
Author

KnoAll commented Apr 14, 2020

ok, made the changes and rebooted. waiting to see....

@KnoAll
Copy link
Author

KnoAll commented Apr 14, 2020

OK, receiving data, fingers crossed that it is stable!

@lbussy
Copy link
Collaborator

lbussy commented Apr 14, 2020

I've seen it flake out anywhere between a couple of hours and > a day. Here's a graph showing that:

Image Alt

I'd love to find a better way to detect it, but the library is semi-silent on it. It's one of my most annoying issues right now. :) I'm tracking it within my own work as Issue #1.

@KnoAll
Copy link
Author

KnoAll commented Apr 15, 2020

So I have not had a Tilt disconnect since changing the settings. Interestingly, I have also not had a spike in SG either.
image

@lbussy
Copy link
Collaborator

lbussy commented Apr 15, 2020

That's great news! It also gives me a place to go to maybe help generate some additional "bad data" to dind an upstream fix overall,

@KnoAll
Copy link
Author

KnoAll commented Apr 15, 2020

First of all, thanks to both of you for all your effort and work on Fermentrack. LOVING it!
Secondly, what do you typically use/see for logging interval. I think it is set on 30s logging which seems like quite a bit but I'm used to the original BrewPi which was only every 2m.

I'll keep you updated if anything changes.

@lbussy
Copy link
Collaborator

lbussy commented Apr 15, 2020

I don't maintain Fermentrack - I just happen to be using the same libraries in BrewPi Remix so having a larger sample of people is beneficial to both "sides."

The logging interval impacts space and performance. If you are not having issues with either then don't sweat it.

@uSlackr
Copy link
Contributor

uSlackr commented Apr 15, 2020 via email

@lbussy
Copy link
Collaborator

lbussy commented Apr 15, 2020

  1. I'll script a stand-along fix for folks who don't like to or are not comfortable with editing system files.
  2. I'll work with @thorrak to see if he wants to incorporate what will be an upstream fix to him when I get it solved.
  3. This is related to the speed at which the Pi communicates with the BLE devices (or vice-versa in this case.) In a side conversation with the Tilt devs and my own testing, it seems this happens more frequently with Buster (where the speed was increased) and older Pi's (like my Pi 2). It also shows up more when there's more than one Tilt supposedly.

@lbussy
Copy link
Collaborator

lbussy commented Apr 16, 2020

For 2 above: @thorrak you can use this if you like:

INPUT="/usr/bin/btuart"
SEARCHSTRING="\$HCIATTACH /dev/serial1 bcm43xx"

update() {
    while IFS= read -r line
    do
        if [[ "$line" == *"$SEARCHSTRING"* ]]
        then
            baud=$(echo "$line" | tr -s ' ' | cut -d ' ' -f 4)
            eval sed -i 's/$baud/115200/g' "$INPUT"
        fi
    done < "$INPUT"
    echo "$INPUT updated."
}

It will update ALL baud rates in that file (only one would be applicable) to 115200.

For 1 above (a script a few of you can test) you can try this:

curl -L uartspeed.brewpiremix.com | sudo bash

This runs as root (and will reload and run as root if you skip the sudo) because it needs to restart the Bluetooth daemon.

It might take an hour or so for DNS to update so if you get a curl: (6) Could not resolve host: uartspeed.brewpiremix.com error, give it a try after dinner.

@KnoAll
Copy link
Author

KnoAll commented Apr 16, 2020

Still not a single disconnect or spike in SG!

@uSlackr
Copy link
Contributor

uSlackr commented Apr 17, 2020 via email

@thorrak
Copy link
Owner

thorrak commented Jun 20, 2023

Closing this as I believe it has since been resolved. There’s a a new Tilt stack coming with #724 as well, so if this reoccurs after that goes live I want to separate the issue.

@thorrak thorrak closed this as completed Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants