2010-03-02 16:26:51

by Henry Owens

[permalink] [raw]
Subject: Bluetooth SPP on Nokia N900 (Maemo 5)

Hi All,

My first mail to this list. I am currently trying to get a bluetooth
SPP connection going on my Nokia N900, but I'm having some
difficulties using the examples on the HOWTO Wiki.

Specifically, I get an error related to the ActivateService call in
the example - I have seen reference to this being obselete in Bluez
4.x, is this the problem in the example code?

If so, how could the code be rewritten to allow a connection (I have
no prior experience with BT programming, but am comfortable in
Python).

The code at the moment is:

import dbus
import time
import sys
bus = dbus.SystemBus()
bmgr = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'),
'org.bluez.Manager')
bus_id = bmgr.ActivateService('serial')
serial = dbus.Interface(bus.get_object(bus_id, '/org/bluez/serial'),
'org.bluez.serial.Manager')
# Service connection, read the serial API to check the available patterns
if (len(sys.argv) < 2):
??????? print "Usage: %s <address> [service]" % (sys.argv[0])
??????? sys.exit(1)
address = sys.argv[1]
if (len(sys.argv) < 3):
??????? service = "spp"
else:
??????? service = sys.argv[2]
# Bind to the default local adapter
device = serial.ConnectService(address, service)
print "Connected %s to %s" % (device, address)
print "Press CTRL-C to disconnect"
try:
??????? time.sleep(1000)
??????? print "Terminating connection"
except:
??????? pass
serial.DisconnectService(device)


Regards,
Henry.


2010-03-05 10:52:25

by Henry Owens

[permalink] [raw]
Subject: Re: Bluetooth SPP on Nokia N900 (Maemo 5)

Vinicius,

Many thanks for your help - I used the example script, and it is now
connecting correctly to my device.

I am having a slight issue, however, with the fact that the
"SetSerialParameters" method is experimental, and thus I can not use
it - could anyone point me to where I can set the parameters correctly
so that it can receive packets from the device?

FYI, the device is simplex - it sends a packet once per second, and
ignores any commands, so I simply want to receive the packets and
parse them.

At present, when I use the code below, I do not get any output, which
I assume is because my serial settings are incorrect.

Many thanks again for your help,
Henry.

test.py:

import sys
import dbus

bus = dbus.SystemBus()

manager = dbus.Interface(bus.get_object("org.bluez", "/"),
"org.bluez.Manager")

adapter = dbus.Interface(bus.get_object("org.bluez", manager.DefaultAdapter()),
"org.bluez.Adapter")

address = "00:07:80:88:F4:E9"
service = "spp"

path = adapter.FindDevice(address)

serial = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Serial")

node = serial.Connect(service)

print "Connected %s to %s" % (node, address)

print "Press CTRL-C to disconnect"

a = open("/dev/rfcomm0","r")

w = a.readline()

print w

serial.Disconnect(node)



On Tue, Mar 2, 2010 at 5:14 PM, Vinicius Gomes
<[email protected]> wrote:
> Hi Henry,
>
> On Tue, Mar 2, 2010 at 1:26 PM, Henry Owens <[email protected]> wrote:
>> Hi All,
>>
>> My first mail to this list. I am currently trying to get a bluetooth
>> SPP connection going on my Nokia N900, but I'm having some
>> difficulties using the examples on the HOWTO Wiki.
>>
>> Specifically, I get an error related to the ActivateService call in
>> the example - I have seen reference to this being obselete in Bluez
>> 4.x, is this the problem in the example code?
>>
>
> Yeah, the example code in the wiki is outdated, take a look at the
> example in the sources [1],
> for a working one.
>
> Also, in that same directory there are a few more examples that could be useful.
>
>
> Cheers,
> --
> Vinicius Gomes
> INdT - Instituto Nokia de Tecnologia
>
> [1] http://git.kernel.org/?p=bluetooth/bluez.git;a=blob;f=test/test-serial;hb=HEAD
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at ?http://vger.kernel.org/majordomo-info.html
>

2010-03-02 17:14:10

by Vinicius Costa Gomes

[permalink] [raw]
Subject: Re: Bluetooth SPP on Nokia N900 (Maemo 5)

Hi Henry,

On Tue, Mar 2, 2010 at 1:26 PM, Henry Owens <[email protected]> wrote:
> Hi All,
>
> My first mail to this list. I am currently trying to get a bluetooth
> SPP connection going on my Nokia N900, but I'm having some
> difficulties using the examples on the HOWTO Wiki.
>
> Specifically, I get an error related to the ActivateService call in
> the example - I have seen reference to this being obselete in Bluez
> 4.x, is this the problem in the example code?
>

Yeah, the example code in the wiki is outdated, take a look at the
example in the sources [1],
for a working one.

Also, in that same directory there are a few more examples that could be useful.


Cheers,
--
Vinicius Gomes
INdT - Instituto Nokia de Tecnologia

[1] http://git.kernel.org/?p=bluetooth/bluez.git;a=blob;f=test/test-serial;hb=HEAD