Android Bluetooth Serial/RFCOMM/SPP, How to Change the BAUD RATE?
Asked Answered
O

2

10

This is very frustrating as I've been trying for weeks and not even a clue on the internet.

I am working on a project that reads/writes bluetooth serial data on different farming hardware.

most of these hardware are old and changing the baud rate of their SPP is not an option.

I'm using the android bluetooth chat as a basis to read/write, I've only changed the UUID to allow connection to the devices I have

I've managed to read from a tag reader at a bad rate of 19,200 beautifully, and formatted nicely

However, I'm stuck now with the scales which has a baud rate of 9,600 and shows funny characters in my app, not even close to the format that should come from the scales

This project was done previously on a old Windows Mobile and baud rates could be changed in their API

Is there a way to do this in Android or am I barking up the wrong tree?

Overt answered 7/4, 2011 at 5:4 Comment(0)
U
2

Presumably some Bluetooth to serial converter is attached to the legacy devices? If so you should be able to program it once to always use a particular bit rate. Then there would be no need for the Bluetooth client to set the bit rate...

Undoing answered 7/4, 2011 at 9:22 Comment(2)
thank you! I managed to set the baud rate of the physical connection between the device and the bluetooth adaptor. it works like a charm now! I came to realise that there are no baud rates to tinkle with when it comes to bluetooth connectionsOvert
@Zigi how actually did you manage to set the baud rate of physical connection ? I have a similar problem and stuck at 9600bps at the moment. I have configured the printer baud rate to 115200bps but still very slow and it doesn't look like setting printer baud rate affacted anything..Witkowski
M
10

Edit: Fixed some errors.

There's no good information on the internet about this - and lots of it is wrong - don't trust anyone!

In particular, these two things are not true:

  • RFCOMM and SPP (Serial Port Profile) are two names for the same thing. (They are however very closely related.)
  • There's no need to set the baud rate of an RFCOMM / SPP connection.

Here is what I have found:

Bluetooth serial connections are made as described in the SPP using RFCOMM. RFCOMM is a connection that runs over L2CAP and allows sending serial data and control parameters in frames. It is heavily based on an ancient standard called TS 07.10. SPP is the bluetooth profile.

This framing also allows you to send out-of-band data for things like controlling serial signals (DTR, CTS, etc) and for setting the baud rate.

From the SPP specification:

DevA may inform DevB of RS232 port settings with the Remote Port Negotiation Command, directly before DLC establishment. There is a requirement to do so if the API to the RFCOMM adaptation layer exposes those settings (e.g. baud rate, parity).

Sadly Android doesn't expose this functionality at all. I suppose it may be possible to send the Remote Port Negotiation command ourselves but I'm pretty sure that would require reimplementing RFCOMM which requires access to L2CAP that we don't have.

The Remote Port Negotiation command is detailed here page 31. Note "There are default values assigned on all parameters, if no negotiation is performed, the default value is chosen."

Therefore it is impossible to set the baud rate as desired on Android. It will use the default baud rate that your bluetooth adapter uses (probably 9600).

Also note that Windows does support setting the baud rate of bluetooth adapters.

Menial answered 27/5, 2014 at 12:3 Comment(6)
I changed the baud rate of my ELM 327 Bluetooth OBD-2 adapter ($10 Chinese ELM clone) from its default 38400 to 230400 - Android will pair with the device but when I use a terminal app that worked before I get no response from the device at all... I wonder whether the device is bricked or if there is a way to make it work again (on whatever system/OS). I have similar OBD-2 adapter with USB and that works with 230.4k.Catch
If you can I would try testing at 115200 or below since those rates are more common. There might be some code in the path that thinks you can't go above 115200.Menial
Well the problem is I am not really able to set the baud rate on the receiver (Android)... the only app I found that may be able to set it play.google.com/store/apps/… will not connect to the device that is paired in OS (requires BT PIN over and over again). I did not test in pure Linux (laptop) with BT dongle yet. Can Linux (not Android) set BT baud rate? The bad thing is that there is no reply in other terminal apps (those who cant set the rate) - if the device was alive it would at least send back something even on wrong input command...Catch
I haven't tested on Linux but I would expect it can. You definitely can't set the baud rate on Android. I expect that app is referring to USB serial adapters which it apparently also supports.Menial
Such a shame that remote port negotiation isn't possible on Android! Also, it's thoroughly odd how this is barely documented and Google doesn't even seem interested in acknowledging requests related to the feature, marking them as obsolete instead (here and here).Savoirfaire
@Catch I'm afraid 'Serial Terminal' for android cannot set speed of bluetooth connection. I was able to check the code for this application. It ignore bluetooth options.Nippers
U
2

Presumably some Bluetooth to serial converter is attached to the legacy devices? If so you should be able to program it once to always use a particular bit rate. Then there would be no need for the Bluetooth client to set the bit rate...

Undoing answered 7/4, 2011 at 9:22 Comment(2)
thank you! I managed to set the baud rate of the physical connection between the device and the bluetooth adaptor. it works like a charm now! I came to realise that there are no baud rates to tinkle with when it comes to bluetooth connectionsOvert
@Zigi how actually did you manage to set the baud rate of physical connection ? I have a similar problem and stuck at 9600bps at the moment. I have configured the printer baud rate to 115200bps but still very slow and it doesn't look like setting printer baud rate affacted anything..Witkowski

© 2022 - 2024 — McMap. All rights reserved.