maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Need Help on: Building a Bluetooth APP in Qt (https://talk.maemo.org/showthread.php?t=62625)

mboremski 2010-09-20 19:06

Need Help on: Building a Bluetooth APP in Qt
 
Hello,

I am NEW to writing apps in Qt.
Until now i programmed software for small microcontrollers (like AVR).
I also programmed some small apps for console in C.

So please forgive me if i have to ask step by step:

My Idea:
I got a Bluetooth-Module (BlueNiceCom III pdf) and combined it with an AVR.
This module is sending Data via SPP-Protokoll.
I wan tto write a GIU-APP that converts this data in e.g. bar graph or text in a first step.

Until now
My brohter helped me out writing a small console app (in C) to see the incoming data in the terminal.
We compiled it directly on the N900.. But the compiler and all its parts was so big.. so I had to remove it (and unfortunately reflash my N900).
So far i know a bit about how bluetooth as SPP works (own file for the opened connection / rfcomm and so on)

Bevore i forget.
I have:
WondowsXP
Nokia Qt SDK
MADDE
and of course a N900.. ;-)

Now I want to start (and go on ;) ) with Qt to get what I need.
I had my first experiences in writing a "hello World"-APP and my C++ is getting better.

My next step (and my first questions) is to establish a bluetooth connection to a known (MAC-address) bluetooth device.
Does anyone have any experiences in connecting a bluetooth-device (via SPP) with Qt?:confused:
Is there a lib that i can use? (and how can I?):confused:

I found the QBluetooth-lib.. But its only for symbian devices..

I hope I dont get awnsers like : rtfm..
better would be: rtfm "here", "here" and "here" ... ;)

TY so far,
Markus

sampppa 2010-09-21 12:37

Re: Need Help on: Building a Bluetooth APP in Qt
 
Hi

I once tried to compile qt bluetooth from qt-extented but i never got it to work. I think it is not working anymore on top of the new bluez version.
http://doc.qt.nokia.com/qtextended4....othmodule.html

I think that at the moment the only way to use bluetooth is with libbluetooth3 library.

mboremski 2010-09-21 15:09

Re: Need Help on: Building a Bluetooth APP in Qt
 
@sampppa,
Can i use the libbluetooth3-lib with Qt?
How can I install it? (Do I need to install it? )

Quote:

Originally Posted by sampppa (Post 822294)

Did you give me a link to a solution that dont work? :confused:

@all
Any other ideas?

TY so far
Markus

talmage 2010-09-21 20:00

Re: Need Help on: Building a Bluetooth APP in Qt
 
There's a little mention of it on http://qt.nokia.com/. I guess you have already tried searching there.

Qt 4.7 has some nifty new APIs for mobility. Maybe there is something for you in the Messaging API or the Service Framework.

It seems to me that once you pair your N900 with your new hardware device that there ought to be some simple way of addressing it over a socket.

nilsbenson 2010-09-23 01:07

Re: Need Help on: Building a Bluetooth APP in Qt
 
There isn't an easy way to do this as far as I know. I am currently doing something similar (attempting to connect to an SPP device over Bluetooth).

The Maemo UI doesn't allow you to conifigure SPP devices. In some limited instances it will set one up, but if you want to use it in your app you have to do it yourself.

To do this the best(?) way I have found is to talk to BlueZ over D-Bus. Python is the easiest language to do use for this. In my app I do the following:

1) Connect to bluez and enumerate all paired bluetooth devices
2) for each device I query the services it offers
3) I build a list of every device that reports SerialPort as a service
4) Connect to the SerialPort service on the device - this will establish the SPP connection and will set up a device file for you to access. The Connect() function on the bluez Device D-Bus object will return the name of the file to access. Then it's just like opening a regular device file for serial IO.

There may be a way to do all that using some bluez tools (I am pretty sure there is), but I have chosen to do it via code.

nilsbenson 2010-09-23 04:09

Re: Need Help on: Building a Bluetooth APP in Qt
 
If you can wait a week or so (leaving town tomorrow) I can post a Bluetooth manager I'm putting together in C++ / QT. It will be able to enumerate BT devices, and make serial connections. That is all, but will show you what you need to do to continue..

alex25 2010-09-23 06:13

Re: Need Help on: Building a Bluetooth APP in Qt
 
Quote:

Originally Posted by nilsbenson (Post 824007)
If you can wait a week or so (leaving town tomorrow) I can post a Bluetooth manager I'm putting together in C++ / QT. It will be able to enumerate BT devices, and make serial connections. That is all, but will show you what you need to do to continue..

I'm also working on a Qt application that has to communicate with bluetooth devices (bluetooth heart beat chest and bluetooth OBD2 car adapter)
Until now I don't have a solution. So your input would be very helpful. The application should also work on symbian devices. :o

djs_tx 2010-10-03 04:15

Re: Need Help on: Building a Bluetooth APP in Qt
 
Quote:

Originally Posted by nilsbenson (Post 824007)
If you can wait a week or so (leaving town tomorrow) I can post a Bluetooth manager I'm putting together in C++ / QT. It will be able to enumerate BT devices, and make serial connections. That is all, but will show you what you need to do to continue..

I'm interested in this too. I'm a little disappointed that QT appears to have no native bluetooth API... :mad:

discus-axel 2010-10-20 09:50

Re: Need Help on: Building a Bluetooth APP in Qt
 
Quote:

Originally Posted by nilsbenson (Post 824007)
If you can wait a week or so (leaving town tomorrow) I can post a Bluetooth manager I'm putting together in C++ / QT. It will be able to enumerate BT devices, and make serial connections. That is all, but will show you what you need to do to continue..

Hi,

I am a newbie in BT and it would a great help for me to get the promise C++/Qt example.

djs_tx 2010-11-01 02:41

Re: Need Help on: Building a Bluetooth APP in Qt
 
I'm still very much interested in this... Would appreciate anything you've got working. Better than starting from zero.

pillar 2010-11-08 09:58

Re: Need Help on: Building a Bluetooth APP in Qt
 
Yes, very much interested in this as well, any updates on progress?

djs_tx 2010-11-08 16:03

Re: Need Help on: Building a Bluetooth APP in Qt
 
I am no expert but there doesn't seem to be any experts helping out. So I may have this all wrong but here is what I have figured out so far:

1. QT has a module in progress for bluetooth connections but it is not complete and is not part of the stuff that is supposed to be delivered by years end.
http://qt.nokia.com/developer/qt-roa...nnectivity-api

2. You can establish an RFComm channel and connection through DBUS interactions But I have not been able to locate any C++ examples that make sense to me.

The way I am solving the problem for my own personal use is to use the Queen Beecon widget to create a desktop shortcut for the command line "rfcomm bind" command. It is not a good solution to deploy to other people but if you have one or two devices you want to play with like me, it will let you develop the rest of your application while you wait for other solutions.

scudderfish 2010-12-10 11:08

Re: Need Help on: Building a Bluetooth APP in Qt
 
I've done this in Python, but I'm now trying to port over to C++ and I'm stumped :(

pillar 2010-12-10 14:45

Re: Need Help on: Building a Bluetooth APP in Qt
 
QtMobility 1.2 will include this and there seems to be a tech preview out, but I don't know of maemo5 has the backend for it..

tswindell 2010-12-11 10:22

Re: Need Help on: Building a Bluetooth APP in Qt
 
The Bluetooth stuff that is being developed for Qt Mobilitys' Connectivity module does have Maemo5/Linux support. I actually had to implement my own version for an app I'm working on. You should be able to just use their sources though. I'll probably try and compile it myself, as now I'm planning to release my app open I can use their code.

djs_tx 2010-12-14 01:52

Re: Need Help on: Building a Bluetooth APP in Qt
 
Thanks for all the help, still working on this. Some progress, some problems.

I went to the QT git site and cloned the latest to my hard drive. Did ./configure, make, sudo make install. Everything worked after I grabbed the alsa dev library.

I went into the examples folder and found a service discovery example for bluetooth. It built just fine on my linux desktop version of QT creator and it displayed the bluetooth mac and names of all the bluetooth devices nearby. That was a big step forward.

But it does not build when I select the maemo target, obviously because I only built the examples for my desktop. So the next question is this:

Can I somehow "cross compile" the git snapshot I downloaded for Maemo using my desktop or do I have to have the full scratchbox environment installed to build the qt mobility snapshot?

Thanks,
David

scudderfish 2010-12-17 19:38

Re: Need Help on: Building a Bluetooth APP in Qt
 
OK, here is some code I just got running on my N900. It connected a to a bluetooth rs232 adapter, created a device /dev/rfcomm0 and then disconnected it. Hope it is of some help.

Code:

    QString address = "00:12:6F:03:BC:63";
    QString service = "spp";

    QDBusConnection bus = QDBusConnection::systemBus();
    QDBusInterface manager_iface("org.bluez", "/","org.bluez.Manager", bus);

    QDBusReply<QDBusObjectPath > devices = manager_iface.call("DefaultAdapter");

    if (devices.isValid())
    {
        QDBusObjectPath defaultAdapter = devices.value();
        QString defaultAdapterPath = defaultAdapter.path();
        qDebug() << defaultAdapterPath;

        QDBusInterface adapter_iface("org.bluez",defaultAdapterPath,"org.bluez.Adapter",bus);
        QDBusReply<QDBusObjectPath> path = adapter_iface.call("FindDevice",address);

        if(path.isValid())
        {
            QDBusInterface serial_iface("org.bluez",defaultAdapterPath,"org.bluez.Serial",bus);

            QDBusMessage node = serial_iface.call("Connect",service);
            qDebug() << node;
            QVariant dev = node.arguments().at(0);
            qDebug() << dev;
            QDBusMessage result = serial_iface.call("Disconnect",dev);
            qDebug() << result;
        }
        else
        {
            qDebug() << path.error();
        }
    }
    else
    {
        qDebug() << devices.error();
    }


scudderfish 2010-12-19 21:03

Re: Need Help on: Building a Bluetooth APP in Qt
 
I've generated some classes (mainly lifted from the bluez dbus qt example) and commited them here

https://garage.maemo.org/plugins/scm...ot=maegasquirt

Pretty much the same code as before now looks like
Code:


    org::bluez::Manager manager(BLUEZ_SERVICE_NAME,
                                BLUEZ_MANAGER_PATH, QDBusConnection::systemBus());


    QDBusPendingReply<QDBusObjectPath> dpath = manager.DefaultAdapter();
    dpath.waitForFinished();
    if (!dpath.isValid())
    {
        qCritical() << "Unable to find default Bluetooth adapter";
        return -1;
    }

    QDBusObjectPath adapterPath = dpath.value();

    org::bluez::Adapter adapter(BLUEZ_SERVICE_NAME,
                                adapterPath.path(), QDBusConnection::systemBus());
    if (!adapter.isValid())
    {
        qCritical() << "Can't get valid adapter object reference!";
        return -1;
    }

    QDBusPendingReply<QDBusObjectPath> device = adapter.FindDevice("00:12:6F:03:BC:63");

    device.waitForFinished();
    if (device.isValid())
    {
        QDBusPendingReply<> reply = adapter.RemoveDevice(device.value());
        reply.waitForFinished();
    }


aperles 2010-12-19 21:52

Re: Need Help on: Building a Bluetooth APP in Qt
 
May be the solution could be easier.

Taking into account that you want to use a SPP-profile (a virtual serial port), you could consider to read/write this port directly.

I use QextSerialPort library ( http://code.google.com/p/qextserialport/ ) on Linux an Windows boxes, including Bluettoth SPP for GPSs.

I haven't yet tried to compile it on Maemo, but considering that it is Linux, I think it will work.

If other guys consider that this approach could work, I can try it. (No much time now, I'm fighting against telephony extesions for Symbian :confused:).

Regards,
Àngel

tswindell 2010-12-19 23:19

Re: Need Help on: Building a Bluetooth APP in Qt
 
I've already got an app that does this, if you can wait I plan on releasing it next week.

tswindell 2010-12-21 21:08

Re: Need Help on: Building a Bluetooth APP in Qt
 
Just released my app that provides this functionality, see: http://talk.maemo.org/showthread.php?t=67276


All times are GMT. The time now is 16:21.

vBulletin® Version 3.8.8