Bluetooth connectivity issues for Android

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

java.io.IOException: Unable to start Service Discovery 

Python script 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 tried all three bluetoothConnect () options, as shown in the code above. If I try the first two connection methods, I can see blueSMiRF in the list of devices to connect.

My arduino sketch (powered by Arduino Mega) is shown below. It simply redirects characters from one port to another. Serial is connected to my 9600 laptop, Serial1 is connected to BlueSMiRF on 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 can use Putty to access blueSMiRF command mode by typing $$$. Everything seems to be in order. I have only a little concern about the settings for the class of service and device class. They are set to factory defaults of 0x0000 and 0x1f00 respectivley, and I wonder if the service class 0x1101 (UUID for SSP) can be set.

Additional information: Android 2.3.3 SL4A r4

+4
source share
2 answers

Switch the RX-TX for blueSMiRF when it talks to the arduino board.

If you can connect to blueSMiRF via a PC, it has the RX-TX setting as an arduino board.

Installing a PC on blueSMiRF:
PC TX → Arduino RX → blueSMiRF RX
PC RX <- Arduino TX <- blueSMiRF TX

Arduino setup for blueSMiRF:
Arduino RX → blueSMiRF TX
Arduino TX <- blueSMiRF RX

0
source

PyBluez module works well overall, and I used it with SL4A without any problems. You might just be able to use this and skip Java altogether.

PyBluez is not a pure Python module, so you need to compile it, but it was done, and the latest version is available from the Py4A downloads site. This is this copy that I use personally, without any problems.

Just download a copy of your droid, open the Python4Android application, click Import Modules and select the PyBluez Egg.

0
source

Source: https://habr.com/ru/post/1379914/


All Articles