Commit aa28a3b9c3faced38b5dd95e7d12b44dd2af17e5
1 parent
d963f90960
Exists in
master
ussdcmd
Showing 1 changed file with 31 additions and 0 deletions Side-by-side Diff
ussdcmd.py
... | ... | @@ -0,0 +1,31 @@ |
1 | +#!/usr/bin/env python | |
2 | + | |
3 | +import sys | |
4 | +import ConfigParser | |
5 | +from gsmmodem.modem import GsmModem | |
6 | +from gsmmodem.exceptions import TimeoutException | |
7 | + | |
8 | +config = ConfigParser.RawConfigParser() | |
9 | +config.read('config.ini') | |
10 | + | |
11 | +PORT = config.get('globals','PORT') | |
12 | +BAUDRATE = config.getint('globals', 'BAUDRATE') | |
13 | +PIN = None # SIM card PIN (if any) | |
14 | + | |
15 | +logging.info('Initializing modem...') | |
16 | +modem = GsmModem(PORT, BAUDRATE) | |
17 | +modem.smsTextMode = True | |
18 | +modem.connect(PIN) | |
19 | + | |
20 | +logging.info('Waiting for network coverage...') | |
21 | +modem.waitForNetworkCoverage(10) | |
22 | +logging.info('Modem ready') | |
23 | + | |
24 | +ussd_command = sys.argv[1] | |
25 | +response = modem.sendUssd(ussd_command, TOPUP_USSD_TIMEOUT) | |
26 | +message = response.message.strip() | |
27 | +logging.info(u'USSD response: {0}'.format(message)) | |
28 | + | |
29 | +if response.sessionActive: | |
30 | + response.cancel() | |
31 | + |