I 99% of finishing my script but have run into a problem
im trying to display the text messages recived from a GSM modem in python.
So far I can read that a text has come in but cant display the message.
I know the self.ser.readlines() comes back as a list
import serial
import time
class TextMessage:
def connectPhone(self):
self.ser = serial.Serial('COM14', 460800, timeout=5) #for mine this was ttyUSB0 but could be ttyUSB1 etc. good idea to runs ls usb and find out that way
time.sleep(1)
def read(self):
self.ser.write('ATZ\r')
time.sleep(1)
self.ser.write('AT+CMGF=1\r')# put in textmode
time.sleep(1)
self.ser.write('''AT+CMGL="ALL"''' + '''\r''') #fetch all sms's
read = self.ser.readlines()
for msg in read:
if "+CMGL" in msg: #+CMGL looks for all SMS messages
print msg
def disconnectPhone(self):
self.ser.close()
sms = TextMessage()
sms.connectPhone()
sms.read()
sms.disconnectPhone()
raw_input("Press anykey to exit")
here is output
AT+CMGL="ALL"
+CMGL: 0,"REC READ","+61xxxxxxxxx",,"16/04/30,19:53:38+38"
+CMGL: 1,"REC READ","+61xxxxxxxxx",,"16/05/02,14:47:53+38"
+CMGL: 2,"REC READ","+61xxxxxxxxx",,"16/05/02,21:27:58+38"
My desired output would be
+CMGL: 0,"REC READ","+61xxxxxxxxx",,"16/04/30,19:53:38+38"
Test back
+CMGL: 1,"REC READ","+61xxxxxxxxx",,"16/05/02,14:47:53+38"
Im a message
+CMGL: 2,"REC READ","+61xxxxxxxxx",,"16/05/02,21:27:58+38"
TEST TEST TEST
Can anyone assist?
Output with if removed
ATZ
OK
AT+CMGF=1
Ok
AT+GCML="ALL"
+CMGL: 0,"REC READ","+61xxxxxxxxx",,"16/04/30,19:53:38+38"
Test back
+CMGL: 1,"REC READ","+61xxxxxxxxx",,"16/05/02,14:47:53+38"
Im a message
+CMGL: 2,"REC READ","+61xxxxxxxxx",,"16/05/02,21:27:58+38"
TEST TEST TEST
OK