Samsung / TizenFX

C# Device APIs for Tizen

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bluetooth] Can't create RFCOMM socket with given port number

Csaba8472 opened this issue · comments

I'd like to achieve something like this with Tizen.Network.Bluetooth:

s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)  
s.connect((device, port)) 
s.recv(128)

This is written with PyBluez, it creates a socket, connects to the device at the given port and receives data.

I've run into two issues:
1, I can't create socket without defining UUID.
IBluetoothClientSocket CreateSocket(string serviceUuid);
I've used HFP UUID, I don't know whether it is a proper workaround or not.

2, IBluetoothClientSocket.Connect doesn't have port property, so I don't know which port will be used.

When I set HFP UUID and just connect, I get BT_ERROR_OPERATION_FAILED error.

Is there something I didn't notice?

1, I can't create socket without defining UUID.
IBluetoothClientSocket CreateSocket(string serviceUuid);
I've used HFP UUID, I don't know whether it is a proper workaround or not.

You should not use Predefined UUID' for the RFCOMM socket. Because Predefined UUID is used for the specific function in the
platform. So use RFCOMM UUID or the custom UUID. You can generate the random UUID using uuidgen tool.
$ uuidgen
24f72081-3aa7-427c-8ac2-afc0eafba9e2

2, IBluetoothClientSocket.Connect doesn't have port property, so I don't know which port will be used.
When I set HFP UUID and just connect, I get BT_ERROR_OPERATION_FAILED error.
BT socket don't have 'port' option, 'port' is a concept of network socket. You can communicate with the server using socket fd even if you don't know the port number.
Please refer next code for the connection and data exchange.
https://review.tizen.org/gerrit/gitweb?p=test/tct/csharp/api.git;a=blob;f=tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/BluetoothSetup.cs;h=a9717bb14ee48dc5b0cd1d067eeb03fbef42a4e3;hb=refs/heads/tizen --> CreateClientSocketUtil() function

https://review.tizen.org/gerrit/gitweb?p=test/tct/csharp/api.git;a=blob;f=tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSIBluetoothClientSocket.cs;h=33c0ef9043d9ffcefcf69f3def2d3fff317cd634;hb=refs/heads/tizen --> Connect_SOCKET_CONNECTION_TEST

** If you want to use HFP function in tizen. You can use BluetoothAudio class. (Not use socket function)
https://samsung.github.io/TizenFX/latest/api/Tizen.Network.Bluetooth.BluetoothAudio.html connect type (AudioGateway)
Sample is next
https://review.tizen.org/gerrit/gitweb?p=test/tct/csharp/api.git;a=blob;f=tct-suite-vs/Tizen.Bluetooth.Manual.Tests/testcase/TSBluetoothAudio.cs;h=551363ac42e51702634b6c323ff31498a24d4701;hb=refs/heads/tizen

At first I tried RFCOMM UUID, however "0003", "3" and "00000003-0000-1000-8000-00805F9B34FB" didn't work, because I got ServiceNotFound error(in ConnectionStateChanged callback).

I thought I should just create a socket with port, because the python example works. What I'm trying to do is to get gear iconx and galaxy bud's battery level. The python script works on linux, so iconx can broadcast it's battery level through port 1 with RFCOMM connection.

I can't open review.tizen.org because I don't have account. Can I register somewhere?

  1. At first I tried RFCOMM UUID, however "0003", "3" and "00000003-0000-1000-8000-00805F9B34FB" didn't work, because I got ServiceNotFound error(in ConnectionStateChanged callback).

Is there same uuid socket server on the remote device? if not, ServiceNotFound error will be occured when you try to connect to the remote device.

  1. I thought I should just create a socket with port, because the python example works. What I'm trying to do is to get gear iconx and galaxy bud's battery level. The python script works on linux, so iconx can broadcast it's battery level through port 1 with RFCOMM connection.

At first, please set-up the socket connection with the remote device before sending data.

I can't open review.tizen.org because I don't have account. Can I register somewhere?

Please register an account in tizen.org. You can use the account in review.tizen.org also.

Yes and no.

As I mentioned, when I use this script I can get the battery level. This script uses RFCOMM UUID (3) and can get the gear iconx's battery level. However if I try to get the bonded gear iconx device's uuids with BluetoothDevice.ServiceUuidList, RFCOMM UUID doesn't get listed. So yes, remote device(gear iconx) is able to behave as RFCOMM server, but no I can't get RFCOMM UUID listed. (that's why I tried HFP UUID)

These are the UUIDs from BluetoothDevice.ServiceUuidList

0000110A-0000-1000-8000-00805F9B34FB
0000110B-0000-1000-8000-00805F9B34FB
0000110C-0000-1000-8000-00805F9B34FB
0000110D-0000-1000-8000-00805F9B34FB
0000110E-0000-1000-8000-00805F9B34FB
0000111E-0000-1000-8000-00805F9B34FB
00001200-0000-1000-8000-00805F9B34FB
00001800-0000-1000-8000-00805F9B34FB
00001801-0000-1000-8000-00805F9B34FB
0000180A-0000-1000-8000-00805F9B34FB
0000180D-0000-1000-8000-00805F9B34FB
00009900-0000-1000-8000-00805F9B34FB
00011101-0000-1000-8000-00805F9B34FB
08160700-0301-0403-0109-0509AB114378

I try, but when I try to use RFCOMM UUID I get ServiceNotFound error and when I try to use HFP UUID I get BT_ERROR_OPERATION_FAILED.

  1. Why don't you create rfcomm server on the remote device(gear iconx)? You need to create the rfcomm server and try to connect the server on the test device.
  2. Please check '00011101' is correct or not because 0001101 is for rfcomm uuid.

1
gear iconx is the server, I try to connect to it with a galaxy watch as a client. Would it be helpful if I'd send the source code?

2
actually 0x0003 is the rfcomm UUID. Tizen api naming is a little bit misleading because it always creates rfcomm socket, but I have to set the service uuid, which can be the serial port. Serial port UUID is 0x1101 as you've written.

I tried to connect to the gear iconx with this UUID: 00011101-0000-1000-8000-00805F9B34FB, and it connected successfully, however I only get this: "\x10\x19\a\x05" from the device.

Maybe iconx uses different ports for rfcomm communication which I can't set directly from Tizen, and I can't access to them because UUIDs are not assigned to that specific port. Is there any way I could create socket to a given port?

I think we can close this one, as port can not be set.