Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steep learning curve #28

Open
mcondarelli opened this issue Mar 1, 2020 · 3 comments
Open

Steep learning curve #28

mcondarelli opened this issue Mar 1, 2020 · 3 comments

Comments

@mcondarelli
Copy link

mcondarelli commented Mar 1, 2020

Hi,
first and foremost: Thanks for all the good work.

I'm trying to use dbussy/ravel to interface ConnMan.
Since I'm new to all of them: ConnMan, D-Bus and Your code, there's little surprise in me having problems, sorry.

I am trying to do things stepwise and I have the following test code:

#!/usr/bin/python3

import asyncio
import ravel

import pprint
from logging import getLogger
log = getLogger('networks')
pp = pprint.PrettyPrinter(indent=4)

bus_name = "net.connman"
path_name = "/"
iface_name = "net.connman.Manager"
chime_signal_name = "chime"

loop = asyncio.get_event_loop()


bus = ravel.system_bus()
bus.attach_asyncio(loop)
server = loop.run_until_complete(bus.get_proxy_interface_async(destination=bus_name,
                                                               path="/",
                                                               interface=iface_name))
server = server(connection=bus.connection, dest=bus_name)


async def main():
    print('===================================')
    tl = await server['/'].GetTechnologies()
    for p in tl[0]:
        # pp.pprint(p)
        print('-----------------------------------')
        print(f'-- {p[1]["Name"][1]}: {p[0]} --')
    print('===================================')
    sl = await server['/'].GetServices()
    for p in sl[0]:
        # pp.pprint(p)
        print('-----------------------------------')
        print(f'-- {p[1]["Name"][1]}: {p[0]} --')
    print('===================================')
    for p in tl[0]:
        pp.pprint(p)
        if p[1]['Type'][1] == 'wifi':
            print('-----------------------------------')
            t = p[1]
            print(f'-- {t["Name"][1]}: {p[0]} --')
            s = bus.get_proxy_interface(bus_name,  p[0], 'net.connman.Technology')
            s(connection=bus.connection, dest='net.connman.Technology').Scan()
            await asyncio.sleep(10)
    print('===================================')
    sl = await server['/'].GetServices()
    for p in sl[0]:
        # pp.pprint(p)
        print('-----------------------------------')
        print(f'-- {p[1]["Name"][1]}: {p[0]} --')
    print('===================================')


loop.run_until_complete(main())

This code, mostly stealed from useless_managed_object_server_ravelled, results in an exception:

===================================
-----------------------------------
-- Wired: /net/connman/technology/ethernet --
-----------------------------------
-- WiFi: /net/connman/technology/wifi --
-----------------------------------
-- Bluetooth: /net/connman/technology/bluetooth --
===================================
-----------------------------------
-- NETGEAR_11AC: /net/connman/service/wifi_001500d77076_4e4554474541525f31314143_managed_psk --
-----------------------------------
-- Wired: /net/connman/service/ethernet_02693694c027_cable --
-----------------------------------
-- Wired: /net/connman/service/ethernet_723575276940_cable --
-----------------------------------
-- Wired: /net/connman/service/ethernet_ae8d48867953_cable --
-----------------------------------
-- Wired: /net/connman/service/ethernet_ba6926867953_cable --
-----------------------------------
-- Wired: /net/connman/service/ethernet_366cdd276940_cable --
===================================
[   ObjectPath('/net/connman/technology/ethernet'),
    {   'Connected': (Signature('b'), True),
        'Name': (Signature('s'), 'Wired'),
        'Powered': (Signature('b'), True),
        'Tethering': (Signature('b'), False),
        'Type': (Signature('s'), 'ethernet')}]
[   ObjectPath('/net/connman/technology/wifi'),
    {   'Connected': (Signature('b'), True),
        'Name': (Signature('s'), 'WiFi'),
        'Powered': (Signature('b'), True),
        'Tethering': (Signature('b'), False),
        'Type': (Signature('s'), 'wifi')}]
-----------------------------------
-- WiFi: /net/connman/technology/wifi --
Traceback (most recent call last):
  File "/home/mcon/projects/dbussy/networks.py", line 78, in <module>
    loop.run_until_complete(main())
  File "/usr/lib/python3.7/asyncio/base_events.py", line 583, in run_until_complete
    return future.result()
  File "/home/mcon/projects/dbussy/networks.py", line 67, in main
    s(connection=bus.connection, dest='net.connman.Technology').Scan()
AttributeError: 'net.connman.Technology_factory' object has no attribute 'Scan'

Process finished with exit code 1

Reference code I'm trying to convert to ravel is:

    technology = dbus.Interface(bus.get_object("net.connman", 
                                               "/net/connman/technology/wifi"),
                                "net.connman.Technology")
    technology.Scan()

What am I doing so wrong?
Thanks in Advance
Mauro

@ldo
Copy link
Owner

ldo commented Mar 1, 2020

Note that the proxy interface needs an object path, e.g.

s(connection=bus.connection, dest='net.connman.Technology')['/net/connman/technology/wifi'].Scan()

(Not sure if that exact path will work. Try running the introspect_all example script to see more details about that daemon’s object model.)

@mcondarelli
Copy link
Author

Thanks for the quick answer.

./introspect_all system net.connman returns:

<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/">
    <interface name="org.freedesktop.DBus.Introspectable">
        <method name="Introspect">
            <arg name="xml" type="s" direction="out"/>
        </method>
    </interface>
    <interface name="net.connman.Manager">
        <method name="GetProperties">
            <arg name="properties" type="a{sv}" direction="out"/>
        </method>
        <method name="SetProperty">
            <arg name="name" type="s" direction="in"/>
            <arg name="value" type="v" direction="in"/>
        </method>
        <method name="GetTechnologies">
            <arg name="technologies" type="a(oa{sv})" direction="out"/>
        </method>
        <method name="RemoveProvider">
            <arg name="provider" type="o" direction="in"/>
            <annotation
                name="org.freedesktop.DBus.Deprecated"
                value="true"
            />
        </method>
        <method name="GetServices">
            <arg name="services" type="a(oa{sv})" direction="out"/>
        </method>
        <method name="GetPeers">
            <arg name="peers" type="a(oa{sv})" direction="out"/>
        </method>
        <method name="ConnectProvider">
            <arg name="provider" type="a{sv}" direction="in"/>
            <arg name="path" type="o" direction="out"/>
            <annotation
                name="org.freedesktop.DBus.Deprecated"
                value="true"
            />
        </method>
        <method name="RegisterAgent">
            <arg name="path" type="o" direction="in"/>
        </method>
        <method name="UnregisterAgent">
            <arg name="path" type="o" direction="in"/>
        </method>
        <method name="RegisterCounter">
            <arg name="path" type="o" direction="in"/>
            <arg name="accuracy" type="u" direction="in"/>
            <arg name="period" type="u" direction="in"/>
        </method>
        <method name="UnregisterCounter">
            <arg name="path" type="o" direction="in"/>
        </method>
        <method name="CreateSession">
            <arg name="settings" type="a{sv}" direction="in"/>
            <arg name="notifier" type="o" direction="in"/>
            <arg name="session" type="o" direction="out"/>
        </method>
        <method name="DestroySession">
            <arg name="session" type="o" direction="in"/>
        </method>
        <method name="RequestPrivateNetwork">
            <arg name="path" type="o" direction="out"/>
            <arg name="settings" type="a{sv}" direction="out"/>
            <arg name="socket" type="h" direction="out"/>
        </method>
        <method name="ReleasePrivateNetwork">
            <arg name="path" type="o" direction="in"/>
        </method>
        <method name="RegisterPeerService">
            <arg name="specification" type="a{sv}" direction="in"/>
            <arg name="master" type="b" direction="in"/>
        </method>
        <method name="UnregisterPeerService">
            <arg name="specification" type="a{sv}" direction="in"/>
        </method>
        <signal name="PropertyChanged">
            <arg name="name" type="s"/>
            <arg name="value" type="v"/>
        </signal>
        <signal name="TechnologyAdded">
            <arg name="path" type="o"/>
            <arg name="properties" type="a{sv}"/>
        </signal>
        <signal name="TechnologyRemoved">
            <arg name="path" type="o"/>
        </signal>
        <signal name="ServicesChanged">
            <arg name="changed" type="a(oa{sv})"/>
            <arg name="removed" type="ao"/>
        </signal>
        <signal name="PeersChanged">
            <arg name="changed" type="a(oa{sv})"/>
            <arg name="removed" type="ao"/>
        </signal>
    </interface>
    <interface name="net.connman.Clock">
        <method name="GetProperties">
            <arg name="properties" type="a{sv}" direction="out"/>
        </method>
        <method name="SetProperty">
            <arg name="name" type="s" direction="in"/>
            <arg name="value" type="v" direction="in"/>
        </method>
        <signal name="PropertyChanged">
            <arg name="name" type="s"/>
            <arg name="value" type="v"/>
        </signal>
    </interface>
    <node name="net">
        <node name="connman">
            <node name="iwd_agent">
                <interface name="org.freedesktop.DBus.Introspectable"/>
                <interface name="net.connman.iwd.Agent">
                    <method name="Release"/>
                    <method name="RequestPassphrase">
                        <arg name="path" type="o" direction="in"/>
                        <arg name="passphrase" type="s" direction="out"/>
                    </method>
                    <method name="Cancel">
                        <arg name="reason" type="s" direction="in"/>
                    </method>
                </interface>
            </node>
            <node name="service">
                <node name="ethernet_02693694c027_cable">
                    <interface
                        name="org.freedesktop.DBus.Introspectable"
                    />
                    <interface name="net.connman.Service">
                        <method name="GetProperties">
                            <arg
                                name="properties"
                                type="a{sv}"
                                direction="out"
                            />
                            <annotation
                                name="org.freedesktop.DBus.Deprecated"
                                value="true"
                            />
                        </method>
                        <method name="SetProperty">
                            <arg name="name" type="s" direction="in"/>
                            <arg name="value" type="v" direction="in"/>
                        </method>
                        <method name="ClearProperty">
                            <arg name="name" type="s" direction="in"/>
                        </method>
                        <method name="Connect"/>
                        <method name="Disconnect"/>
                        <method name="Remove"/>
                        <method name="MoveBefore">
                            <arg name="service" type="o" direction="in"/>
                        </method>
                        <method name="MoveAfter">
                            <arg name="service" type="o" direction="in"/>
                        </method>
                        <method name="ResetCounters"/>
                        <signal name="PropertyChanged">
                            <arg name="name" type="s"/>
                            <arg name="value" type="v"/>
                        </signal>
                    </interface>
                </node>
                <node name="ethernet_366cdd276940_cable">
                    <interface
                        name="org.freedesktop.DBus.Introspectable"
                    />
                    <interface name="net.connman.Service"/>
                </node>
                <node name="ethernet_723575276940_cable">
                    <interface
                        name="org.freedesktop.DBus.Introspectable"
                    />
                    <interface name="net.connman.Service"/>
                </node>
                <node name="ethernet_ae8d48867953_cable">
                    <interface
                        name="org.freedesktop.DBus.Introspectable"
                    />
                    <interface name="net.connman.Service"/>
                </node>
                <node name="ethernet_ba6926867953_cable">
                    <interface
                        name="org.freedesktop.DBus.Introspectable"
                    />
                    <interface name="net.connman.Service"/>
                </node>
                <node
                    name="wifi_001500d77076_4e4554474541525f31314143_managed_psk"
                >
                    <interface
                        name="org.freedesktop.DBus.Introspectable"
                    />
                    <interface name="net.connman.Service"/>
                </node>
            </node>
            <node name="technology">
                <node name="bluetooth">
                    <interface
                        name="org.freedesktop.DBus.Introspectable"
                    />
                    <interface name="net.connman.Technology">
                        <method name="GetProperties">
                            <arg
                                name="properties"
                                type="a{sv}"
                                direction="out"
                            />
                            <annotation
                                name="org.freedesktop.DBus.Deprecated"
                                value="true"
                            />
                        </method>
                        <method name="SetProperty">
                            <arg name="name" type="s" direction="in"/>
                            <arg name="value" type="v" direction="in"/>
                        </method>
                        <method name="Scan"/>
                        <signal name="PropertyChanged">
                            <arg name="name" type="s"/>
                            <arg name="value" type="v"/>
                        </signal>
                    </interface>
                </node>
                <node name="ethernet">
                    <interface
                        name="org.freedesktop.DBus.Introspectable"
                    />
                    <interface name="net.connman.Technology"/>
                </node>
                <node name="wifi">
                    <interface
                        name="org.freedesktop.DBus.Introspectable"
                    />
                    <interface name="net.connman.Technology"/>
                </node>
            </node>
        </node>
    </node>
</node>

I changed the relevant part in (your guess about the missing path seems correct to me):

            print('-----------------------------------')
            t = p[1]
            print(f'-- {t["Name"][1]}: {p[0]} --')
            if use_dbussy:
                i = bus['net.connman']['/net/connman/technology/wifi'].get_interface('net.connman.Technology')
                await i.Scan()
            elif use_ravel:
                s = await bus.get_proxy_interface_async(bus_name,  p[0], 'net.connman.Technology')
                i = s(connection=bus.connection, dest='net.connman.Technology')['/net/connman/technology/wifi']
                await i.Scan()
            else:  # use old
                import dbus
                i = dbus.Interface(dbus.SystemBus().get_object("net.connman",
                                                               "/net/connman/technology/wifi"),
                                   "net.connman.Technology")
                i.Scan()
            await asyncio.sleep(10)

and dbussy and "old" seem to work, while ravel bombs with:

-- WiFi: /net/connman/technology/wifi --
Traceback (most recent call last):
  File "/home/mcon/projects/dbussy/networks.py", line 55, in main
    await i.Scan()
TypeError: 'NoneType' object is not subscriptable

Any further hint?
TiA!

@ldo
Copy link
Owner

ldo commented Mar 2, 2020

That’s a mysterious message to get at that point. Perhaps try dumping out some more info about the “i” object before that Scan() call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants