GPS + GSM tracker


hi,
so have been working on project involves gps module , gsm shield connected arduino. problem when text number inserted in gsm shield send me coordinates, there seems no response.
however if send same character via pc using serial communication, text including gps coordinates in phone.
i want find out bug in code. i'll grateful :)

[#include <softwareserial.h>
#include <string.h>
 #include <tinygps.h>
softwareserial myserial(7,8);
softwareserial sim900(7, 8);
char inchar; // hold incoming character gsm shield
tinygps gps;
softwareserial ss(4, 3);
unsigned int x;
static void smartdelay(unsigned long ms);
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(tinygps &gps);
static void print_str(const char *str, int len);
void setup()
{
 
  myserial.begin(19200);               // gprs baud rate   
  serial.begin(19200);    // gprs baud rate
  ss.begin(4800);
  delay(500);
  sim900.print("at+cmgf=1\r");  // set sms mode text
  delay(100);
  sim900.print("at+cnmi=2,2,0,0,0\r");
  // blurt out contents of new sms upon receipt gsm shield's serial out
  delay(100);
}
 
void loop()
{
   float flat, flon;
  unsigned long age, date, time, chars = 0;
  unsigned short sentences = 0, failed = 0;
  static const double london_lat = 51.508131, london_lon = -0.128002;
 
 
  gps.f_get_position(&flat, &flon, &age);
  print_float(flat, tinygps::gps_invalid_f_angle, 10, 6);
  print_float(flon, tinygps::gps_invalid_f_angle, 11, 6);
 
  gps.stats(&chars, &sentences, &failed);
   //if character comes in cellular module...
  if(sim900.available() >0)
  {
      inchar=sim900.read();
      if (inchar=='a')
      {
        sendtextmessage(flat, tinygps::gps_invalid_f_angle, 10, 6,flon, tinygps::gps_invalid_f_angle, 11, 6);
        x=1;
                   
  sim900.println("at+cmgd=1,4"); // delete sms
 
        }
       
        if (inchar=='b')
          {
            delay(10);
            x=2;
                       
  sim900.println("at+cmgd=1,4"); // delete sms
 
          }
          if (inchar=='c')
          {
              delay(10);
              x=3;
                         
  sim900.println("at+cmgd=1,4"); // delete sms
 
            }
            }

 /* serial.println();
     if(x==1)
     {
       sendtextmessage(flat, tinygps::gps_invalid_f_angle, 10, 6,flon, tinygps::gps_invalid_f_angle, 11, 6);
      }
  if (x==2)
    {
      for(int y=0;y<5;y++)
      {
        sendtextmessage(flat, tinygps::gps_invalid_f_angle, 10, 6,flon, tinygps::gps_invalid_f_angle, 11, 6);
        delay(5000);
}
    }*/
  smartdelay(1000);
}
static void smartdelay(unsigned long ms)
{
  unsigned long start = millis();
 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}
static void print_float(float val, float invalid, int len, int prec)
{
  if (val == invalid)
  {
    while (len-- > 1)
     
    serial.print(' ');
  }
  else
  {
    serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1); // . , -
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    (int i=flen; i<len; ++i)
      serial.print(' ');
  }
  smartdelay(0);
}
static void print_int(unsigned long val, unsigned long invalid, int len)
{
  char sz[32];
  if (val == invalid)
    strcpy(sz, "*******");
  else
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  (int i=strlen(sz); i<len; ++i)
    sz = ' ';
  if (len > 0)
    sz[len-1] = ' ';
  serial.print(sz);
  smartdelay(0);
}
static void print_str(const char *str, int len)
{
  int slen = strlen(str);
  (int i=0; i<len; ++i)
    serial.print(i<slen ? str : ' ');
  smartdelay(0);
}
 
///sendtextmessage()
///this function send sms message
void sendtextmessage(float val, float invalid, int len, int prec,float val1, float invalid1, int len1, int prec1)
{
  myserial.print("at+cmgf=1\r");    //because want send sms in text mode
  delay(100);
  myserial.println("at + cmgs = \"+xxxxxxxxx\"");//send sms message, careful need add country code before cellphone number
  delay(100);
  myserial.print(val,prec);//the content of message
  myserial.print(" ");
  delay(100);
  myserial.println(val1,prec1);
  delay(100);
  myserial.println((char)26);//the ascii code of ctrl+z 26
  delay(100);
  myserial.println();
}
 
void showserialdata()
{
  while(myserial.available()!=0)
    serial.write(myserial.read());
}
]

code: [select]
softwareserial myserial(7,8);
softwareserial sim900(7, 8);

what thinking? or, thinking?


Arduino Forum > Using Arduino > Programming Questions > GPS + GSM tracker


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code