Successfully send sms with python
Laura Creighton
lac at openend.se
Wed Sep 23 05:30:29 EDT 2015
In a message of Tue, 22 Sep 2015 22:25:31 -0600, Michael Torrie writes:
<snip>
>Consider something like this with no error checking when using the
>serial port, no context managers for the serial device:
>file sms.py:
>----------------------
>import serial
>import time
>
>serial_port = 'COM13'
>timeout = 5
>baud = 460800
>
>def send_message(recipient, message):
> ser = serial.Serial(serial_port, baud, timeout=timeout)
> time.sleep(1)
> self.ser.write('ATZ\r')
> time.sleep(1)
> self.ser.write('AT+CMGF=1\r')
> time.sleep(1)
> self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r\n''')
> time.sleep(1)
> self.ser.write(self.content + "\r\n")
> time.sleep(1)
> self.ser.write(chr(26))
> time.sleep(1)
> print "message sent!"
>
> ser.close()
2 questions.
Why all the sleep(1)s?
and don't you need to flush the thing after each write?
Laura
More information about the Python-list
mailing list