Pages: [1]   Go Down
Author Topic: SMS reading with Arduino + SM5100B-D  (Read 2645 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello i need your help with this. Here is the code:

Code:
#include <SoftwareSerial.h> //Sarjaliikennekäskyille
#include <string.h>

char incoming_char = 0; //Tuleva viesti Serial Portilta
char mobilenumber[]="xxxxxxxxxx";
char textmessage[160];
int b=0;


SoftwareSerial cell(2,3); // 2 = RX(Receive) ja 3 = TX(Transmit)
void startSMS();
void endSMS();
void SendGPSLocation();

void setup()
{
   Serial.begin(4800);
   cell.begin(4800);
   Serial.println("Starting SM5100B Communication...");
   Serial.println("Waiting for GPS signal...");
 
}
void loop()
{
  //--------------------------------------------GSM----------------------------------
  if(cell.available() >0)
    {
   
       incoming_char=cell.read();    //Get the character from the cellular serial port.
       Serial.print(incoming_char);  //Print the incoming character to the terminal.
    }
  if(Serial.available() >0)
    {
      incoming_char=Serial.read();  //Get the character coming from the terminal
      cell.print(incoming_char);    //Send the character to the cellular module.
     
      if (incoming_char == 'k')
      {
        SendGPSLocation();
      }
 
    }
   
     
}
void startSMS()
{
digitalWrite(13, HIGH);
cell.println("AT+CMGF=1"); // set SMS mode to text
cell.print("AT+CMGS=");
cell.print((char)13); // ASCII equivalent of "
cell.print(mobilenumber);
cell.println((char)13);  // ASCII equivalent of "
delay(500); // give the module some thinking time
}

void endSMS()
{
cell.println((char)26);  // ASCII equivalent of Ctrl-Z
delay(15000); // the SMS module needs time to return to OK status
digitalWrite(13, LOW);
}

 void SendGPSLocation()
{
  startSMS();
  cell.print("Koordinaatit:");
  cell.print(incoming_char);
  endSMS();
}

And in there where are my "if's" i need a new if which check if i had send a sms "Coordinates" then it will go to SendGPSLocation();

Code:
void loop()
{
  //--------------------------------------------GSM----------------------------------
  if(cell.available() >0)
    {
   
       incoming_char=cell.read();    //Get the character from the cellular serial port.
       Serial.print(incoming_char);  //Print the incoming character to the terminal.
    }
  if(Serial.available() >0)
    {
      incoming_char=Serial.read();  //Get the character coming from the terminal
      cell.print(incoming_char);    //Send the character to the cellular module.
     
      if (incoming_char == 'k')
      {
        SendGPSLocation();
      }
 
    }
   
     
}


Thanks i hope you can help me with this!!! =)
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49272
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
And in there where are my "if's" i need a new if which check if i had send a sms "Coordinates" then it will go to SendGPSLocation();
You need a lot more than that. You currently aren't even storing the data that you get. Not storing it means that there is no possibility of parsing the data. With nothing to parse, there are no coordinates.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"incoming_char" contains the gps coordinates.... and i only need to know how to check incoming SMS and read it with Uno and check if that SMS contains rigth letters.........
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49272
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
"incoming_char" contains the gps coordinates
O
n
e

c
h
a
r
a
c
t
e
r

a
t

a

t
i
m
e
.

You must store them in an array, until the end of the message is detected. Then, you can parse the data.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well then i also need help with that... How can i do that? And the SMS still.... Is somewhere a project which i can take a look???
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49272
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is somewhere a project which i can take a look???
It isn't any different from reading from Serial or reading from EthernetClient. Look at any of the bazillions of examples around. Or just try something.

Start with the simplest task. Define an array to put data in. Define an index into that array. Increment the index after storing a character. Add a NULL to the array, without incrementing the index. Then, all that is left to do is to reset the index value at the appropriate time, and stuff a NULL in the array at the new index location.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to make a program using arduino and GPRS Shield sld33149p, so when I send SMS from my mobile phone to GPRS shield, GPRS shield will send SMS back to my phone

* sketch_nov05b.ino (1.08 KB - downloaded 28 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to make a program using arduino and GPRS Shield sld33149p, so when I send SMS from my mobile phone to GPRS shield, GPRS shield will send SMS back to my phone

#include <SoftwareSerial.h>
#include <String.h>
char pesan;
SoftwareSerial mySerial(7, smiley-cool;
 
void setup()
{
  mySerial.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);    // the GPRS baud rate
  delay(500);
}
 
void loop()
{
  if (mySerial.available()){
  pesan=mySerial.read();
  mySerial.print(pesan);
  if (pesan=='suhu'){
  kirim();}}
  //after start up the program, you can using terminal to connect the serial of gprs shield,
  //if you input 't' in the terminal, the program will execute SendTextMessage(), it will show how to send a sms message,
  //if input 'd' in the terminal, it will execute DialVoiceCall(), etc.
}

void kirim(){
   mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
 
  mySerial.println("AT + CMGS = \"+628975476477\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  mySerial.println("A test message!");//the content of the message
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();}
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49272
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
char pesan;

pesan=mySerial.read();
if (pesan=='suhu')
How do you propose to send 'suhu' as ONE character?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So how? I must using string?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49272
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So how? I must using string?
Yes. Use string. NOT String.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I already use string to declare pesan instead use char. but after i compile the program.it say that string isn't data type. When I use String to declare pesan, after compile the program, there is an error. it say invalid convertion from int to const char. the error is in this line pesan=mySerial.read();
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49272
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I already use string to declare pesan instead use char. but after i compile the program.it say that string isn't data type.
And it's right. A string is a NULL terminated array of chars, not a separate type.

Quote
When I use String to declare pesan, after compile the program, there is an error. it say invalid convertion from int to const char.
And it's right. You can't assign an int (what you get from Serial.read()) to a String.

There are dozens of examples of how to read serial data (one character at a time), and store them in an array. Hey, look, here's one:
Code:
#define SOP '<'
#define EOP '>'

bool started = false;
bool ended = false;

char inData[80];
byte index;

void setup()
{
   Serial.begin(57600);
   // Other stuff...
}

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

Your sender should be delimiting the stuff you are trying to parse in some way that makes it easy for you to read.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Besides data type problem, is there any problem from GPRS shield to read SMS? Actually I don't get it how to make GPRS shield know that I send SMS to it.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi again. Now i have function which will get altitude and longitude. How can i do a check up when i ask by SMS coordinates and my code will perform a certain function after that. Heres my new code:

Code:
#include <TinyGPS.h>
#include <SoftwareSerial.h> //Sarjaliikennekäskyille
#include <string.h>
#define RXPIN 2
#define TXPIN 3

char incoming_char = 0; //Tuleva viesti Serial Portilta
char mobilenumber[]="0451352086";
char textmessage[160];
int b=0;
float latitude, longitude;

TinyGPS gps;


SoftwareSerial cell(2,3); // 2 = RX(Receive) ja 3 = TX(Transmit)
SoftwareSerial uart_gps(RXPIN, TXPIN);

void startSMS();
void endSMS();
void SendGPSLocation();
void getgps(TinyGPS &gps);

void setup()
{
   Serial.begin(4800);
   cell.begin(4800);
   Serial.println("Starting SM5100B Communication...");
   Serial.println("Waiting for GPS signal...");
 
}
void loop()
{
 
 // getgps(gps);//-----------------------------------------------GPS-----------------------------------
/*while(uart_gps.available())     // While there is data on the RX pin...
    {
        int c = uart_gps.read();    // load the data into a variable...
        if(gps.encode(c))      // if there is a new valid sentence...
        {
          getgps(gps);         // then grab the data.
        }
    }
 //--------------------------------GPS LOPPUU---------------------------------------------
*/ 
 
  //--------------------------------------------GSM----------------------------------
  if(cell.available() >0)
    {
     
       incoming_char=cell.read();    //Get the character from the cellular serial port.
       Serial.print(incoming_char);  //Print the incoming character to the terminal.
    }
  if(Serial.available() >0)
    {
      incoming_char=Serial.read();  //Get the character coming from the terminal
      cell.print(incoming_char);    //Send the character to the cellular module.
    }
 //----------------------------------GSM LOPPUU_---------------------------------------
     
}
void startSMS()
{
digitalWrite(13, HIGH);
cell.println("AT+CMGF=1"); // set SMS mode to text
cell.print("AT+CMGS=");
cell.print((char)13); // ASCII equivalent of "
cell.print(mobilenumber);
cell.println((char)13);  // ASCII equivalent of "
delay(500); // give the module some thinking time
}

void endSMS()
{
cell.println((char)26);  // ASCII equivalent of Ctrl-Z
delay(15000); // the SMS module needs time to return to OK status
digitalWrite(13, LOW);
}

 void SendGPSLocation()
{
  startSMS();
  getgps(gps);
  endSMS();
}
void getgps(TinyGPS &gps)
{
 
 
  gps.f_get_position(&latitude, &longitude);
 
 cell.print("N  ");
 cell.print(latitude,5);
 cell.print(" W ");
 cell.println(longitude,5);
 
 //Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude()); cell.print(gps.f_altitude());
 //Serial.print("Course (degrees): "); Serial.println(gps.f_course()); cell.print(gps.f_course());
 
 
 unsigned long chars;
 unsigned short sentences, failed_checksum;
 gps.stats(&chars, &sentences, &failed_checksum);
 
 
}

I have done already how to send the coordinates by SMS. All i need now is to read my SMS and after that perform "void SendGPSLocation()"...

Pls i need and exact example or a straight answer which i can copy because i am so new to AT Commands....



Logged

Pages: [1]   Go Up
Jump to: