I'm currently working on an Android application based on Bluetooth Chat sample. The code seems to work but when I try to pair my android device (a Samsung Ace GT-S5839i) with my laptop, some drivers fail to install.
In the device bluetooth services list I can see BluetoothChatSecure and BluetoothChatInsecure services but when I try to connect my phone to my laptop I have a connection error.
This is my first time doing any Bluetooth development, and I can't figure out what happens.
EDIT:
Actually I have several errors:
08-11 01:34:49.140: E/BluetoothChat(29847): + ON RESUME +
08-11 01:34:49.187: E/BluetoothEventLoop.cpp(1510): onCreateDeviceResult: D-Bus error: org.bluez.Error.AlreadyExists (Device already exists)
08-11 01:34:49.203: E/DTUN_HCID4(29886): No device pointer found for peer! Ignore Error = true. Ignoring error...
08-11 01:34:49.421: E/(29869): ****************search UUID = 87fa***********
08-11 01:34:50.179: E/BluetoothEventLoop.cpp(1510): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/29886/hci0/dev_70_F1_A1_B7_61_A8
08-11 01:34:54.304: E/BluetoothEventLoop.cpp(1510): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/29886/hci0/dev_70_F1_A1_B7_61_A8
P.S.
Does anybody know why Windows tried to install two Bluetooth Peripheral Device without finding the right drivers when I used the default uuid?
I finally set up a bluetooth secure connection between my phone and my laptop. These are the required steps:
First, I set up a Bluetooth Icoming COM port in my laptop
Secondly, I changed my uuid according to the [android documentation][2]
Hint: If you are connecting to a Bluetooth serial board then try using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.
Then I enabled the SSP service in my phone so I was able to get the
Standard Serial over Bluetooth link working
Finally, I open a serial connection with the Icoming COM port through
a Hyperterminal (like putty)
I hope this is helpful to someone.
Related
I am willing to create a server and client program on my android mobile devices.
The devices communicate with each other on the same wifi network, therefore, some simple scanning mechanism must be implemented - The client phones search for a server phone through some kind of broadcast.
What I did:
My protocol - the client phone broadcasts a message port p on the wifi, the server listens on port p. when the server gets the broadcast message it sends a message back, therefore discovering itself to the client.
My code -
I have opened a broadcast socket on my app, it sends a broadcast message.
Meanwhile there is a python script on my PC that listens and replies - I use python so that my testing will be easier - Wireshark on the PC and I can see everything.
What happens:
When I use one of my Galaxy S phones - it works and I get a response.
When I use the other Galaxy S phone - it doesn't work.
Now this is what I know:
The phone that works actually has Nexus ROM on it Ver. 4.1.1
The phone that doesn't work has 2.3.3 regular galaxy ROM
The python code says it receives both of the broadcasts sent from both phones, and replies to both of them without raising any exception.
So far I was thought the problem may be
1. the older version'd phone.
2. the windows firewall
3. the router firewall
So I have opened Wireshark, and Indeed I saw that both phones are sending their broadcasts - it was logged on Wireshark.
But the python script only responded to the first one.
So this is why 1 & 3 are irrelevant - if the router firewall was blocking my UDP I would have still seen the python server response, same with the older versioned phone.
To get rid of 2 i just disabled the windows firewall - still same problem.
Does anyone has a clue to why this effect might happen?
Thanks!
Edit
My python code:
def scan(data, addr, sock):
print "received scan message:", data, addr
name = u"name".encode("utf-16-le")
data = "DISC" + short2bytes(len(name)) + name
print "sending back %s to %s" % (data, addr)
sock.sendto(data, addr)
if __name__ == "__main__":
sock = socket(AF_INET, SOCK_DGRAM)
sock.bind(('', UDP_PORT))
while 1:
data, addr = sock.recvfrom(1500)
print "received packet " + data
if data.startswith("SCAN"):
scan(data, addr, sock)
edit 2:
Okay! Seems like my code and protocol DID work.
As it turns out the 2.3.3 phone had some severe ARP problems.
After some resets it works flawlessly!
I use this code
luugiathuy.com/2011/02/android-java-bluetooth/
The server side is the PC
the client is the device, with the app based on bluetooth chat example
The device (galaxy tab 7.0) can establish connection with the PC.
However the PC server (written in java and bluecove) did nothing, as nothing is connected.
The loop for trying to find connected device is
while(true) {
try {
System.out.println("waiting for connection...");
connection = notifier.acceptAndOpen();
Thread processThread = new Thread(new ProcessConnectionThread(connection));
processThread.start();
} catch (Exception e) {
e.printStackTrace();
return;
}
Output on PC:
uuid: 0000110100001000800000805f9b34fb
waiting for connection...
EDIT: source downloadhttps://github.com/luugiathuy/Remote-Bluetooth-Android
Same issue I got when I was trying in linux. But the reason (still not sure) when you run the bluetooth android application without turning on the Java server using bluecove, It will try to connect with the already installed bluetooth software. You may see the bluetooth icon asking for granting access to the mobile device.
To solve this, I just changed the uuid in the server and application (say from 1103 to 1101 and vice versa) and then started the server first and then the android application. Java server part started listening.
The reason I think may be the uuid when it did not found the bluecove stack service server, it got connected to the device server listening on same uuid. So after changing the uuid and making sure that the server is running before launching the android application should solve the issue.
If you are getting connected to the bluetooth system application and not to the Java bluecove server,
1) First change the uuid both server and android application.
2) Second make sure your server is running and listening on same uuid.
3) Launch the android application which try to communicate on same rfcomm connection uuid.
Server part code I took from : http://www.jsr82.com/jsr-82-sample-spp-server-and-client/
Library : http://code.google.com/p/bluecove/downloads/list
Yes, it happens with me too, I suggest you to fire following commend on shell, when it shows waiting for connection.
hcitool cc 58:C3:8B:D7:FA:F4
here 58:C3:8B:D7:FA:F4 is my device's bluetooth address, which should be replaced by your device's bluetooth address.
To get your device's bluetooth address, just start bluetooth in your device with discoverable mode and execute hcitool scan command, it will display all the active device with their name and bluetooth address.
Well you may run the above hcitool cc 58:C3:8B:D7:FA:F4 command via Java code as follows,
try
{
Process p=Runtime.getRuntime().exec("hcitool cc 58:C3:8B:D7:FA:F4");
}
catch ( Exception e )
{
}
The output from your program says it listens on UUID 0x1101. Is that true? The sample you reference shows it listening on a different UUID. Its Service Class Id is 0x04c6093b and is set as follows:
34 UUID uuid = new UUID(80087355); // "04c6093b-0000-1000-8000-00805f9b34fb"
35 String url = "btspp://localhost:" + uuid.toString() + ";name=RemoteBluetooth";
36 notifier = (StreamConnectionNotifier)Connector.open(url);
The two need to match on client and server.
When I connect my laptop to my Android phone, the computer aways shows me this error :
1827 Data Router usb connection is true
1827 Data Router DSR is on Don't send DTR on
My phone is galaxy II with Android 4.03.
According to my search:
DSR=Data Set Ready DCE (Data Carrier Detect) is ready to receive commands or data.
DTR=Data Terminal Ready Indicates presence of DTE to DCE.
This is not an application error, this is spam in your log from the system. It's okay to ignore unless you're working on the phone's hardware.
I wrote a little application for Android 2.3 using Eclipse Galileo.
The application is based on Bluetooth Chat example published on Google.
The problem is that bluetooth connection fails.
I connect my Android with Bluetooth access point via SPP - serial port profile).
The reasons why the connection fails are not clear for me.
I see the following in logs:
10-09 18:52:35.989: ERROR/BluetoothEventLoop.cpp(162): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/18286/hci0/dev_00_1A_7D_0A_B7_5F
10-09 18:58:35.239: ERROR/(18269): ****************search UUID = 1101***********
10-09 18:58:35.489: ERROR/BluetoothEventLoop.cpp(162): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/18286/hci0/dev_00_1A_7D_0A_B7_5F
10-09 18:58:35.529: ERROR/BluetoothEventLoop.cpp(162): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/18286/hci0/dev_00_1A_7D_0A_B7_5F
10-09 18:58:35.669: ERROR/BLZ20_WRAPPER(20769): ##### ERROR : btlif_process_con_rsp: no bt sock found, scn 1#####
Any help is appreciable
I think it may be related to a bug in the samsung bluetooth stack related to SSP connections.
check this link out:
http://www.samsunggalaxysforum.com/firmware-problems/connection-problems-sgs-bluetooth-spp-device/
One solution I had was if I detected a blutooth error in my app on a samsung device in software I would turn off the bluetooth wait 5 seconds and turn it back on.
I think you using wrong UUID
UUID should be 00001101-0000-1000-8000-00805f9b34fb
If UUID is wrong not able to connect.
I am trying to use the Bluetooth Chat sample API app that google provides to connect to a bluetooth RS232 adapter hooked up to another device. Here is the app for reference:
http://developer.android.com/resources/samples/BluetoothChat/index.html
And here is the spec sheet for the RS232 connector just for reference:
http://serialio.com/download/Docs/BlueSnap-guide-4.77_Commands.pdf
Well the problem is that when I go to connect to the device with:
mmSocket.connect(); (BluetoothSocket::connect())
I always get an IOException error thrown by the connect() method. When I do a toString on the exception I get "Service discovery failed". My question is mostly what are the cases that would cause an IOException to get thrown in the connect method? I know those are in the source somewhere but I don't know exactly how the java layer that you write apps in and the C/C++ layer that contains the actual stacks interface. I know that it uses the bluez bluetooth stack which is written in C/C++ but not sure how that ties into the java layer which is what I would think is throwing the exception. Any help on pointing me to where I can try to dissect this issue would be incredible.
Also just to note I am able to pair with the RS232 adapter just fine but I am never able to actually connect. Here is the logcat output for more reference:
I/ActivityManager( 1018): Displayed activity com.example.android.BluetoothChat/.DeviceListActivity: 326 ms (total 326 ms)
E/BluetoothService.cpp( 1018): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)
D/BluetoothChat( 1729): onActivityResult -1
D/BluetoothChatService( 1729): connect to: 00:06:66:03:0C:51
D/BluetoothChatService( 1729): setState() STATE_LISTEN -> STATE_CONNECTING
E/BluetoothChat( 1729): + ON RESUME +
I/BluetoothChat( 1729): MESSAGE_STATE_CHANGE: STATE_CONNECTING
I/BluetoothChatService( 1729): BEGIN mConnectThread
E/BluetoothService.cpp( 1018): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)
E/BluetoothEventLoop.cpp( 1018): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/1498/hci0/dev_00_06_66_03_0C_51
I/BluetoothChatService( 1729): CONNECTION FAIL TOSTRING: java.io.IOException: Service discovery failed
D/BluetoothChatService( 1729): setState() STATE_CONNECTING -> STATE_LISTEN
D/BluetoothChatService( 1729): start
D/BluetoothChatService( 1729): setState() STATE_LISTEN -> STATE_LISTEN
I/BluetoothChat( 1729): MESSAGE_STATE_CHANGE: STATE_LISTEN
V/BluetoothEventRedirector( 1080): Received android.bleutooth.device.action.UUID
I/NotificationService( 1018): enqueueToast pkg=com.example.android.BluetoothChat callback=android.app.ITransientNotification$Stub$Proxy#446327c8 duration=0
I/BluetoothChat( 1729): MESSAGE_STATE_CHANGE: STATE_LISTEN
E/BluetoothEventLoop.cpp( 1018): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/1498/hci0/dev_00_06_66_03_0C_51
V/BluetoothEventRedirector( 1080): Received android.bleutooth.device.action.UUID
The device I'm trying to connect to is the 00:06:66:03:0C:51 which I can scan for and apparently pair with just fine.
The below is merged from a similar question which was successfully resolved by the selected answer here:
How can one connect to an rfcomm device other than another phone in Android?
The Android API provides examples of using listenUsingRfcommWithServiceRecord() to set up a socket and createRfcommSocketToServiceRecord() to connect to that socket.
I'm trying to connect to an embedded device with a BlueSMiRF Gold chip. My working Python code (using the PyBluez library), which I'd like to port to Android, is as follows:
sock = bluetooth.BluetoothSocket(proto=bluetooth.RFCOMM)
sock.connect((device_addr, 1))
return sock.makefile()
...so the service to connect to is simply defined as channel 1, without any SDP lookup.
As the only documented mechanism I see in the Android API does SDP lookup of a UUID, I'm slightly at a loss. Using "sdptool browse" from my Linux host comes up empty, so I surmise that the chip in question simply lacks SDP support.
Ok the short answer is I had to use this UUID in order to connect to my SPP device:
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
I tried to change it since I thought that only the "1101" part was important since I see that mentioned with SPP stuff all over the place on the intertubes but that made it not connect again. Apparently that specific UUID is what is supposed to be used to connect to generic SPP devices. Anyway just figured I'd post it up here so anyone who this sort of problem has an answer. Took me about 3 days to find it LOL!
I guess it is related to a sony-ericsson phones bug (see here).
I was able to connect from/to an android 2.0 device and my mac using bluetooth and a totally made-up UUID. Trying to make the same thing with a j2me device (a sony ericsson w910i) was working only if the android was the server, otherwise I get the same exception as you.
The UUID you are using, as far as I know, is a "base address" for the spp profile, and in the ServiceClassIDList field of the ServiceRecord returned by the server device when issuing a service discovery, it should be listed AFTER the UUID you decided to use..apparentely this is not the case in some situations (e.g. my phone first listed the generic UUID and then my custom UUID).
Looks like it's the same situation here.
You can try to manually change the ServiceRecord and return the proper ServiceClassIDList. Maybe it will work for you..unfortunately, my stupid cell phone refuse to change it :(
PS. a strange thing is that my mac is indeed able to see the service, even if the ServiceRecord is "broken", I guess that android just bother to see the first UUID in the ServiceClassIDList, while my pc go through the list searching every element. But this is just my supposition :)
The baud rate you set must match the device it's hooked to. They have the default 115200 or switch to 9600 but if you need other (1200 in my case for a survey instrument) you need to set that up through hyperterminal* and a null modem cable.
*Though the docs for the bluesnap device suggest using hyperterminal there are issues with it. After a few calls to bluesnap, they suggested:
First, when connecting the device to a PC, try putting the Jumper settings back to their original positions using 115200 8, N, 1 and X off. When DTE enabled, a terminal connection cannot be established without using special software specifically designed for DTR/DTE connections.
Second, HyperTerminal has known issues with the BlueSnap. I would recommend trying TeraTerm or PuTTY.
took me 4 days to find this out!
What baud rate do you have your bluetooth device set at? I'm connected, but my data is showing up as the typical garbled mush you get with mixed baud rates. I have mine set to 57600, this is what I've seen other folks use. Oh, thanks for posting your results the UUID had me working for a few days as well.
If 'sdptool browse' reports no information about the device try 'sdptool records [device-mac-here]'