Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions tools/sendsms.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def parseArgs():
parser.add_argument('-p', '--pin', metavar='PIN', default=None, help='SIM card PIN')
parser.add_argument('-d', '--deliver', action='store_true', help='wait for SMS delivery report')
parser.add_argument('destination', metavar='DESTINATION', help='destination mobile number')
parser.add_argument('--debug', action='store_true', help='turn on debug (serial port dump)')
parser.add_argument('message', nargs='?', metavar='MESSAGE', help='message to send, defaults to stdin-prompt')
return parser.parse_args()

def parseArgsPy26():
Expand All @@ -31,12 +33,14 @@ def parseArgsPy26():
parser.add_option('-b', '--baud', metavar='BAUDRATE', default=115200, help='set baud rate')
parser.add_option('-p', '--pin', metavar='PIN', default=None, help='SIM card PIN')
parser.add_option('-d', '--deliver', action='store_true', help='wait for SMS delivery report')
parser.add_option('--debug', action='store_true', help='turn on debug (serial port dump)')
parser.add_positional_argument(Option('--destination', metavar='DESTINATION', help='destination mobile number'))
options, args = parser.parse_args()
if len(args) != 1:
parser.error('Incorrect number of arguments - please specify a DESTINATION to send to, e.g. {0} 012789456'.format(sys.argv[0]))
else:
options.destination = args[0]
options.message = None
return options

def main():
Expand All @@ -45,8 +49,9 @@ def main():
sys.stderr.write('Error: No port specified. Please specify the port to which the GSM modem is connected using the -i argument.\n')
sys.exit(1)
modem = GsmModem(args.port, args.baud)
# Uncomment the following line to see what the modem is doing:
#logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)
if args.debug:
# enable dump on serial port
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)

print('Connecting to GSM modem on {0}...'.format(args.port))
try:
Expand All @@ -65,8 +70,11 @@ def main():
modem.close()
sys.exit(1)
else:
print('\nPlease type your message and press enter to send it:')
text = raw_input('> ')
if args.message is None:
print('\nPlease type your message and press enter to send it:')
text = raw_input('> ')
else:
text = args.message
if args.deliver:
print ('\nSending SMS and waiting for delivery report...')
else:
Expand Down