c++bluetoothread-writerfcommspp

Unable to read from /dev/rfcomm


I am trying to connect my target to mobile device through blue-tooth SPP profile. Once bluetooth connection is up, request is made to create rfcomm channel to communicate.

output of 
ls -all /dev/rfcomm0
crw-rw-rw-    1 root     dialout   216,   0 Jan  1 00:02 /dev/rfcomm0

once rfcomm device is created, in my code I am opening the file and writing data to it.

fd = open('/dev/rfcomm0', O_RDWR | O_NOCTTY | O_SYNC);
write(write(fd, &sendBuffer[0], sendBuffer.size())

write is successful. again if I try to read the data through rfcomm, code does not proceed.

read(fd, recvbuf, recvbuflen)

Since read was not working I tried closing the file descriptor and again open it.

This time it is not able to open /dev/rfcomm0. It returns -1.

Please guide where I am lacking.

Also I am newbie to this, so if there are any documents on bluetooth SPP using C++.


Solution

  • Found the solution, the mobile application to which I was trying to connect uses different UUID to communicate. If I start a connection using application defined UUID, I am able to read and write the data properly.

    But still I have one query, Bluetooth specification defines UUID for its profiles.

    For SPP it is 0x0003.
    

    In my use case navigation device communicates with android application using SPP profile but uses UUID other than 0x0003.

    So does this mean android application can choose any random unique UUID other than what is mentioned by specs to communicate over SPP?