I want to read two lines from AT Command's output and do INSERT INTO table VALUES in python. The output of AT is always in two rows but it's a sequence, unlike open file and read it until the next limiter, but we have to wait.
anyway this is my code:
class SMSWait(self):
def run(self):
self.open()
while self.ser.isOpen():
time.sleep(1)
SMSRead = 'AT+CMGL="ALL"\r\n'
self.SendCommand(SMSRead, getline=True)
while self.ser.inWaiting() > 0:
**data = self.ser.readall()
print data**
def open(self):
self.ser = serial.Serial('/dev/ttyUSB0', baudrate=115200, timeout=.1, rtscts=0)
self.SendCommand('AT\r')
self.SendCommand('AT+CMGF=1\r')
self.ser.flushInput()
self.ser.flushOutput()
def SendCommand(self,command, getline=True):
self.ser.write(command)
data = ''
if getline:
data = self.ReadLine()
data = filter(None, data)
return data
def ReadLine(self):
data = self.ser.readline()
return data
it will show the output:
AT+CMGL="ALL"
+CMGL: 2,"REC READ","+60xxxxxxxxx",,"15/02/05,14:13:47+28"
mydata43414242453564567578689789done
OK
now, how do i process this "sequence" output and ignoring the AT+CMGL="ALL" and "OK" and put them to database using "insert into" in one query. i don't have problem with accessing database using python. and i'm okay with regex. maybe someone could help me logically or script. thank you