Hi,

Because i saw some questions about how to access to wlancond with dbus
And because I had the same question last week, i decided to send to this
list a code sample. This code sample simulate an "iwlist scan" call.

I hope this will be useful for someone.

Gabriel Grise
from dbus.glib import *
import gobject
import dbus
import array

loop=None
#function to handle response from wlancond
def scan_results(*args):
    #first parameter is the number of Cell
    #each cell have an essid, bssid, rssi, channel, capabilities bytes.
    for i in  range(0, args[0]):
                pos = 1+(i*5)
                (essid, bssid, rssi, channel, capbits) = args[pos:pos+5]
                
                print """
                Cell %d - Address: %s
                ESSID: %s
                Channel: %d
                Signal Level: %d
                """ % (i, "%02X:%02X:%02X:%02X:%02X:%02X" % (bssid[0],bssid[1],bssid[2],bssid[3],bssid[4],bssid[5]),
                         array.array("b", essid).tostring(), channel, rssi)
    loop.quit()
    
if __name__ ==  "__main__":
    
        #mandatory to receive dbus signal
        loop=gobject.MainLoop();
        
        bus = dbus.SystemBus()
        
        
        
        #get wlancond object
        wlancond = bus.get_object('com.nokia.wlancond', '/com/nokia/wlancond/request');
        #request interface 
        request = dbus.Interface(wlancond, 'com.nokia.wlancond.request')  
        
        #you will receive the scan reply through a signal
        bus.add_signal_receiver(scan_results, dbus_interface="com.nokia.wlancond.signal", signal_name="scan_results");
        
        #send a request to wlancond
        #the first parameter seem to be the power level, WLANCOND_TX_POWER10 or WLANCOND_TX_POWER100
        #but i have no idea of what value have these two constants, so i found one of them with a strace.
        
        #the second parameter is an ESSID, it's a bytes array
        request.scan(dbus.Int32(8), dbus.Array([], signature="y"))
        
        #you need to wait for the signal.
        loop.run()
        
_______________________________________________
maemo-developers mailing list
maemo-developers@maemo.org
https://lists.maemo.org/mailman/listinfo/maemo-developers

Reply via email to