How can I retrieve the text sms from a modem device with Python?

I am trying to read text sms from a attached modem and then send an sms in reply with Python. I am using Python 2.7 on Windows 7 and my modem is Huawei E1550. After lots of googling, I have successfully send an sms but I failed to read any sms from the modem. My codes are below:

import serial
import time

#FOR SENDING:

def Sending(message, sender):
SerialPort = serial.Serial(“COM46”,115200)
SerialPort.write(‘AT+CMGF=1\r’)
time.sleep(1)
SerialPort.write(‘AT+CMGS="’+sender+'"
')
time.sleep(1)
SerialPort.write(message+“\x1A”)
time.sleep(1)
print ‘message sent’

x = raw_input("type the number:
")
y = raw_input("type the message:
")

Sending(y,x)

#FOR READING:

def readSMS():
SerialPort = serial.Serial(“COM46”,115200)
list = SerialPort.write(“AT+CMGL=ALL”)
msg = []
for item in list:
#print item
if item.startswith(“+CMGL:”) == False:
if item!=“OK”:
msg.append(item)
print msg

1 Like

Digi provides a digisms module you can use on your Gateway to get the SMS messages, you don’t have to try to access the modem directly, and are likely to not be successful if you try.