Watching for registration with python

Dan Williams dcbw at redhat.com
Fri Sep 1 16:17:39 UTC 2017


On Fri, 2017-09-01 at 10:51 -0500, Dan Williams wrote:
> On Fri, 2017-09-01 at 14:26 +0100, colin.helliwell at ln-systems.com
> wrote:
> > I've been having a look at the modem-watcher-python example, and
> > would like
> > to do something similar - namely wait until the modem has
> > registered
> > on the
> > network and then grab the MCC/MNC.
> > Is there some sort of event I can hook for this (similar to what
> > the
> > example
> > does with ' object-added'), or do I just need to poll?
> > Thanks
> 
> ModemWatcher.py has the modem watching stuff already.  What you want
> to
> do is modify the on_object_added() method to:
> 
> 1) check modem.get_state() >= ModemManager.ModemState.REGISTERED
> 2) if yes, then grab the MCC/MNC with something like:
> 
>     mccmnc = obj.get_modem_3gpp().get_operator_code()
> 
> 3) if no, then connect to the 'state' property notifier:
> 
>         modem.connect('notify::state', self.modem_state_changed, obj)
> 
> and then have a separate function that handles that change:
> 
>     def modem_state_changed(self, modem, prop, obj):
>         if modem.get_state() >= ModemManager.ModemState.REGISTERED:
>             mccmnc = obj.get_modem_3gpp().get_operator_code()
> 
> The part I'm a bit fuzzy on now is getting the mcc/mnc, because for
> that you need to call obj.get_modem_3gpp() I think.

hah, skip this last sentence.  I went and figured it out, updated the
examples above, and then forgot to remove the sentence.

Dan


More information about the ModemManager-devel mailing list