4
votes

I'm trying to get a simple python script running on my Andorid phone (using SL4A) to connect to a BlueSMiRF bluetooth modem (based on an RN41 device), however no matter what I try I keep getting the following error when I try to connect.

java.io.IOException: Unable to start Service Discovery

The python script is shown below

import android

droid = android.Android()
droid.toggleBluetoothState(True)

result = droid.bluetoothConnect()
#result = droid.bluetoothConnect('00001101-0000-1000-8000-00805f9B34fb')
#result = droid.bluetoothConnect('00001101-0000-1000-8000-00805f9B34fb', '00:06:66:07:AE:44')

print repr(result)

droid.toggleBluetoothState(False)

I have tried all three variations of bluetoothConnect() as shown in the code above. If I try the first two methods of connecting I can see the blueSMiRF in the list of devices to connect too.

My arduino sketch (running on an Arduino Mega) is shown below. It simply forwards the characters from one port to another. Serial is connected to my laptop at 9600, Serial1 is connected to the BlueSMiRF at 115200.

void setup ()
{
  // initialise serial
  Serial.begin(9600);  
  Serial1.begin(115200);  
}

void loop ()
{

  if (Serial1.available())
  {
    char c = Serial1.read(); 
    Serial.print(c); 
  }

  if (Serial.available())
  {
    char c = Serial.read();        
    Serial1.print(c); 
  }
} 

I am able to use Putty to access the blueSMiRF's command mode by typing $$$. Everything appears to be okay. I only have slight concerns about the settings for the Service Class and Device Class. These are set to the factory default values of 0x0000 and 0x1f00 respectively and I wonder if the service class might need to be set to 0x1101 (UUID for SSP).

Other info: Android version 2.3.3 SL4A r4

2
You might want to try asking on the Py4A mailing list or checking the Py4A issues.Velociraptors

2 Answers

0
votes

Switch RX-TX for the blueSMiRF when it shall talk with the arduino board.

If you are able to connect to the blueSMiRF through the PC it has RX-TX setup as the arduino-board.

PC to blueSMiRF setup:
PC TX --> Arduino RX --> blueSMiRF RX
PC RX <-- Arduino TX <-- blueSMiRF TX

Arduino to blueSMiRF setup:
Arduino RX --> blueSMiRF TX
Arduino TX <-- blueSMiRF RX

0
votes

The PyBluez module works well in general and I've used it with SL4A with no problems. You may have better luck just using that and skipping the Java altogether.

PyBluez is not a pure Python module, so it has to be compiled, but this has been done and a recent version is available from the downloads section of the Py4A site. It's this copy that I use personally, without any issues.

Just download a copy to your droid, open the Python4Android app, hit Import Modules, and select the PyBluez egg.