Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Developer
Posts: 20
Registered: ‎07-22-2013
My Device: Z10
Accepted Solution

BlackBerry 10 - Develop SPP (Obex) Server

I have to develop an app which receives an obex bluetooth file from a digitel pen (a device for which I cannot write software). It would be ideal, if the app would receive the bluetooth file directly. For previous BlackBerry firmware versions we had an app which does that with (in Java): _server = (ServerSocketConnection) Connector.open('serviceName', Connector.READ_WRITE, false); and connection = _server.acceptAndOpen(); DataInputStream dis = connection.openDataInputStream(); DataOutputStream dos = connection.openDataOutputStream(); DoSomething(dis, dos); Now everything I find about SPP/Obex communication in BB10 is the SPP Chat Example, but I am a bit lost as to where I should make my modifications. I thought, the startSPPServer-Method would be a good start: bt_spp_open_server((char *) 'serviceName', (char *) SPP_SERVICE_UUID, 0, BTControllerSPPCallback, reinterpret_cast(this) but my serviceName is obviously causing an error (errno: EINVAL). Unfortunately I am not a good C++ programmer, so maybe I am totally wrong about something. But there is no futher documentation that I could read and rather than trying out anything I can think of, I would be very glad if someone has a hint for me. An alternative to the above scenario could be to send the bluetooth files to the phone instead of the app, which already works, to monitor the bluetooth folder and take the files from there. But the problem is that you have to manually accept any bluetooth connection to the phone, which is bad for our workflow. Is it possible to automatically accept every incoming file from an already paired device? I didn't find such a setting. Thank you in advance :-)
Retired
Posts: 418
Registered: ‎07-18-2012
My Device: Q10

Re: BlackBerry 10 - Develop SPP (Obex) Server

Hi,

 

At this time (10.1), only SPP, GATT and LE functions are programatically available.

 

OBEX is normally implemented on top of SPP/RFCOMM - you would have to handle the bytes that make higher level protocols yourself.

 

Which device is the bt_spp_open_server failing on? Which OS version is running?

 

Can you paste more of your open code?

 

Thanks.

 

 

--
Rob is no longer associated with BlackBerry.
Developer
Developer
Posts: 20
Registered: ‎07-22-2013
My Device: Z10

Re: BlackBerry 10 - Develop SPP (Obex) Server

Thanks for your answer!

And sorry for the bad formatting in the first post, there originally were some paragraphs (obviously javascript was not enabled ...).

 

As I understood it, it would be possible to establish the bluetooth connection to the digital pen via SPP. For the byte per byte transfer I already have sample code in Java. For better reading the code (in Java) from above again:

 

// open ServerSocketConnection with a special 'serviceName':
_server = (ServerSocketConnection) Connector.open('serviceName', Connector.READ_WRITE, false);  

...

connection = _server.acceptAndOpen();
DataInputStream dis = connection.openDataInputStream();
DataOutputStream dos = connection.openDataOutputStream(); 
// Process the incoming file byte per byte:
DoSomething(dis, dos); 

 

But what I don't know is how I the app is able to "get the info" that another device wants to send something. Yesterday I tried another 'serviceName' (the first I used worked with previous BB versions, but failed on BB10, this new one worked with Android devices) and this new one worked, which means I got no error, but the pen is still sending its files to the phone and not to the app.


My BB10 device is a Z10.

 

At this moment, I think, I would just need the method which sets up the "listening" for an incoming pen-connection. I thought this could be bt_spp_open_server, but I am really not sure.

 

If you need more information, please let me know. Right now I can't think of other lines of code which would help explaining my problem.

 

 

Developer
Developer
Posts: 20
Registered: ‎07-22-2013
My Device: Z10

Re: BlackBerry 10 - Develop SPP (Obex) Server

Ok ... interesting:

I tested again and with some bluetooth device deleting and new pairing I could make it work!

 

It seems that you have to first install (or debug) the app before you pair the device (in my case the digital pen) to the phone. This fact was not new to me, but I thought I did that before. What I also tried now was to pair the device from the phone instead initializing the pairing from the pen. I also thought I did that before, but I think, something else was not right before (the serviceName? Now it's the above mentioned second name).

 

Now it works as follows:

I took the SPP Chat Sample and on the phone I opened per button click the SPP Server. In the code I made one small adjustment in the ChatManager::startSPPServer() Method:

 

bt_spp_open_server((char *) "serviceName", (char *) SPP_SERVICE_UUID, 0, BTControllerSPPCallback, reinterpret_cast<long>(this)

 where "serviceName" is the Name of my digital pen service record.

 

Maybe this info helps someone, too. We developed this kind of app for a number of devices and the order of actions to pair pen and phone is not always the same.

 

Retired
Posts: 418
Registered: ‎07-18-2012
My Device: Q10

Re: BlackBerry 10 - Develop SPP (Obex) Server

[ Edited ]

You're saying that the pen doesn't ever connect if the service isn't there at pairing time? 

 

I don't think this is a general Bluetooth problem - can the Pen refresh services?

 

This is fairly standard behaviour. The service won't be visible to a device that pairs when the application isn't running.

 

 

--
Rob is no longer associated with BlackBerry.