From c320e50753e544e3277280ee53b10eadcdd46fdb Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 29 Jan 2025 10:20:18 -0600 Subject: examples: add sms-watch-python Add an example that watches for and prints all SMS messages of all modems. Signed-off-by: Dan Williams --- examples/sms-send-python/README | 20 +++++++++++ examples/sms-send-python/sms-send-python | 59 ++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 examples/sms-send-python/README create mode 100755 examples/sms-send-python/sms-send-python (limited to 'examples/sms-send-python') diff --git a/examples/sms-send-python/README b/examples/sms-send-python/README new file mode 100644 index 00000000..3927c743 --- /dev/null +++ b/examples/sms-send-python/README @@ -0,0 +1,20 @@ + +The sms-send-python program makes use of the 'libmm-glib' library through +GObject Introspection to talk to ModemManager. + +The program will: + * Detect whether ModemManager is found in the bus + * Prepare SMS properties object with the provided Number and Text. + * Loop through each modem found in the system, and for each: + ** Create a SMS + ** Send the SMS + +The output will look like this: + +$ ./sms-send-python "+1234567890" "hello there, how are you?" +/org/freedesktop/ModemManager1/Modem/0: sms sent + +Note that the program requires ModemManager and libmm-glib to be installed in +the system and the introspection typelibs available in the standard paths. + +Have fun! diff --git a/examples/sms-send-python/sms-send-python b/examples/sms-send-python/sms-send-python new file mode 100755 index 00000000..46d5e692 --- /dev/null +++ b/examples/sms-send-python/sms-send-python @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; either version 2 of the License, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright (C) 2016 Aleksander Morgado +# + +import sys + +import gi +gi.require_version('ModemManager', '1.0') +from gi.repository import Gio, GLib, GObject, ModemManager + + +def main(): + """Main routine.""" + + # Process input arguments + if len(sys.argv) != 3: + sys.stderr.write('error: wrong number of arguments\n') + sys.stdout.write('usage: sms-python \n') + sys.exit(1) + + # Prepare SMS properties + sms_properties = ModemManager.SmsProperties.new() + sms_properties.set_number(sys.argv[1]) + sms_properties.set_text(sys.argv[2]) + + # Connection to ModemManager + connection = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) + manager = ModemManager.Manager.new_sync( + connection, Gio.DBusObjectManagerClientFlags.DO_NOT_AUTO_START, None) + if not manager.get_name_owner(): + sys.stderr.write('ModemManager not found in bus') + sys.exit(2) + + # Iterate modems and send SMS with each + for obj in manager.get_objects(): + messaging = obj.get_modem_messaging() + sms = messaging.create_sync(sms_properties) + sms.send_sync() + print('%s: sms sent' % messaging.get_object_path()) + + +if __name__ == "__main__": + main() -- cgit v1.2.3-70-g09d2