PDA

View Full Version : wait for a string



sahin5002
- 1st April 2009, 13:05
when i try to read sms 5 then I am waiting for the user no "8801717101959"
then this code is fine




SerOut2 txd,Baud,["at+cmgr=5",13]
SerIn2 rxd,Baud,500,delet_sms,[wait ("+8801717101959")]



But I am trying to wait for a string " str phoneno\14 "
Because the authorized phone no is in phoneno[14]

Please help me

BobPigford
- 1st April 2009, 19:23
Hello,
While I am not an expert, I am confused by the line in your code that reads:
SerIn2 rxd,Baud,500,delet_sms,[wait ("+8801717101959")]
That command will wait for that string for 500 milliseconds, and if it is not received, it will jump to the label delet_sms.

What seems to be missing is the variable into which you want to stuff subsequent serial input that will follow "+8801717101959". Is that variable named phoneno?

Remember that the string you wait for is not the data part of the input, it is just a trigger to accept what follows and place it into a variable. If I have understood your intentions correctly, you want to gather some additional set of numbers and place them into a variable after receiving that quoted string "+8801717101959". If so, your syntax could be:
SERIN2 rxd,Baud,500,delet_sms,[wait ("+8801717101959"), phoneno]

Is this what you had intended?

Bob

Ioannis
- 1st April 2009, 19:46
And why especially message 5? Are yousure about this?

What if you have deleted already one and now you have 4 SMS?

Ioannis

sahin5002
- 1st April 2009, 20:41
SerOut2 txd,Baud,["at+cmgr=5",13]
SerIn2 rxd,Baud,500,delet_sms,[wait ("+8801717101959")]


I just read sms memory index 5, and check the sender no by waiting the phone no [wait ("+8801717101959")]. Its a authorized phone no. If the sender phone no don't match then I delete it. If match then i know what to do.(Tested)

I always read and delete index 5. So any new sms first arrive in index 5.


My problem is, the authorized phone no saved in EEprom. And its may change time to time. So I need to wait for a string type array.

I have tried with that . But compiler show error this line

SerIn2 rxd,Baud,500,delet_sms,[wait("#str phoneno\14"),skip 32,str inbox\8]

aratti
- 1st April 2009, 22:38
This snippet should solve your problem.

EEprom 0,[49,55,49,55,49,48,57,53,57] ' your number without the area code 1717101959

InBox var Byte [8] ' make your array larger so you can use a byte as command
Num0 var Byte [9]
Num1 var Byte [9]
Flag var byte
Try var Byte
A0 var Byte

For A0=0 to 9
Read A0,Num0[A0] ' here you load you number in array Num0
Next A0


IniCall:
Try=Try+1
If Try>5 then delet_sms ' if counter >5 then abort ( if 5 cycles are too many reduce them to an acceptable number)
SerOut2 txd,Baud,["at+cmgr=5",13]
SerIn2 rxd,Baud,1000,IniCall,[wait ("+880"),Str Num1\9,skip 32,str inbox\8] ' here you load the incoming number into array Num1

Try=0
Flag=1
For A0=0 to 9
If Num0[A0]<>Num1[A0] then Flag=0 ' here you compare the two array if not all digits agree then Flag is set to zero
next A0

If flag=0 then delet_sms ' flag reports "not corrected number" so delete sms


'your code here to work with the array inbox

goto mainLoop ' your code mainLoop

delet_sms:
Try=0

' your code for deleting sms


'If you make an inbox array equal to 11 elements then you can use it to change the number when needed
For instance if inbox[10]= 100 then gosub Change


Change:

For A0 =0 to 9
Write A0, inbox[A0]
Num0[A0]=inbox[A0]
Next A0
Return





Your number is stored into the eeprom and is loaded in the array Num0 at runtime. I am not sure if "880" is the area code.

If Try>5 then there is not sms, so you don't need to delete it. Trying to delete is dangerous because you could delete an incoming sms.

Al.

Ioannis
- 2nd April 2009, 13:58
My question still is what if you have deleted all SMS and the new valid arrives at location 1?

Ioannis

sahin5002
- 2nd April 2009, 20:10
sms index 1,2,3,4 are used to store the emergency sms. These sms are used to notify the user .

sahin5002
- 2nd April 2009, 20:17
Hi aratti . Thanks for your help. I have solved it.
Can you please inform me one more thing, When any new sms arrived, the GSM modem send a notification " +CMTI: "SM",5 " .

How i can use this notification to interrupt in my program.

Ioannis
- 2nd April 2009, 21:44
Your program might be interrupted only by an Hardware Interrupt, say from the USART module.

So, if you want a fast interrupt system, have a look at Darrels Instant Interrupt.

Then every time you have an RS-232 activity, the ISR will take care of the event. Store the incoming data in an array and do a compare byte-to-byte with a stored reference array, say in the EEPROM.

I am working on a similar project and may post a snipet as soon as I get it working.

Ioannis

xxxxxx
- 2nd April 2009, 22:37
Your program might be interrupted only by an Hardware Interrupt, say from the USART module.

So, if you want a fast interrupt system, have a look at Darrels Instant Interrupt.

Then every time you have an RS-232 activity, the ISR will take care of the event. Store the incoming data in an array and do a compare byte-to-byte with a stored reference array, say in the EEPROM.

I am working on a similar project and may post a snipet as soon as I get it working.

Ioannis

that would be nice :D

--
http://www.mtskola.com

aratti
- 2nd April 2009, 23:02
Can you please inform me one more thing, When any new sms arrived, the GSM modem send a notification " +CMTI: "SM",5 " .

How i can use this notification to interrupt in my program.

The best way is the one that Ioannis suggested you in post #9.

For "HSERIN" instruction you have to use specific pins of your pic micro (you didn't say the type), which are the USART module, plus the DT interrupt routine.

Serch the forum for DT interrupt to learn more or go to this link: http://www.picbasic.co.uk/forum/showthread.php?t=3251


XXXXX you can download the project for sms controller at this link:http://techni.caliti.es/blog/2008/12/sms-io-controller.html

since the project is well documented, you could see the technique used to activate 8 relays or read the status of 8 inputs all via sms command.


Al.

xxxxxx
- 2nd April 2009, 23:27
The best way is the one that Ioannis suggested you in post #9.

For "HSERIN" instruction you have to use specific pins of your pic micro (you didn't say the type), which are the USART module, plus the DT interrupt routine.

Serch the forum for DT interrupt to learn more or go to this link: http://www.picbasic.co.uk/forum/showthread.php?t=3251


XXXXX you can download the project for sms controller at this link:http://techni.caliti.es/blog/2008/12/sms-io-controller.html

since the project is well documented, you could see the technique used to activate 8 relays or read the status of 8 inputs all via sms command.


Al.

:D yes but i want to make my own :D....."why make things simple if you could complicate them"