Hello!
I am currently using Arduino Uno and a compatible GSM Shield.
I am trying to receive an SMS with some characters("#ok" in my code), analyze these characters, and if they match with what Arduino is expecting(#ok), Arduino must control the state of a digital port and send an SMS to a defined number.
Please someone can help me? I am getting nowhere...
So, running through your code by hand. We run setup() to configure everything, fine. Then we run loop(). This calls the function receiveSMS(). Let's assume that there's nothing there at the moment - SIM900.available()==0 - so it drops through and returns to loop(). Then we have an infinite loop....
If there is something available, perhaps information returned from the previous commands, and the first character isn't a '#', then drop through and return to loop() - as above.
Perhaps what you want to do is if there is something to read, read it, and if '#' then process. If not, discard and wait for the next character to appear?
dannable:
If there is something available, perhaps information returned from the previous commands, and the first character isn't a '#', then drop through and return to loop() - as above.
Perhaps what you want to do is if there is something to read, read it, and if '#' then process. If not, discard and wait for the next character to appear?
Basically, I think you understood right. I send an SMS from another phone with the text: #ok.
It reads the stream from the shield(I guess, because I don't figured out perfectly how it works), if the stream contains '#', keep reading. If the next character is 'o', keep reading and the same thing for the 'k'. Once it recognizes that the last character was 'k', it means it received #ok and return true.
If input == true, the loop() calls sendSMS(), which, internally does a control on the pin state(LOW or HIGH) and communicates the state via SMS to the given number.
Yes, once you have a '#', then check the next is 'o' and then the next is 'k'. Then set the flag. Otherwise, keep reading! But don't forget to allow for, say, '##ok' coming through
You could always echo the character read to the screen to see what is happening?
dannable:
You could always echo the character read to the screen to see what is happening?
I'm sorry but I think I didn't understand your question.
I think the problem is in receiving and interpreting the sms, because the sending part works, already tested.
Ok.
No, I haven't done it until now. I'll try a little bit later, because I have not the possibility to use a second SIM card now.
I will update you as soon as possible.
Hi ,
You will possibly need two changes in your program
SIM900.print("AT+CNMI=2,2,0,0,0\r");
move this command to the void setup() loop
and to find the "#ok" in the receivng sms you can use "indexof" command
try this
String inchar;
if(SIM900.available()>0)
{
inchar=SIM900.read();
if(inchar.indexOf("#ok") >=0) // this command will check if your messgae received has got #ok in it .
Hope this post is helpful
All the best
check this link also .. this wil help you receive sms and once you received you just use that indexof command..