Re: Disconnect WiFi using cNetworkManager Python library



On Monday 23 of January 2012 15:48:19 Olivier Deckmyn wrote:

> Hi,

>

> I’m building an Python application that has to connect and disconnect from

> Wifi on linux box. It's my very first experience with d-bus and gobject.

>

> I’m using NetworkManager layer, through the nice networkmanager lib found

> in cnetworkmanager

> (http://vidner.net/martin/software/cnetworkmanager/thanx to Martin

> Vidner), in my daemon (named stationd).

>

> This daemon runs a gobject.MainLoop. Once a timeout_add_seconds awake

> (triggers by an action of user in GUI), I have to disconnect current

> running Wifi and connect to a new one:

>

 

It depends on what NetworkManager version do you use. Latest version 0.9

made some major changes and the API is not compatible with 0.8 API. The main

change was removing user settings service. Now NM just uses one settings service built into NM.

 

Lots of info about NM can be found on this wiki page:

http://live.gnome.org/NetworkManager

 

D-Bus API:

http://projects.gnome.org/NetworkManager/developers/api/09/spec.html

http://projects.gnome.org/NetworkManager/developers/api/08/spec-08.html

 

Also, cnetworkmanager is not maintained any more. We have now nmcli command

line tool (written in C) inside NM, which should implement most of API.

See

http://repo.or.cz/w/cnetworkmanager.git/blob_plain/HEAD:/nmcli-migration.html (however it's old link, so for up-to-date nmcli syntax use 'man nmcli')

 

You can connect to configured connection (profiles) using nmcli via:

nmcli con up id name_of_the_connection

It doesn't matter what connection type it is (ethernet, wifi, vpn, ...)

 

nmcli can't connect to a WiFi SSID if there's no connection for it, at the moment. But, it is planned to add the feature.

 

For examples how to work with D-Bus API in various languages see:

http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples

 

Jirka

 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]