Pages: [1]   Go Down
Author Topic: SoftwareSerial freezing after working for 2 days ...  (Read 948 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone ,
I made a gps tracker system for my car..
It always works but sometimes.. it cannot read the serial data, I cannot specify the problem because it appears after 2-3 days.. It appears then after 2-3 hours. it does what it should have do.. I couldn't understand....

Sometimes....
I call it ... nothing is done (normally it should turns the recieved call to busy then it sends the coordinates in a SMS message)
after 2-3 hours..
it sends the SMS ...
??????? :O ??????

Do I have a mistake in code???
Thanks ...


Code:
#include <TimerOne.h>
#include <TinyGPS.h>
#include <SoftwareSerial.h>

TinyGPS gps;

SoftwareSerial gsmSerial(2, 3);
SoftwareSerial ss(5,6);

boolean debug = true;

String inData = String();
boolean inputAvailable = false;
boolean admin_called = false;
String RemoveCommand = String("AT+CMGD=");

String ADMIN_PHONE_NUMBER_1 = String("05558230165");
String ADMIN_PHONE_NUMBER_2 = String("05323342412");
String ADMIN_PHONE_NUMBER_3 = String("05396933288");
String ADMIN_PHONE_NUMBER_4 = String("05373624078");

String recievedNumber = String();

int callback_counter=0;
int removesms_counter=0;
int indexofMsgStr = 0;
float flat, flon, fkmph;
unsigned long age;

float flat_store = 0.0;
float flon_store = 0.0;

void setup()
{
  Serial.begin(9600);
  ss.begin(9600);
  gsmSerial.begin(9600);
  
  Timer1.initialize(8388480); //about 8.3 seconds
  Timer1.attachInterrupt(callback);
  
  delay(3000);
  inData = "";
  
  //Serial.println("basla...");
  
}

void loop() // run over and over
{
  gsmSerial.listen();
  while(gsmSerial.available())
  {
    inputAvailable = true;
    int tmp = gsmSerial.read();
    inData += (char) tmp;
    delay(7);
  }
  if(inputAvailable){
    inputAvailable=false;
    processData();
    inData="";
  }
  
  if(callback_counter >= 80)
  {
    //Serial.print("callback ok!");
    callback_counter = 0;
    TAKEGPSDATA();
  }

  //REMOVE ALL SMS MESSAGES
  if(removesms_counter >= 10000)
  {
    removesms_counter = 0;
    removeSms();
  }
  
  
}
void printGPSDATA(){
    gps.f_get_position(&flat, &flon, &age);

    if( flat > 0.0 )
    flat_store = flat;

    if( flon > 0.0 )
    flon_store = flon;

    fkmph = gps.f_speed_kmph(); // speed in km/hr

    //Serial.print("HIZ=");
    //Serial.println(fkmph);
    //Serial.print("LAT=");
    //Serial.println(flat,6);
    //Serial.print("LON=");
    //Serial.println(flon,6);
}

void TAKEGPSDATA(){
    //Serial.println("---->TAKEGPSDATA");
    ss.listen();
    delay(100);
    for (unsigned long start = millis(); millis() - start < 1000;)
    {
      while (ss.available())
      {
        char c = ss.read();
        if (gps.encode(c)) // Did a new valid sentence come in?
          {
            printGPSDATA();
          }
      }
    }
    gsmSerial.listen();
    //Serial.println("<----TAKEGPSDATA");
}

void processData(){
  //Serial.println(inData);
  
  if(IsRinging())
  { // telefon caliyor
    //Serial.println("telefon caliyor");
    AramayiMesguleCevir();
    indexofMsgStr = inData.indexOf("05");
    recievedNumber = inData.substring(indexofMsgStr , indexofMsgStr+11);
    //Serial.print("recieved number=");
    //Serial.println(recievedNumber);
    
    if(IsAdminNumber())
    {
      //Serial.println("admin ok!");
      TAKEGPSDATA();
      KoordinatBilgisiGonder();
    }
  }
}

void AramayiMesguleCevir(){
  gsmSerial.println("AT H");
  delay(50);
}



/***********DURUM BILGISI GONDER*********/
/*****************START*******************/
void KoordinatBilgisiGonder(){
  String atSendNumber = String(23);
  /////////////SEND SMS////////////
  gsmSerial.println("AT+CMGF=1");
  
  atSendNumber = "AT+CMGS=\"+9";
  atSendNumber += recievedNumber;
  atSendNumber += "\"";

  gsmSerial.println(atSendNumber);
  
  gsmSerial.print("ENLEM =");
  gsmSerial.println(flat_store,6);
  gsmSerial.print("BOYLAM =");
  gsmSerial.println(flon_store,6);
  
  gsmSerial.print("HIZ =");
  gsmSerial.print(fkmph);
  gsmSerial.println(" km/saat");
  
  gsmSerial.println("LINK =");
  gsmSerial.print("http://maps.google.com/?ie=UTF8&hq=&ll=");
  gsmSerial.print(flat_store,6);
  gsmSerial.print(",");
  gsmSerial.print(flon_store,6);
  gsmSerial.print("&z=20");
  gsmSerial.write(26);
}

void removeSms(){
//Serial.println("---->removeSms");
gsmSerial.println("AT+CMGD=1,4");
delay(100);
gsmSerial.write(26);
//Serial.println("<----removeSms");
}

int IsRinging()
{
  if (inData.indexOf("VOICE") >= 0 )
  {
    return 1;
  }
  else
  {
    return 0;
  }
}
int IsAdminNumber()
{
    
  if(ADMIN_PHONE_NUMBER_1 == recievedNumber)
  {
    return 1;
  }
  else if(ADMIN_PHONE_NUMBER_2 == recievedNumber)
  {
    return 1;
  }
  else if(ADMIN_PHONE_NUMBER_3 == recievedNumber)
  {
    return 1;
  }
  else if(ADMIN_PHONE_NUMBER_4 == recievedNumber)
  {
    return 1;
  }
  return 0;
  
}

void callback()
{
  callback_counter++;
  removesms_counter++;
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46224
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
String inData = String();
This is invoking the String constructor to create a String instance. Then, it invokes the copy constructor to make a copy of that object, in inData. Then, it invokes the destructor to get rid of the original object. That's a lot of useless work.
Code:
String inData = "";
One call to the constructor.

Code:
String RemoveCommand = String("AT+CMGD=");

String ADMIN_PHONE_NUMBER_1 = String("05558230165");
String ADMIN_PHONE_NUMBER_2 = String("05323342412");
String ADMIN_PHONE_NUMBER_3 = String("05396933288");
String ADMIN_PHONE_NUMBER_4 = String("05373624078");

String recievedNumber = String();
Same issues here.

Code:
    int tmp = gsmSerial.read();
    inData += (char) tmp;
Assigning the result of a read() to an int, and then casting that int to a char is silly. Just assign the result to a char. Or, simply append it directly to the String instance.

Code:
    delay(7);
Wrong!!!

There is some end of packet marker on the data you get from the phone. Read the serial data, appending it to the String, until that marker arrives. Then, process the packet. No delay() is needed, and certainly none is desired.

Code:
  String atSendNumber = String(23);
This creates a String with the value "23", and copies that string to atSendNumber. How is that a smart thing to do?

Code:
int callback_counter=0;
int removesms_counter=0;
These are referenced by the ISR and by other code. The MUST be declared volatile.

Code:
Sometimes....
I call it ... nothing is done (normally it should turns the recieved call to busy then it sends the coordinates in a SMS message)
Simple solution, and it has nothing to do with SoftwareSerial. Ditch the String class. You are running out of memory.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi PaulS, Thanks for your reply.. I reviewed the code , I'll try it when I meet with my car tomorrow..
but I have already tried to read serial data without delay then it cannot catch all data. I guess that the reason is chacing data into tmp variable.. now I have the code like this

Code:
#include <TimerOne.h>
#include <TinyGPS.h>
#include <SoftwareSerial.h>

TinyGPS gps;

SoftwareSerial gsmSerial(2, 3);
SoftwareSerial ss(5,6);

String inData = "";
boolean inputAvailable = false;

String ADMIN_PHONE_NUMBER_1 = "05558230165";
String ADMIN_PHONE_NUMBER_2 = "05323342412";
String ADMIN_PHONE_NUMBER_3 = "05396933288";
String ADMIN_PHONE_NUMBER_4 = "05373624078";

String recievedNumber = "";

int callback_counter=0;
int removesms_counter=0;
int indexofMsgStr = 0;
float flat, flon, fkmph;
unsigned long age;

float flat_store = 0.0;
float flon_store = 0.0;

void setup()
{
  Serial.begin(9600);
  ss.begin(9600);
  gsmSerial.begin(9600);
 
  Timer1.initialize(8388480); //about 8.3 seconds
  Timer1.attachInterrupt(callback);
 
  delay(2000);
 
 
}

void loop() // run over and over
{
  gsmSerial.listen();
  while(gsmSerial.available())
  {
    inputAvailable = true;
    inData += (char) gsmSerial.read();
  }
  if(inputAvailable){
    inputAvailable=false;
    processData();
    inData="";
  }
}
void printGPSDATA(){
    gps.f_get_position(&flat, &flon, &age);

    if( flat > 0.0 )
    flat_store = flat;

    if( flon > 0.0 )
    flon_store = flon;

    fkmph = gps.f_speed_kmph(); // speed in km/hr

}

void TAKEGPSDATA(){
    Serial.println("---->TAKEGPSDATA");
    ss.listen();
    delay(100);
    for (unsigned long start = millis(); millis() - start < 1000;)
    {
      while (ss.available())
      {
        char c = ss.read();
        if (gps.encode(c)) // Did a new valid sentence come in?
          {
            printGPSDATA();
          }
      }
    }
    gsmSerial.listen();
    Serial.println("<----TAKEGPSDATA");
}

void processData(){
  Serial.println(inData);
 
  if(IsRinging())
  { // telefon caliyor
    Serial.println("telefon caliyor");
    AramayiMesguleCevir();
    indexofMsgStr = inData.indexOf("05");
    recievedNumber = inData.substring(indexofMsgStr , indexofMsgStr+11);
    Serial.print("recieved number=");
    Serial.println(recievedNumber);
   
    if(IsAdminNumber())
    {
      Serial.println("admin ok!");
      TAKEGPSDATA();
      KoordinatBilgisiGonder();
    }
  }
}

void AramayiMesguleCevir(){
  gsmSerial.println("AT H");
  delay(50);
}



/***********DURUM BILGISI GONDER*********/
/*****************START*******************/
void KoordinatBilgisiGonder(){
  String atSendNumber = "AT+CMGS=\"+9";
  /////////////SEND SMS////////////
  gsmSerial.println("AT+CMGF=1");
 
  atSendNumber += recievedNumber;
  atSendNumber += "\"";

  gsmSerial.println(atSendNumber);
 
  gsmSerial.print("ENLEM =");
  gsmSerial.println(flat_store,6);
  gsmSerial.print("BOYLAM =");
  gsmSerial.println(flon_store,6);
 
  gsmSerial.print("HIZ =");
  gsmSerial.print(fkmph);
  gsmSerial.println(" km/saat");
 
  gsmSerial.println("LINK =");
  gsmSerial.print("http://maps.google.com/?ie=UTF8&hq=&ll=");
  gsmSerial.print(flat_store,6);
  gsmSerial.print(",");
  gsmSerial.print(flon_store,6);
  gsmSerial.print("&z=20");
  gsmSerial.write(26);
}

void removeSms(){
  Serial.println("---->removeSms");
  gsmSerial.println("AT+CMGD=1,4");
  delay(100);
  gsmSerial.write(26);
  Serial.println("<----removeSms");
}

int IsRinging()
{
  if (inData.indexOf("VOICE") >= 0 )
  {
    return 1;
  }
  else
  {
    return 0;
  }
}
int IsAdminNumber()
{
   
  if(ADMIN_PHONE_NUMBER_1 == recievedNumber)
  {
    return 1;
  }
  else if(ADMIN_PHONE_NUMBER_2 == recievedNumber)
  {
    return 1;
  }
  else if(ADMIN_PHONE_NUMBER_3 == recievedNumber)
  {
    return 1;
  }
  else if(ADMIN_PHONE_NUMBER_4 == recievedNumber)
  {
    return 1;
  }
  return 0;
 
}

void callback()
{
  callback_counter++;
  removesms_counter++;

  if(callback_counter >= 80)
  {
    Serial.print("callback ok!");
    callback_counter = 0;
    TAKEGPSDATA();
  }

  //REMOVE ALL SMS MESSAGES
  if(removesms_counter >= 10000)
  {
    removesms_counter = 0;
    removeSms();
  }
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46224
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but I have already tried to read serial data without delay then it cannot catch all data. I guess that the reason is chacing data into tmp variable
No. It has to do with the fact that receiving serial data takes time, like my typing. If you only read what I write when I enter a carriage return or period, you don't notice how long it takes. If you try to read each character, and anticipate the end of a sentence based on a specific time for me to hunt and peck each character, you will be wrong often.

You really do need to determine what the end of packet marker is, and read data (without delay) until that character arrives.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I really understand what you mean now...
Many many thanks for your help !  smiley-wink
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PaulS , I tried the code then ... without
Code:
delay(3);
after
Code:
inData += (char) gsmSerial.read();
cannot catch all characters... Then, it shows like this

Code:
VOIC

but it should be like this
Code:
VOICE:
some at commands here , which includes the coming phone number

I really cannot understand why it cannot catch all data without delay..... smiley-cry
Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11197
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If it's still using the same logic posted earlier, you aren't waiting for a complete message to be received, you're ending the read loop and processing the received string as soon as the Arduino manages to empty the serial receive buffer. You need to have your sketch read and buffer the received message until it is complete - and that implies you also need a way to decide whether it's complete.

If you think you're already doing this, post your current code and perhaps somebody will spot why it isn't working.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I do not have any sketch, So I should make one...

Is it possible that gsm modem doesn't send any data after some time ?
I debug it with serial monitor then ... sometimes , I call it .. the device is blinking but no characters is recieving ?
smiley-cry
« Last Edit: June 14, 2012, 01:18:53 pm by boraciner » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I used max232 module btw Uc and gsm modem... Does it make it hard to communicate ? smiley-cry
and I fixed these components So, I cannot remove it smiley-cry
 
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I closed the taking gps coordinates and sending sms parts.. now just rejects the incoming call ... it seems to be ok for this mechanism.. I'm trying it now...

the code : 
Code:
#include <TimerOne.h>
#include <TinyGPS.h>
#include <SoftwareSerial.h>

TinyGPS gps;

SoftwareSerial gsmSerial(2, 3);
SoftwareSerial ss(5,6);

String inData = "";
boolean inputAvailable = false;

String ADMIN_PHONE_NUMBER_1 = "05558230165";
String ADMIN_PHONE_NUMBER_2 = "05323342412";
String ADMIN_PHONE_NUMBER_3 = "05396933288";
String ADMIN_PHONE_NUMBER_4 = "05373624078";

String recievedNumber = "";

int callback_counter=0;
int removesms_counter=0;
int indexofMsgStr = 0;
float flat, flon, fkmph;
unsigned long age;

float flat_store = 0.0;
float flon_store = 0.0;

void setup()
{
  Serial.begin(9600);
  ss.begin(9600);
  gsmSerial.begin(9600);
 
  Timer1.initialize(8388480); //about 8.3 seconds
  Timer1.attachInterrupt(callback);
 
  delay(2000);
  Serial.println("basla");
  gsmSerial.println("AT+ECHO=0"); // echo off
}

void loop() // run over and over
{
  gsmSerial.listen();
  while(gsmSerial.available())
  {
    inputAvailable = true;
    inData += (char) gsmSerial.read();
    delay(7);
  }
  if(inputAvailable)
  {
    inputAvailable=false;
    processData();
    inData="";
  }
}
void printGPSDATA(){
  gps.f_get_position(&flat, &flon, &age);
 
  if( flat > 0.0 )
  flat_store = flat;
 
  if( flon > 0.0 )
  flon_store = flon;
 
  fkmph = gps.f_speed_kmph(); // speed in km/hr

}

void TAKEGPSDATA(){
  Serial.println("---->TAKEGPSDATA");
  ss.listen();
  delay(100);
  for (unsigned long start = millis(); millis() - start < 1000;)
  {
    while (ss.available())
    {
      char c = ss.read();
      if (gps.encode(c)) // Did a new valid sentence come in?
      {
        printGPSDATA();
      }
    }
  }
  gsmSerial.listen();
  Serial.println("<----TAKEGPSDATA");
}

void processData(){
  Serial.println(inData);
 
  if(IsRinging())
  { // telefon caliyor
    Serial.println("telefon caliyor");
    AramayiMesguleCevir();
    /*indexofMsgStr = inData.indexOf("05");
    recievedNumber = inData.substring(indexofMsgStr , indexofMsgStr+11);
    Serial.print("recieved number=");
    Serial.println(recievedNumber);
   
    if(IsAdminNumber())
    {
      Serial.println("admin ok!");
      TAKEGPSDATA();
      KoordinatBilgisiGonder();
    }
    */
  }
}

void AramayiMesguleCevir(){
  gsmSerial.println("AT H");
  delay(50);
}



/***********DURUM BILGISI GONDER*********/
/*****************START*******************/
void KoordinatBilgisiGonder(){
  String atSendNumber = "AT+CMGS=\"+9";
  /////////////SEND SMS////////////
  gsmSerial.println("AT+CMGF=1");
 
  atSendNumber += recievedNumber;
  atSendNumber += "\"";
 
  gsmSerial.println(atSendNumber);
 
  gsmSerial.print("ENLEM =");
  gsmSerial.println(flat_store,6);
  gsmSerial.print("BOYLAM =");
  gsmSerial.println(flon_store,6);
 
  gsmSerial.print("HIZ =");
  gsmSerial.print(fkmph);
  gsmSerial.println(" km/saat");
 
  gsmSerial.println("LINK =");
  gsmSerial.print("http://maps.google.com/?ie=UTF8&hq=&ll=");
  gsmSerial.print(flat_store,6);
  gsmSerial.print(",");
  gsmSerial.print(flon_store,6);
  gsmSerial.print("&z=20");
  gsmSerial.write(26);
}

void removeSms(){
  Serial.println("---->removeSms");
  gsmSerial.println("AT+CMGD=1,4");
  delay(100);
  gsmSerial.write(26);
  Serial.println("<----removeSms");
}

int IsRinging()
{
  if (inData.indexOf("VOICE") >= 0 )
  {
    return 1;
  }
  else
  {
    return 0;
  }
}
int IsAdminNumber()
{

  if(ADMIN_PHONE_NUMBER_1 == recievedNumber)
  {
    return 1;
  }
  else if(ADMIN_PHONE_NUMBER_2 == recievedNumber)
  {
    return 1;
  }
  else if(ADMIN_PHONE_NUMBER_3 == recievedNumber)
  {
    return 1;
  }
  else if(ADMIN_PHONE_NUMBER_4 == recievedNumber)
  {
    return 1;
  }
  return 0;

}

void callback()
{
  callback_counter++;
  removesms_counter++;
 
  if(callback_counter >= 80)
  {
    Serial.print("callback ok!");
    callback_counter = 0;
    TAKEGPSDATA();
  }
 
  //REMOVE ALL SMS MESSAGES
  if(removesms_counter >= 10000)
  {
    removesms_counter = 0;
    removeSms();
  }
}



the log when I make calls...
Code:
basla
AT+ECHO=0

OK


+CRING: VOICE

+CLIP: "+905558230165",145

telefon caliyor
AT H

OK


+CRING: VOICE

+CLIP: "+905558230165",145

telefon caliyor
AT H

OK


+CRING: VOICE

+CLIP: "+905558230165",145

telefon caliyor
AT H

OK


+CRING: VOICE

+CLIP: "+905558230165",145

telefon caliyor
AT H

OK


+CRING: VOICE

+CLIP: "+905558230165",145

telefon caliyor
AT H

OK


+CRING: VOICE

+CLIP: "+905558230165",145

telefon caliyor
AT H

OK


+CRING: VOICE

+CLIP: "+905558230165",145

telefon caliyor
AT H

OK

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I updated the code  , according to a skecth but after 20 minutes I doesn't work... I didn't have any debug chance. but I'll try to catch the output.
my code is :

Code:
#include <TimerOne.h>
#include <TinyGPS.h>
#include <SoftwareSerial.h>

TinyGPS gps;

SoftwareSerial gsmSerial(2, 3);
SoftwareSerial ss(5,6);

String inData = "";
boolean inputAvailable = false;

String ADMIN_PHONE_NUMBER_1 = "05558230165";
String ADMIN_PHONE_NUMBER_2 = "05323342412";
String ADMIN_PHONE_NUMBER_3 = "05396933288";
String ADMIN_PHONE_NUMBER_4 = "05373624078";

String recievedNumber = "";

int callback_counter=0;
int removesms_counter=0;
int indexofMsgStr = 0;
float flat, flon, fkmph;
unsigned long age;
char okunanKarakter = '*';
float flat_store = 0.0;
float flon_store = 0.0;

void setup()
{
  Serial.begin(9600);
  ss.begin(9600);
  gsmSerial.begin(9600);
 
  Timer1.initialize(8388480); //about 8.3 seconds
  Timer1.attachInterrupt(callback);
 
  delay(2000);
  Serial.println("basla");
  gsmSerial.println("AT+ECHO=0"); // echo off
}

void loop() // run over and over
{
  gsmSerial.listen();
  while(gsmSerial.available())
  {
    inputAvailable = true;
    okunanKarakter = (char) gsmSerial.read();
    inData += okunanKarakter;
    if(okunanKarakter == ','){
      break;
    }
  }
 
  if(inputAvailable)
  {
    inputAvailable=false;
    processData();
    inData="";
  }
}
void printGPSDATA(){
  gps.f_get_position(&flat, &flon, &age);
 
  if( flat > 0.0 )
  flat_store = flat;
 
  if( flon > 0.0 )
  flon_store = flon;
 
  fkmph = gps.f_speed_kmph(); // speed in km/hr

}

void TAKEGPSDATA(){
  Serial.println("---->TAKEGPSDATA");
  ss.listen();
  delay(100);
  for (unsigned long start = millis(); millis() - start < 1000;)
  {
    while (ss.available())
    {
      char c = ss.read();
      if (gps.encode(c)) // Did a new valid sentence come in?
      {
        printGPSDATA();
      }
    }
  }
  gsmSerial.listen();
  Serial.println("<----TAKEGPSDATA");
}

void processData(){
  Serial.println(inData);
 
  if(IsRinging())
  { // telefon caliyor
    Serial.println("telefon caliyor");
    AramayiMesguleCevir();
    indexofMsgStr = inData.indexOf("05");
    recievedNumber = inData.substring(indexofMsgStr , indexofMsgStr+11);
    Serial.print("recieved number=");
    Serial.println(recievedNumber);
   
    if(IsAdminNumber())
    {
      Serial.println("admin ok!");
      TAKEGPSDATA();
      KoordinatBilgisiGonder();
    }
   
  }
}

void AramayiMesguleCevir(){
  gsmSerial.println("AT H");
  delay(50);
}



/***********DURUM BILGISI GONDER*********/
/*****************START*******************/
void KoordinatBilgisiGonder(){
  String atSendNumber = "AT+CMGS=\"+9";
  /////////////SEND SMS////////////
  gsmSerial.println("AT+CMGF=1");
  delay(1000);
  atSendNumber += recievedNumber;
  atSendNumber += "\"";
 
  gsmSerial.println(atSendNumber);
  delay(500); 
 
  gsmSerial.print("ENLEM =");
  gsmSerial.println(flat_store,6);
  gsmSerial.print("BOYLAM =");
  gsmSerial.println(flon_store,6);
 
  gsmSerial.print("HIZ =");
  gsmSerial.print(fkmph);
  gsmSerial.println(" km/saat");
 
  gsmSerial.println("LINK =");
  gsmSerial.print("http://maps.google.com/?ie=UTF8&hq=&ll=");
  gsmSerial.print(flat_store,6);
  gsmSerial.print(",");
  gsmSerial.print(flon_store,6);
  gsmSerial.print("&z=20");
  gsmSerial.write(26);
  delay(50);
}

void removeSms(){
  Serial.println("---->removeSms");
  gsmSerial.println("AT+CMGD=1,4");
  delay(100);
  gsmSerial.write(26);
  Serial.println("<----removeSms");
}

int IsRinging()
{
  if (inData.indexOf("VOICE") >= 0 )
  {
    return 1;
  }
  else
  {
    return 0;
  }
}
int IsAdminNumber()
{

  if(ADMIN_PHONE_NUMBER_1 == recievedNumber)
  {
    return 1;
  }
  else if(ADMIN_PHONE_NUMBER_2 == recievedNumber)
  {
    return 1;
  }
  else if(ADMIN_PHONE_NUMBER_3 == recievedNumber)
  {
    return 1;
  }
  else if(ADMIN_PHONE_NUMBER_4 == recievedNumber)
  {
    return 1;
  }
  return 0;

}

void callback()
{
  callback_counter++;
  removesms_counter++;
 
  if(callback_counter >= 80)
  {
    Serial.print("callback ok!");
    callback_counter = 0;
    TAKEGPSDATA();
  }
 
  //REMOVE ALL SMS MESSAGES
  if(removesms_counter >= 10000)
  {
    removesms_counter = 0;
    removeSms();
  }
}


The LOG :

Code:
basla
AT+ECHO=0

OK


+CRING: VOICE

+CLIP: "05396933288",

telefon caliyor
recieved number=05396933288
admin ok!
---->TAKEGPSDATA
<----TAKEGPSDATA
AT+CMGF=1

OK
?jiªêjU¤¥'LMNMN3288"

> Ê?ªªR?S?SÓæÿ?BOYLAM

+CMGS: 97

OK

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46224
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void loop() // run over and over
{
  gsmSerial.listen();
  while(gsmSerial.available())
  {
    inputAvailable = true;
    okunanKarakter = (char) gsmSerial.read();
    inData += okunanKarakter;
    if(okunanKarakter == ','){
      break;
    }
  }
 
  if(inputAvailable)
  {
    inputAvailable=false;
    processData();
    inData="";
  }
}
Read and accumulate whatever serial data has arrived. If any serial data has arrived, assume that a complete packet has arrived. Can you see why that is not a valid assumption?
Logged

Pages: [1]   Go Up
Jump to: