T_Leaf
Posts: 1
Joined: Wed Jan 03, 2018 1:52 am

Raspberry Pi Zero: Bluetooth connection continuously repeats data

Wed Jan 03, 2018 2:42 pm

My son and I spent a few days solving this problem on my new Raspberry PI Zero. Here is the solution in case it's helpful to others.

Running: Linux raspberrypi 4.9.59+ #1047 Sun Oct 29 11:47:10 GMT 2017 armv61

We successfully connected to an ELM327 device over bluetooth. The ELM327 was connected to my 2014 Nissan Leaf OBD port.

On the Linux console we issued

Code: Select all

sudo rfcomm bind rfcomm0 AA:BB:CC:11:22:33
cat /dev/rfcomm0 | tr '\r' '\n'

The output from cat was continuous until stopped with <ctl> c and started with:

Code: Select all

+CONNECTING<<A4:34:D9:37:CE:EE
?

>NECTED
?

>+CONNECTING<<A4:34:D9:37:CE:EE
?

>?
?

>
?

>>NECTED
?

>
?

>
?

>+CONNECTING<<A4:34:D9:37:CE:EE
?

>?
?

>
?

>>?

We used tshark to determine that Linux was echoing everything received over Bluetooth back to the ELM327 which echoed it back and so on.

As an alternative to cat we then used picocom with the following options which worked properly.

Code: Select all

sudo picocom --imap crcrlf --omap lfcr  /dev/rfcomm0

Issuing stty before and after using picocom we discovered that it was setting attributes on /dev/rfcomm0 which were fixing the problem.

Code: Select all

stty -F /dev/rfcomm0 -a

Our current solution is to use stty to correct the offending attributes each time we connect. We do it each time to ensure the attributes are correct because the attributes are reset when Linux boots. Note that the /dev/rfcomm0 bind must be created before stty can set the attributes. The release and final bind must be done to ensure the new attributes are used.

Code: Select all

sudo rfcomm bind rfcomm0 AA:BB:CC:11:22:33 
stty -F /dev/rfcomm0 clocal -icrnl -ixon -opost -isig -iexten -echo -hupcl
sudo rfcomm release  rfcomm0
sudo rfcomm bind rfcomm0 AA:BB:CC:11:22:33 

I'd love to hear from others who can explain was this is necessary and/or who have a better/simpler solution.

Return to “Troubleshooting”

Who is online

Users browsing this forum: cobrafast1, Gavinmc42 and 19 guests