Go Down

Topic: Need help about receiving a SMS from SIM900 module and doing something with it (Read 74 times) previous topic - next topic

Caenem

Hello everyone,
I'm currently working on a weather station project, precisely on the communication part.
It means that i'm working with a SIM900 module to send alert SMS and GPS coordinates if the user send a SMS with a sort of password (like in ads : send LOVE to 66900).
And it's for the gps coordinates part that i ask help here, for the moment this is what i did
Code: [Select]
//Num module : +33768265074 // ! // Maxime : +33786284633 // ! // 44.7260358,5.021091 //
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7,8);    // RX, TX
char mdp[] = "Test"; // we compare this to the content of incoming SMS
boolean sms;

void setup()
{     
  SIM900.begin(9600); // Init module (SIM900)
  Serial.begin(9600); // Init serial communication
  delay(500);
  Serial.println("Waiting for SMS");
  sms = true;
}

void loop()
{
  if(sms == true)
  {
    receivesms();
    sms = false;
  }
    if(SIM900.available())
    {
      Serial.write(SIM900.read()); // Write in the serial monitor the messages
    }
    /*
      if(SIM900.read() == mdp) // So this is this if that makes trouble, this line should be supposed to check if the user entered the right "password"
      {
        Serial.println("ok"); // A little confirmation
      }
      */
     
}

void receivesms()
{
  SIM900.println("AT+CMGF=1\r");   // SMS mode
  SIM900.println("AT+CMGL=\"ALL\"\r"); // Display all messages
  delay(1000);
}

And here's a screen of what it does :

Simple it just displays in the serial monitor the incoming messages.

In this first program you can see that i commented the "if(SIM900.read() == mdp) and what's in inside too"; because this is what makes me an error, and if i uncomment like this :
Code: [Select]
//Num module : nothing // ! // Maxime : +youwillnothavehisnumber:p // ! // 44.7260358,5.021091 //
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7,8);    // RX, TX
char mdp[] = "Test"; // we compare this to the content of incoming SMS
boolean sms;

void setup()
{     
  SIM900.begin(9600); // Init module (SIM900)
  Serial.begin(9600); // Init serial communication
  delay(500);
  Serial.println("Waiting for SMS");
  sms = true;
}

void loop()
{
  if(sms == true)
  {
    receivesms();
    sms = false;
  }
    if(SIM900.available())
    {
      Serial.write(SIM900.read()); // Write in the serial monitor the messages
    }
   
      if(SIM900.read() == mdp) // So this is this if that makes trouble, this line should be supposed to check if the user entered the right "password"
      {
        Serial.println("ok"); // A little confirmation
      }
     
     
}

void receivesms()
{
  SIM900.println("AT+CMGF=1\r");   // SMS mode
  SIM900.println("AT+CMGL=\"ALL\"\r"); // Display all messages
  delay(1000);
}


It is like there is a transmission problem because it displays weird caracters ( baud rate is ok though).
I don't know if it comes from the "mdp" variable or the "SIM900.read()".

So I think I described well my problem, feel free to ask things it can only be helpful  :)


Link for gsm module if you are interested : http://wiki.seeed.cc/GPRS_Shield_v1.0/ (i haven't been paid by the brand for this link)

PaulS

Quote
In this first program you can see that i commented the "if(SIM900.read() == mdp) and what's in inside too"; because this is what makes me an error, and if i uncomment like this
SIM900.read() returns ONE character. One character will never equal a string.

Do you understand what read() does with respect to the incoming serial buffer?

You need to look at Robin2's tutorial on serial data processing.
http://forum.arduino.cc/index.php?topic=396450.0
Your code should have EXACTLY one call to SIM900.read() in it, NOT two like it has now.
The art of getting good answers lies in asking good questions.

Caenem

Thanks i'll read the guide. But is there a way to modify
Code: [Select]
Serial.write(SIM900.read());
To manage that there's only one call of SIM900.read() like you said.

PaulS

Quote
But is there a way to modify ... To manage that there's only one call of SIM900.read() like you said.
Code: [Select]
  char c = SIM900.read();

  Serial.print(c);

  if(c == 'b')

One read; two uses of the same character.
The art of getting good answers lies in asking good questions.


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy