Wait for SMS messages
Dan Williams
dan at ioncontrol.co
Wed Jan 29 16:39:32 UTC 2025
On Tue, 2025-01-28 at 12:05 +0000, Brendan Simon wrote:
>
> IND.T Classification: Public
>
>
>
> What's the best way to monitor and wait for SMS messages for
> processing?
> I'm using a Debian based system and python3.
> I was thinking of something involving systemd and/or a python package
> such asdbus_next.
With Python we'd typically use the bundled GObject introspection data
to directly work with libmm-glib. There are some examples in MM git:
https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/tree/main/examples?ref_type=heads
> I want to keep it simple, but I want to avoid a polling task and
> calls to mmcli to list messages and detect new ones by comparing
> previous listing.
> I.e. I want a task to sleep, waiting for an SMS message, and wake up
> when one is received so that it can be processed.
Yeah, avoiding polling is pretty easy. GLib-based programs use an event
loop pattern and sleep when they're not doing anything.
I added an SMS watcher example here:
https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/1284
Hopefully that's easy enough to follow, all questions welcome.
It does require a bit of D-Bus knowledge to fully understand the flow,
but even without that you just plug your own code into the SmsWatcher's
show() method and that'll run for any "new" SMS from any modem. I say
"new" in quotes because it'll also print out any messages in the modem
at the time it's run, then wait for new ones from the network or local
addition.
Hope that helps.
Dan
More information about the ModemManager-devel
mailing list