I want to connect my Android Phone (2.3.6 Samsung Note) to an embedded Bluetooth device (RN-42 BT UART module on Arduino). Started with BluetoothChat example and have the embedded device paired with the phone. So far all seems to work fine, the devices get connected and data is passed from Android to embedded device. What I am still missing is to make the devices connect automatically once the two are in range.
Using the debugger I see the embedded device is "Host" or in it's term "Slave" and the Android being a client, as the Android issuing a connect request.
Best Answer
I have a similar configuration (Android Galaxy S3 phone 4.0 and RN-42 BT connected to Arduino Uno) I am able to pair the Android and the bluetooth and to connect from the Android to the RN-42 BT (I am using the BlueTerm app to test that) However, I'm unable to connect from the RN-42 BT to the Android phone. I followed the innstructions and the code example in: http://www.instructables.com/id/Missed-calls-and-SMS-Notifier-Accessory/
I programmed the 42 BT to serve as a client and set it to Auto connect mode (SR,3). In my Android code, the BluetoothSerialService (equivalent to the PhoneInfoServer example code) is stuck in the AcceptThread on: socket = mmServerSocket.accept(); I'm attaching the following pieces of codes that are related to the connection problem:
In Google's BluetoothChat demo app there is an option to make the phone discoverable so that another phone can connect to it. I am looking for something similar for bluetooth serial connection. I looked for an app on Google Play that will test listenning to an incoming connection request from a bluetooth serial device, but didn't find such an app. Does someone know of such an app?
Regards, Avner
Arduino code that sets the connection mode to auto and initiates a connection with the Android phone
Android
BluetoothSerialService AcceptThread
code that listens to incoming connectionlogcat messages that show that the code is stuck waiting for incoming connection
I further discovered that the RN-42 BT is getting into auto-connect mode but tries to connect to another non-android LG phone at the house.
I discovered this by reseting the RN-42 BT to the factory defaults. Using the BlueTerm app I successfully connect from the Android phone to the RN-42 BT. When I perform an inquiry scan ($$$I\r) I get the mac address and the name of the LG phone. This phone has a bluetooth with a different mac address (0026e25d8a91) - I don't know what causes the RN-42 BT to try and connect with this device.
This means that the auto connect mode does work but the connection is directed to the wrong phone. I'm pazzled because I'm specifying the mac address of the Android phone using the following commands (with delays between them)
I am now thinking that the connection initiation from the RN-42 BT is Ok but that the BluetoothServerSocket on the android code is not set up properly.
I have tried setting the BluetoothServerSocket to listen using listenUsingInsecureRfcommWithServiceRecord and listenUsingRfcommWithServiceRecord. I notice that there is a command createInsecureRfcommSocketToServiceRecord. Should I use it instead?
Any advice would be greatly appreciated.
Thanks, Avner