Help please full duplex serial varriables gsm save use data strings
libadman
Posts: 36
Hello to all! I lam making an alram system using the propeller, I have a sim900 gsm module, my issue is im trying to read data sent from the gsm module and use it, I was using basic stamp with the wait command in order to read sms from module and another to look for password and command. I have not been using the propeller for more than 2 weeks now and since there is no santax manual some things im lost on. So far I have found a not so reliable way to read data from the gsm module, everything works however when I run the code and timeout occurs and/or the code cycles the ":" byte im waiting on is still there. Im not sure how to explain it so I will post my code and comment there.. Just having a hard time understanding spin. any help would be apreciated
CON
'Set up the clock mode
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
'5 MHz clock * 16x PLL = 80 MHz system clock speed
var
byte laz
Byte i, val[1]
Byte se[64]
LONG stack[20]
obj
ser : "FullDuplexSerial"
tv : "TV_Text"
pst : "Parallax Serial Terminal"
PUB Bu
tv.start(12) ' Pushbutton/Led Method
ser.start(1,2,%0000,2400) 'start the FullDuplexSerial object
waitcnt(cnt + (1 * clkfreq))
COGNEW(sen, @stack)
' dira[1] := 0 ' Door sensor on pin 1
'dira[2] := 0 ' livingroom window pin 2
'dira[3] := 0 ' kids window pin 3
'dira[4] := 0 ' my windown pin 4
'dira[5] := 0 ' motion sensor
'if buttons then do action
nh
pub nh
pub nm
tv.str(string(13,"Deleating All SMS Messages...",13))
waitcnt(cnt + (3 * clkfreq))
ser.Str(STRING("AT+CMGD=1,4"))
ser.Tx($0D)
PUB dor
ser.Str(STRING("AT + CMGR=1")) '
ser.Tx($0D) 'read sms ina[5]
waitcnt(cnt + (4 * clkfreq))
nh
PUB sen 'it never stops getting the : flush has no effect
repeat
SER.RXFLUSH 'try and clear the :
i[0]:=("0") 'try and clear the :
i[2]:=("0") 'try and clear the :
i[3]:=("0") 'try and clear the :
repeat until (i[0] := ser.Rx) == ":" 'wait on : after first run this wont wait its like the : is still there
tv.str(string("got the signal",13)) 'lets me know : showed up, this should be sms
i[0]:=(ser.rx) 'grab letter
i[1]:=(ser.rx) 'grab letter
i[2]:=(ser.rx) 'grab letter this will be checked
i[3]:=(ser.rx) 'grab letter this will be checked
if i[2]:="S" and i[3]:="M" 'if at this point there IS a sms, check and see if this is so
tv.str(string("Accepted",13)) ' if it is sms then let me know it is
ser.Str(STRING("AT + CMGR=1")) 'ask to read the text in location 1
ser.Tx($0D) ' carrige return required
repeat until (i[0] := ser.Rx) == "D" 'look for D---- response exspected +cmgr: "rec read","+18132222222","", date time ect
tv.str(string("Error D not recived")) 'did d loop quit, do this, only on timeout--? need help
sen
tv.str(string("SMS RECIVED FROM NUMBER:")) 'print this as for the next data to print is the phone number
i[0]:=(ser.rx) 'grab letter
i[1]:=(ser.rx) 'grab letter
i[2]:=(ser.rx) 'grab letter
i[3]:=(ser.rx) 'grab letter
i[4]:=(ser.rx) 'END TRASH 'grab letter
i[5]:=(ser.rx) 'start of useful information
i[6]:=(ser.rx) 'grab letter
i[7]:=(ser.rx) 'grab letter
i[8]:=(ser.rx) 'grab letter
i[9]:=(ser.rx) 'grab letter
i[10]:=(ser.rx) 'grab letter
i[11]:=(ser.rx) 'grab letter
i[12]:=(ser.rx) 'grab letter
i[13]:=(ser.rx) 'grab letter
i[14]:=(ser.rx) 'grab letter
TV.OUT(I[5]) 'prove i have the data
TV.OUT(I[6]) 'prove i have the data
TV.OUT(I[7]) 'prove i have the data
TV.OUT(I[8]) 'prove i have the data
TV.OUT(I[9]) 'prove i have the data
TV.OUT(I[10]) 'prove i have the data
TV.OUT(I[11]) 'prove i have the data
TV.OUT(I[12]) 'prove i have the data
TV.OUT(I[13]) 'prove i have the data
TV.OUT(I[14]) 'prove i have the data
TV.OUT(STRING("DONE")) 'lets me know routine is done
'after getting here the code restarts
sen 'start over
' waitcnt(cnt + (1 * clkfreq)) 'wait 1 second for the serial object to finish printing
pub nn
CON
'Set up the clock mode
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
'5 MHz clock * 16x PLL = 80 MHz system clock speed
var
byte laz
Byte i, val[1]
Byte se[64]
LONG stack[20]
obj
ser : "FullDuplexSerial"
tv : "TV_Text"
pst : "Parallax Serial Terminal"
PUB Bu
tv.start(12) ' Pushbutton/Led Method
ser.start(1,2,%0000,2400) 'start the FullDuplexSerial object
waitcnt(cnt + (1 * clkfreq))
COGNEW(sen, @stack)
' dira[1] := 0 ' Door sensor on pin 1
'dira[2] := 0 ' livingroom window pin 2
'dira[3] := 0 ' kids window pin 3
'dira[4] := 0 ' my windown pin 4
'dira[5] := 0 ' motion sensor
'if buttons then do action
nh
pub nh
pub nm
tv.str(string(13,"Deleating All SMS Messages...",13))
waitcnt(cnt + (3 * clkfreq))
ser.Str(STRING("AT+CMGD=1,4"))
ser.Tx($0D)
PUB dor
ser.Str(STRING("AT + CMGR=1")) '
ser.Tx($0D) 'read sms ina[5]
waitcnt(cnt + (4 * clkfreq))
nh
PUB sen 'it never stops getting the : flush has no effect
repeat
SER.RXFLUSH 'try and clear the :
i[0]:=("0") 'try and clear the :
i[2]:=("0") 'try and clear the :
i[3]:=("0") 'try and clear the :
repeat until (i[0] := ser.Rx) == ":" 'wait on : after first run this wont wait its like the : is still there
tv.str(string("got the signal",13)) 'lets me know : showed up, this should be sms
i[0]:=(ser.rx) 'grab letter
i[1]:=(ser.rx) 'grab letter
i[2]:=(ser.rx) 'grab letter this will be checked
i[3]:=(ser.rx) 'grab letter this will be checked
if i[2]:="S" and i[3]:="M" 'if at this point there IS a sms, check and see if this is so
tv.str(string("Accepted",13)) ' if it is sms then let me know it is
ser.Str(STRING("AT + CMGR=1")) 'ask to read the text in location 1
ser.Tx($0D) ' carrige return required
repeat until (i[0] := ser.Rx) == "D" 'look for D---- response exspected +cmgr: "rec read","+18132222222","", date time ect
tv.str(string("Error D not recived")) 'did d loop quit, do this, only on timeout--? need help
sen
tv.str(string("SMS RECIVED FROM NUMBER:")) 'print this as for the next data to print is the phone number
i[0]:=(ser.rx) 'grab letter
i[1]:=(ser.rx) 'grab letter
i[2]:=(ser.rx) 'grab letter
i[3]:=(ser.rx) 'grab letter
i[4]:=(ser.rx) 'END TRASH 'grab letter
i[5]:=(ser.rx) 'start of useful information
i[6]:=(ser.rx) 'grab letter
i[7]:=(ser.rx) 'grab letter
i[8]:=(ser.rx) 'grab letter
i[9]:=(ser.rx) 'grab letter
i[10]:=(ser.rx) 'grab letter
i[11]:=(ser.rx) 'grab letter
i[12]:=(ser.rx) 'grab letter
i[13]:=(ser.rx) 'grab letter
i[14]:=(ser.rx) 'grab letter
TV.OUT(I[5]) 'prove i have the data
TV.OUT(I[6]) 'prove i have the data
TV.OUT(I[7]) 'prove i have the data
TV.OUT(I[8]) 'prove i have the data
TV.OUT(I[9]) 'prove i have the data
TV.OUT(I[10]) 'prove i have the data
TV.OUT(I[11]) 'prove i have the data
TV.OUT(I[12]) 'prove i have the data
TV.OUT(I[13]) 'prove i have the data
TV.OUT(I[14]) 'prove i have the data
TV.OUT(STRING("DONE")) 'lets me know routine is done
'after getting here the code restarts
sen 'start over
' waitcnt(cnt + (1 * clkfreq)) 'wait 1 second for the serial object to finish printing
pub nn