def test_smsd(self): smsd = self.get_smsd() # Inject SMS messages # Please note that SMSD is not thread safe, so you can not # use inject and main loop from different threads smsd.InjectSMS([MESSAGE_1]) smsd.InjectSMS([MESSAGE_2]) try: # Start SMSD thread smsd_thread = threading.Thread(target=smsd.MainLoop) smsd_thread.start() # We need to let it run for some time here to finish initialization time.sleep(10) # Show SMSD status retries = 0 while retries < 2: status = smsd.GetStatus() if status['Sent'] >= 2: break time.sleep(10) retries += 1 self.assertEqual( status['Received'], 2, 'Messages were not received as expected (%d)!' % status['Received'] ) self.assertEqual( status['Sent'], 2, 'Messages were not sent as expected (%d)!' % status['Sent'] ) time.sleep(1) finally: # Signal SMSD to stop smsd.Shutdown() # Wait for it smsd_thread.join()
#!/usr/bin/env python # -*- coding: UTF-8 -*- # vim: expandtab sw=4 ts=4 sts=4: # # Copyright © 2003 - 2018 Michal Čihař <*****@*****.**> # # This file is part of python-gammu <https://wammu.eu/python-gammu/> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU 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 General Public License for more details. # # You should have received a copy of the GNU 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. # """Sample script to show how to get SMSD status""" from __future__ import print_function import gammu.smsd smsd = gammu.smsd.SMSD('/etc/gammu-smsdrc') print(smsd.GetStatus())
# Please note that SMSD is not thread safe, so you can not use inject and main loop from different threads message = {'Text': 'python-gammu testing message', 'SMSC': {'Location': 1}, 'Number': '1234567890'} smsd.InjectSMS([message]) message = {'Text': 'python-gammu second testing message', 'SMSC': {'Location': 1}, 'Number': '1234567890'} smsd.InjectSMS([message]) # Start SMSD thread smsd_thread = threading.Thread(target = smsd.MainLoop) smsd_thread.start() # We need to let it run for some time here to finish initialization time.sleep(10) # Show SMSD status retries = 0 while retries < 60: status = smsd.GetStatus() for k in status.keys(): print '%s: %s' % (k, status[k]) print if status['Sent'] >= 2: break time.sleep(10) retries += 1 if status['Sent'] != 2: raise Exception('Messages were not sent as expected (sent = %d)!' % status['Sent']) time.sleep(1) finally: # Signal SMSD to stop
#!/usr/bin/env python # sample script to show how to get SMSD status import gammu.smsd smsd = gammu.smsd.SMSD('/etc/gammu-smsdrc') print smsd.GetStatus()