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
My Carrier: T-Mobile

Bluetooth stream to read and write to (SPP/Obex)

I have a digital pen which should send files to a BB10 which in return will send them to a server.

By now I have used the SPP Chat Example as base for listening to an incoming pen connection - which works.

 

Now I have to handle the incoming file/bytestream.

In the ChatManager (from SPP Chat Sample) there is the SPPThread::run() method which receives an incoming bluetooth message via

 

ssize_t read (int fildes, void* buf, size_t nbyte)

 

I thought I could use the read method to process the incoming stream, but I don't know if this produces a stream of sorts. I tried to read the incoming bluetooth file byte per byte by doing something like this:

 

int readlen;
char tempbuff[1];

while (m_sppFD>= 0) // m_sppFD is the file descriptor for my digital pen
{
            readlen = read(m_sppFD, tempbuff, 1);
            if (readlen >0)
            {
// process byte
}
else
{
break;
}
}

and the first time the while loop is passed through everything seems fine (the byte is correctly read). But then there is a long break and after that 'readlen' is 0.

 

My assumption now is: the read method doesn't read a bluetooth file constantly byte per byte ... Is that true? I don't find any information.

Or maybe I am not reading the byte properly?

 

 

I decided to try another thing. There is an fopen method which opens a file (could be an incoming bluetooth file, if I understood correctly) which returns a FILE, which can then be used to open a stream.

To call the fopen method I used

 

char addr[18];
bt_spp_get_address(m_sppFD, addr);  // m_sppFD is the file descriptor for my digital pen

 which returned in addr a MAC(?) address.

This address I used to call fopen:

 

FILE *f = fopen(addr, "rb+");

 but f is NULL because the file address couldn't be found in memory.

 

Now I am kind of lost.

Does anyone have a hint for me?

 

I am a C++ beginner, but it's really hard to find information about processing bluetooth streams in BB10.

Some days ago there was a sample about reading (and writing?) from a heart rate monitor (not SPP) in the internet, but I can't find it anymore. If someone knows the URL, maybe this could help me to find out how to process an incoming bluetooth stream byte per byte ...

 

Any help would be appreciated.

 

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Bluetooth stream to read and write to (SPP/Obex)

[ Edited ]

Hi

 

you'll find references to Bluetooth Low Energy resources, including the Heart Rate Monitor application, video and article you're referring to here:

 

http://supportforums.blackberry.com/t5/Native-Development-Knowledge/BlackBerry-10-Bluetooth-LE-resou...

 

These will not help with your current problem however. Your pen probably uses the Serial Port Profile which comes from Bluetooth BR (Basic Rate) whereas the Heart Rate, Find Me and Cycling Speed and Cadence examples referenced in that resources index page relate to Bluetooth Low Energy (AKA Bluetooth Smart).

 

What make / model of pen are you working with?

 

What BlackBerry device are you testing with and what BlackBerry 10 OS version is it running?

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Developer
Developer
Posts: 20
Registered: ‎07-22-2013
My Device: Z10
My Carrier: T-Mobile

Re: Bluetooth stream to read and write to (SPP/Obex)

Thanks for your answer and for the link.

 

Maybe you're right - I can't find some line of code where a bluetooth stream is read byte per byte (at least I couldn't yet).

 

But I thought, that my problem is not neccessarily related to a specific device or bluetooth profile, but to the method of constantly reading a byte stream.

That my pen can connect and send data to the BlackBerry is already verified. Without an app, the file is stored on the phone (I could write an app, which fetches the files from there, but then you would always have to accept it by clicking a button and this would be bad for our workflow). With my slightly customized SPP Chat Sample app the pen is "recognized by the app" and I can read the first byte from the bluetooth stream/file. But this is where I'm stuck: I don't know how to receive the rest of the bytes (and to write bytes back to the pen).

 

We do have this kind of app for other mobile devices (BlackBerry, Android, etc.) but they are mostly in Java and the bluetooth transfer is done by Input and Outputstreams from (bluetooth) sockets.

I don't know what I can use in C++ for that (fopen? read? I tried them both (see first post), but maybe not in the right way).

 

Even if I don't think the actual devices are important to solve the issue, here they are:

 

- Anoto digital pen

- BlackBerry Z10

- 10.1.0.2312

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Bluetooth stream to read and write to (SPP/Obex)

[ Edited ]

Hi

 

you do need to know the device in this case. I happen to have done some work with the Anoto pen and BlackBerry 10. I'll be back with information shortly.

 

Regards

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Developer
Developer
Posts: 20
Registered: ‎07-22-2013
My Device: Z10
My Carrier: T-Mobile

Re: Bluetooth stream to read and write to (SPP/Obex)

I sent you a PN!

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Bluetooth stream to read and write to (SPP/Obex)

You'll need to be developing and testing with the BlackBerry 10.2 APIs for this to work. There's a parameter that has no use in earlier versions of the APIs which it transpires you need to specify for the Anoto Pen to work. Here's what a modified version of the SPP chat code ends up looking like:

 

 

void ChatManager::startSPPServer()

{

   qDebug() << "XXXX startSPPServer";

 

    m_chatHistory.clear();

 

    // service_name (unused), service UUID, non-block flag, callback

    if (bt_spp_open_server((char *) "ANOTO OBEX" , (char *) SPP_SERVICE_UUID, 0, BTControllerSPPCallback, reinterpret_cast<long>(this)) == 0) {

        updateChatWindow("SPP Server started for ANOTO OBEX. Waiting..\n\n");

        m_sppDataThread.init(-1, true);

    qDebug() << "XXXX started SPP server OK. Data thread running";

    } else {

        showDialog("spp_open_server fail", "errno = " + QString::number(errno) );

       qDebug() << "XXXX startSPPServer: errno = " << QString::number(errno);

    }

}

 

The new parameter is the service name of course. The pen looks for this when connecting. 

 

So I just wanted to check... is the pen connecting to your application or not? I would not have expected it to connect unless you specify the service name and use 10.2 as shown here.

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Developer
Developer
Posts: 20
Registered: ‎07-22-2013
My Device: Z10
My Carrier: T-Mobile

Re: Bluetooth stream to read and write to (SPP/Obex)

Thanks for your answer - I already use that ServiceName and the pen connects correctly to the app (as I wrote, I can even read the first byte of its bluetooth stream).

 

AND I use definitely 10.1 :-) So that is not the problem.

I am stuck after reading the first byte ...

Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Bluetooth stream to read and write to (SPP/Obex)

[ Edited ]

Can you test on 10.2 please (your original code)? I don't  know of a reason why your initial attempt, reading from the FD should not be working. If it doesn't work connect with me via a PM again and we'll discuss maybe you sending me your code so I can take a closer look and maybe test myself.

 

Thanks

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Developer
Developer
Posts: 20
Registered: ‎07-22-2013
My Device: Z10
My Carrier: T-Mobile

Re: Bluetooth stream to read and write to (SPP/Obex)

Thanks again.

 

Unfortunately I'm having problems updating my QNX to 10.2 (Error: BlackBerry Native SDK 10.2 Beta 1 1.0.0 (blackberry_10_native_sdk.10.2.0.339.group 1.0.0) requires 'com.qnx.tools.bbt.ide.ide 10.2.0' but it could not be found).

 

Installing a complete new version of QNX with 10.2 results in me not knowing how to import my projects ... (in both the old and the new (where they disappeared) QNX)

 

I think I need some time to check everything and to try out what you suggested.

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

Re: Bluetooth stream to read and write to (SPP/Obex)

Me again :-)

 

I now use the new QNX with 10.2 and imported my project. But I can't upload it to my BB device, because its firmware version is still 10.1 which I can't update, as far as I know.

 

Can I do something about it ...?