Successfully send sms with python

mm0fmf none at mailinator.com
Tue Sep 22 18:27:35 CEST 2015


On 22/09/2015 12:19, Timon Rhynix wrote:
> Hello, I have used pyserial, sms0.4 and other libraries to send sms via huawei E1750 modem.
> The code runs well and no error is thrown but the text message is not sent/delivered to the number.
> One of my code is as follows:
>
> import serial
> import time
>
> class TextMessage:
>      def __init__(self, recipient="0123456789", message="TextMessage.content not set."):
>          self.recipient = recipient
>          self.content = message
>
>      def setRecipient(self, number):
>          self.recipient = number
>
>      def setContent(self, message):
>          self.content = message
>
>      def connectPhone(self):
>          conn = 'COM13'
>          self.ser = serial.Serial(conn, 460800, timeout=5)
>          time.sleep(1)
>
>      def sendMessage(self):
>          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''')
>          time.sleep(1)
>          self.ser.write(self.content + "\r")
>          time.sleep(1)
>          self.ser.write(chr(26))
>          time.sleep(1)
>          print "message sent!"
>
>      def disconnectPhone(self):
>          self.ser.close()
>
> When run it, the "message sent!" is printed but no message is sent/delivered.
> Please assist on what I am missing. Thank you
>

If it's like the GSM modem I used then you should replace those "\r" 
strings with "\r\n".




More information about the Python-list mailing list