HOWTO/NetworkConnections

Description

This page contains network connection and server usage examples. The API description is available at network service.

Service Activation

When a client wants to start the network service or discover the network service bus "id" address the ActivateService? method should be called.

import dbus
bus = dbus.SystemBus()
bmgr = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'), 'org.bluez.Manager')
bus_id = bmgr.ActivateService('network')

# All serial service messages should be sent to this address
print bus_id

Service activation from command line:

$dbus-send --system --type=method_call --print-reply --dest=org.bluez \
/org/bluez org.bluez.Manager.ActivateService string:network

Connections

import dbus
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'), 'org.bluez.Manager')
conn = manager.ActivateService('network')
network = dbus.Interface(bus.get_object(conn, '/org/bluez/network'), 'org.bluez.network.Manager')

# Service connection current support only NAP and GN profiles
path = network.CreateConnection('00:11:22:33:44:55', 'NAP')
connection = dbus.Interface (bus.get_object(conn, path), 'org.bluez.network.Connection')
connection.Connect()

Connection object creation from command line:

$dbus-send --system --type=method_call --print-reply --dest=":X.Y"
/org/bluez/network org.bluez.network.Manager.CreateConnection string:"XX:XX:XX:XX:XX:XX" string:nap

Cancel pending connection

TBD

Removing Connections

Removing connection object from command line:

$dbus-send --system --type=method_call --print-reply --dest=":X.Y"
/org/bluez/network org.bluez.network.Manager.RemoveServer string:"/org/bluez/network/connectionX"

Correction - this should be:

$dbus-send --system --type=method_call --print-reply --dest=":X.Y"
/org/bluez/network org.bluez.network.Manager.RemoveConnection string:"/org/bluez/network/connectionX"