diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2016-07-25 10:36:42 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2016-07-25 12:51:45 +0200 |
commit | 24fd3ef5fb2b4795e7f3bad96d16ee36758e9e8d (patch) | |
tree | a732fb4165e41aae5dcbdd9b6ffd0fd1c1b6e907 | |
parent | a7942177c9f969faec1d767c67d4019a61dc7e16 (diff) | |
download | ModemManager-24fd3ef5fb2b4795e7f3bad96d16ee36758e9e8d.tar.gz |
examples: add SMS sender in python
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | examples/Makefile.am | 2 | ||||
-rw-r--r-- | examples/sms-python/Makefile.am | 4 | ||||
-rw-r--r-- | examples/sms-python/README | 20 | ||||
-rwxr-xr-x | examples/sms-python/sms-python | 51 |
5 files changed, 77 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 5b2427ca5..30415db4c 100644 --- a/configure.ac +++ b/configure.ac @@ -375,6 +375,7 @@ cli/Makefile examples/Makefile examples/modem-watcher-python/Makefile examples/modem-watcher-javascript/Makefile +examples/sms-python/Makefile ]) AC_OUTPUT diff --git a/examples/Makefile.am b/examples/Makefile.am index 53b0b70e6..ba2da3686 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1 +1 @@ -SUBDIRS = modem-watcher-python modem-watcher-javascript +SUBDIRS = modem-watcher-python modem-watcher-javascript sms-python diff --git a/examples/sms-python/Makefile.am b/examples/sms-python/Makefile.am new file mode 100644 index 000000000..8ecca80b0 --- /dev/null +++ b/examples/sms-python/Makefile.am @@ -0,0 +1,4 @@ + +EXTRA_DIST = \ + sms-python \ + $(NULL) diff --git a/examples/sms-python/README b/examples/sms-python/README new file mode 100644 index 000000000..50a1cc55f --- /dev/null +++ b/examples/sms-python/README @@ -0,0 +1,20 @@ + +The sms-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-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!
\ No newline at end of file diff --git a/examples/sms-python/sms-python b/examples/sms-python/sms-python new file mode 100755 index 000000000..2d572f188 --- /dev/null +++ b/examples/sms-python/sms-python @@ -0,0 +1,51 @@ +#!/usr/bin/env python +# -*- 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 <aleksander@aleksander.es> +# + +import sys, signal, gi + +gi.require_version('ModemManager', '1.0') +from gi.repository import GLib, GObject, Gio, ModemManager + +if __name__ == "__main__": + + # Process input arguments + if len(sys.argv) != 3: + sys.stderr.write('error: wrong number of arguments\n') + sys.stdout.write('usage: sms-python <NUMBER> <TEXT>\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 manager.get_name_owner() is None: + 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()) |