Community
cancel
Showing results for 
Search instead for 
Did you mean: 
idata
Community Manager
1,688 Views

edison C++ bluetooth SPP system call

Hi ,

i'd llike to copy recieved SPP bluetooth serial characters to a variable, array or string.

I can make a connection from an SPP app android ( oly in older kernel , thats another story )

// loop forever and poll SPP

for (;;) {

ssize_t size = system ("cat /dev/rfcomm0");

if (size != -1) {

const char serialstring = system ("cat /dev/rfcomm0");

dosometing(serialstring); // go and do something with the recieved character in abother function.

}

}

is there a buffer for incoming charcters with SPP ? how best to read it with a system call ?

0 Kudos
7 Replies
idata
Community Manager
45 Views

Hello bennnn,

 

 

Thanks for reaching out!

 

 

I've never been able to do this on code, the main challenge I've found is that BlueZ's API documentation is very scarce and since I'm not a full-fledged programmer (my background is mainly electronics), sometimes I struggle when reading the API directly. So, if you don't have that problem, then you'll have to use the API directly, in that case, I'd suggest you to start by reading https://github.com/heinervdm/bluez/blob/master/cups/spp.c.

 

 

On the other hand, if you are in a similar position to mine, I've a couple of suggestions, firstly, this book from the MIT http://people.csail.mit.edu/rudolph/Teaching/Articles/BTBook.pdf, it has helped me a lot in the past. Before reading it I was not even able to scan for Bluetooth devices using C code. The section 3.2 explains how to use RFCOMM sockets with C programming (I'm sorry, not C++), so, if you have the time to read the book, I'm sure it will be of much help for you. The other suggestion would be for you to contact BlueZ directly, to see if they can provide you with more concise information, if you are interested in this option, then you can find the contact information for BlueZ at http://www.bluez.org/contact/.

 

 

I hope this information helps you,

 

Pedro M.
idata
Community Manager
45 Views

Thanks for the info Pedro ,

I'll read the book and see if I can use RFCOM.

hopfully I can just use bluetoothctl to handle the pairing etc

then,

rfcomm listen 0 1

then get the serial charcters from,

serialstring = system ("cat /dev/rfcomm0");

I just remembered I have to downgrade the yocto image to pre 3.0 for bluez5 to work with SPP.

The Bluez5 update does not work for me. has this not been fixed on the latest image yet ?

idata
Community Manager
45 Views

You are talking about this issue https://communities.intel.com/message/393307# 393307 https://communities.intel.com/message/393307# 393307, right? If so, have you tried the solution provided at the end of that thread?

 

 

I believe the issue was caused because of the version of BlueZ on the images 3.0 and 3.5 and if you install a previous version (for example, the one in the image 159.devkit) the issue would disappear. So, you can try the steps found in this thread https://communities.intel.com/message/415176# 415176 https://communities.intel.com/message/415176# 415176 to see if they help you with that issue (in case the suggestion above doesn't work).

 

 

As far as I understand, this has not been addressed to the image yet, but hopefully the suggestions above can help you get rid of the issue.

 

 

Let me know.

 

Pedro M.
idata
Community Manager
45 Views

I just tried both examples and niether worked.

I get a disconect within a few seconds.

idata
Community Manager
45 Views

That is strange. I just tested the steps found in https://communities.intel.com/message/415176# 415176 https://communities.intel.com/message/415176# 415176 with the latest image (201606081705) and I was able to create a SPP connection with the test script SPP-loopback.py as explained in https://communities.intel.com/docs/DOC-100754 https://communities.intel.com/docs/DOC-100754. So, I believe this is in fact related to the BlueZ version on Edison, did you make sure to install version 5.22 on your Edison?

 

 

Pedro M.
idata
Community Manager
45 Views

Hi Pedro,

I had the latest version of bluez5 somehow 5.34 i think ,

I removed it and installed bluez5 version 5.22 and the python loopback script works fine.

The python scripts does'nt seam to create a /dev/rfcommN device so its not using rfcomm?

does the python script have any interaction with the OS where I can copy the loopback other than the console itself?

sorry i've never used python so have no idea how its working!

It would save me a lot of time going through the book learnign rfcomm and bluetooth connection management if I could just copy the serial messages from here with a system call. I have a very simple apllication sending simple serial messages..

Thanks for your help with my SPP probelm , at least I have that working

Ben

idata
Community Manager
45 Views

OK, please ignore my last post,

i don't know if this will help anyone else or if its a really bad idea, but I change the python script to append a the serial data to a file so I can then read it in my C++ code.

try:

while True:

data = server_sock.recv(1024)

print(data)

f=open("/home/bentooth.txt", "w+")

f.write(data)

server_sock.send("looping back: %s\n" % data)

except IOError:

pass

server_sock.close()

print("all done")

I'm sure using rfcomm directly is a better way to do it !! but this will work for now..

Ben

Reply