DBus Interface to MM and No Modems?

John Whitmore arigead at gmail.com
Wed Jun 17 06:23:06 PDT 2015


On Fri, Jun 12, 2015 at 09:50:32AM -0500, Dan Williams wrote:
> On Fri, 2015-06-12 at 15:03 +0100, John Whitmore wrote:
> > I'm going through the DBus documentation and can't seem to find what I'm
> > looking for. Then perhaps what I'm looking for is not actually valid. 
> > 
> > The documentation goes through the creation of a connection but I'm at the
> > step before that trying to find out how many, if any modems are actually
> > connected. If there's none then that's fine I have nothing to do but how to
> > determine that?
> 
> ModemManager uses the standard D-Bus "Object manager" interfaces as
> described here:
> 
> http://www.freedesktop.org/software/ModemManager/api/latest/ref-dbus-standard-interfaces-objectmanager.html
> 
> which means you can get the list of modems by doing this:
> 
> sudo dbus-send --system --print-reply
> --dest=org.freedesktop.ModemManager1 /org/freedesktop/ModemManager1
> org.freedesktop.DBus.ObjectManager.GetManagedObjects
> 
> and that'll send you back a dict of the all modems managed by MM keyed
> by object path.  For example:
> 
> method return sender=:1.5 -> dest=:1.139 reply_serial=2
>    array [
>       dict entry(
>          object path "/org/freedesktop/ModemManager1/Modem/0"
>          array [
>             dict entry(
>                string "org.freedesktop.ModemManager1.Modem"
>                array [
>                   dict entry(
>                      string "Plugin"
>                      variant                         string "Sierra"
>                   )
>                   dict entry(
>                      string "PrimaryPort"
>                      variant                         string "cdc-wdm0"
>                   )
>                   dict entry(
>                      string "State"
>                      variant                         int32 3
>                   )
> 
> You can either grab the properties out of the dict here, or just use
> this reply to build up the list of modem objects and query the state
> later.  In this case, my modem is in state 3 (MM_MODEM_STATE_DISABLED)
> because that's what the State property of the
> org.freedesktop.ModemManager1.Modem interface is.  If the modem was
> already connected, the org.freedesktop.ModemManager1.Modem.State
> property would be either 10 (CONNECTING) or 11 (CONNECTED).
> 
> Here's a python example:
> 
> -----
> import dbus, sys
> 
> bus = dbus.SystemBus()
> proxy = bus.get_object("org.freedesktop.ModemManager1",
> "/org/freedesktop/ModemManager1")
> om = dbus.Interface(proxy, "org.freedesktop.DBus.ObjectManager")
> 
> states = { 10: "Connecting", 11: "Connected" }
> 
> modems = om.GetManagedObjects()
> for mpath in modems.keys():
>     modem_state =
> modems[mpath]['org.freedesktop.ModemManager1.Modem']['State']
>     try:
>         state = states[modem_state]
>     except KeyError:
>         state = "Not connected"
>     print "Modem object path: " + mpath + "  (" + state + ")"
> -----
> 
> Let us know if any of this is unclear or if you've got more questions!
> 
> Dan
> 
> 

Thanks for all that, and sorry I've been distracted from this for a few
days. Got back to it and have one good modem I'm working on and one modem I've
not been able to modeswitch as yet. 

With the one that is switching I've got the DBus object. I was going to
attempt to connect with the Simple DBus interface but I'm pulling back a
SignalStrength of 0 so thought that might be to do with the current
state. That I'm sure just means that I have to activate the radio on the
device, so that gets into bearers and the like. So forget the Simple interface
as I don't want to just connect. I want to enable radios check coverage and
then connect.

All that means that I'd really like to use some of the enumerated types that
the DBus interface defines but struggling to find how to get them and use
them. So for example in your code you use states of {10: "Connecting", 11:
"Connected"} How would I use the enumeration:

http://www.freedesktop.org/software/ModemManager/api/latest/ModemManager-Flags-and-Enumerations.html#MMModemState

I'm looking into DBus tutorials and they never seem to go over
enumerations. Just using a bad search term I guess.






More information about the ModemManager-devel mailing list