Sending Text Message w/GPS Data

Hi Everyone!

This should be a simple fix, but I can’t seem to figure out what the error in my code is.

This is what I am using:

So the problem is simply my code. It should be working but the console is giving me this error:

GPRS_Project.ino: In function 'void loop()':
GPRS_Project:58: error: 'gpsdump' was not declared in this scope
GPRS_Project:79: error: a function-definition is not allowed here before '{' token

I have done a ton of troubleshooting and at this point, I don’t know what’s wrong.
The idea is that when I send “t” to the arduino over serial, it will send the current lat and lon to my cell phone. That’s basically the idea anyway. The LCD display is for troubleshooting and a user interface. I will eventually set it up so that when one of the buttons on the LCD are pressed, the device will send the lat and lon to my cell phone too. That’s why I have it.

Anyway… Here is the code:

/*Note: this code is a demo for how to using gprs shield to send sms message, dial a voice call and 
  send a http request to the website, upload data to pachube.com by TCP connection,
 
  The microcontrollers Digital Pin 7 and hence allow unhindered
  communication with GPRS Shield using SoftSerial Library. 
  IDE: Arduino 1.0 or later
  Replace the following items in the code:
  1.Phone number, don't forget add the country code
  2.Replace the Access Point Name
  3. Replace the Pachube API Key with your personal ones assigned
  to your account at cosm.com
  */
 
 
#include <SoftwareSerial.h>
#include <String.h>
#include "TinyGPS.h"                 // Special version for 1.0
#include <LiquidCrystal.h>
 
SoftwareSerial mySerial(7, 8);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

TinyGPS gps;
SoftwareSerial nss(2, 255);            // Yellow wire to pin 2. (Based on using 
                                       // Parallax 28500-RT PMB-648 GPS SiRF Internal Antenna)

// Define some values used by the LCD panel
int lcd_key     = 0;
int adc_key_in  = 0;
// Define LCD Keypad buttons
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

void setup()
{
  mySerial.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);                 // the GPRS baud rate
  nss.begin(4800);                     // the GRS baud rate
  
  // Initialize LCD Screen
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0,0);
  // End initialize LCD Screen
}

void loop() {
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 2000) { // Update every 2 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
      SendTextMessage(gps);
  //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()
 
  if (Serial.available())
    switch(Serial.read())
   {
     case 't':
       SendTextMessage();
       delay(2000);
       lcd.clear();
       break;
   } 
  if (mySerial.available())
    Serial.write(mySerial.read());
}
 
///SendTextMessage()
///this function is to send a sms message
void SendTextMessage(TinyGPS &gps) 
{
  float flat, flon;
  unsigned long age;
  gps.f_get_position(&flat, &flon, &age);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Sending Text Msg");
  Serial.print("Sending Text Msg");
  mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.println("AT + CMGS = \"+14148523700\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  //the content of the message
  mySerial.println(flat, 4); //Latitude
  mySerial.println(", "); // Space between lat and lon
  mySerial.println(flon, 4); //Longitude
  //end of message 
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
  }
}
// Feed data as it becomes available 
bool feedgps() {
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;
      
  }
  return false;
}

Thanks in advance!
Max Kulik

Your code needs to be formatted correctly. Use Tools + Auto Format, and you'll see immediately what the problem is.

You are trying to define SendTextMessage() inside the loop() function.

Passing a global variable to the function is unnecessary.

PaulS: Your code needs to be formatted correctly. Use Tools + Auto Format, and you'll see immediately what the problem is.

You are trying to define SendTextMessage() inside the loop() function.

Passing a global variable to the function is unnecessary.

I ran the auto-format but a message on the bar below said "No changes necessary for Auto Format."

Also, how do you suggest I go about this then if I don't need to define SendTextMessage() Function. I have tried changing it or removing it but I just gives me different errors.

Also, how do you suggest I go about this then if I don’t need to define SendTextMessage() Function.

You do need to define the function. AFTER loop(), not IN loop().

You don’t need to pass it a value, since the value is in a global variable.

PaulS:

Also, how do you suggest I go about this then if I don’t need to define SendTextMessage() Function.

You do need to define the function. AFTER loop(), not IN loop().

You don’t need to pass it a value, since the value is in a global variable.

So this is the part that does not need to be defined in void loop()?:

  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 2000) { // Update every 2 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
      SendTextMessage(gps);

So this is the part that does not need to be defined in void loop()?:

No. That does need to be there.

I ran the auto-format but a message on the bar below said “No changes necessary for Auto Format.”

In which version of the IDE? I just pasted your code in 1.0.5 (again), and Tools + Auto Format makes significant changes. It now looks like:

/*Note: this code is a demo for how to using gprs shield to send sms message, dial a voice call and 
 send a http request to the website, upload data to pachube.com by TCP connection,
 
 The microcontrollers Digital Pin 7 and hence allow unhindered
 communication with GPRS Shield using SoftSerial Library. 
 IDE: Arduino 1.0 or later
 Replace the following items in the code:
 1.Phone number, don't forget add the country code
 2.Replace the Access Point Name
 3. Replace the Pachube API Key with your personal ones assigned
 to your account at cosm.com
 */


#include <SoftwareSerial.h>
#include <String.h>
#include "TinyGPS.h"                 // Special version for 1.0
#include <LiquidCrystal.h>

SoftwareSerial mySerial(7, 8);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

TinyGPS gps;
SoftwareSerial nss(2, 255);            // Yellow wire to pin 2. (Based on using 
// Parallax 28500-RT PMB-648 GPS SiRF Internal Antenna)

// Define some values used by the LCD panel
int lcd_key     = 0;
int adc_key_in  = 0;
// Define LCD Keypad buttons
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

void setup()
{
  mySerial.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);                 // the GPRS baud rate
  nss.begin(4800);                     // the GRS baud rate

  // Initialize LCD Screen
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0,0);
  // End initialize LCD Screen
}

void loop() {
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 2000) { // Update every 2 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
    SendTextMessage(gps);
    //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()

    if (Serial.available())
      switch(Serial.read())
      {
      case 't':
        SendTextMessage();
        delay(2000);
        lcd.clear();
        break;
      } 
    if (mySerial.available())
      Serial.write(mySerial.read());
  }

  ///SendTextMessage()
  ///this function is to send a sms message
  void SendTextMessage(TinyGPS &gps) 
  {
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Sending Text Msg");
    Serial.print("Sending Text Msg");
    mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
    delay(100);
    mySerial.println("AT + CMGS = \"+14148523700\"");//send sms message, be careful need to add a country code before the cellphone number
    delay(100);
    //the content of the message
    mySerial.println(flat, 4); //Latitude
    mySerial.println(", "); // Space between lat and lon
    mySerial.println(flon, 4); //Longitude
    //end of message 
    delay(100);
    mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
    delay(100);
    mySerial.println();
  }
}
// Feed data as it becomes available 
bool feedgps() {
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;

  }
  return false;
}

SendTextMessage() is defined in loop(). Count the closing braces for SendTextMessage() if you don’t believe me.

PaulS:

So this is the part that does not need to be defined in void loop()?:

No. That does need to be there.

I ran the auto-format but a message on the bar below said “No changes necessary for Auto Format.”

In which version of the IDE? I just pasted your code in 1.0.5 (again), and Tools + Auto Format makes significant changes. It now looks like:

/*Note: this code is a demo for how to using gprs shield to send sms message, dial a voice call and 

send a http request to the website, upload data to pachube.com by TCP connection,

The microcontrollers Digital Pin 7 and hence allow unhindered
communication with GPRS Shield using SoftSerial Library.
IDE: Arduino 1.0 or later
Replace the following items in the code:
1.Phone number, don’t forget add the country code
2.Replace the Access Point Name
3. Replace the Pachube API Key with your personal ones assigned
to your account at cosm.com
*/

#include <SoftwareSerial.h>
#include <String.h>
#include “TinyGPS.h”                 // Special version for 1.0
#include <LiquidCrystal.h>

SoftwareSerial mySerial(7, 8);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

TinyGPS gps;
SoftwareSerial nss(2, 255);            // Yellow wire to pin 2. (Based on using
// Parallax 28500-RT PMB-648 GPS SiRF Internal Antenna)

// Define some values used by the LCD panel
int lcd_key     = 0;
int adc_key_in  = 0;
// Define LCD Keypad buttons
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

void setup()
{
  mySerial.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);                 // the GPRS baud rate
  nss.begin(4800);                     // the GRS baud rate

// Initialize LCD Screen
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0,0);
  // End initialize LCD Screen
}

void loop() {
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 2000) { // Update every 2 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
    SendTextMessage(gps);
    //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()

if (Serial.available())
      switch(Serial.read())
      {
      case ‘t’:
        SendTextMessage();
        delay(2000);
        lcd.clear();
        break;
      }
    if (mySerial.available())
      Serial.write(mySerial.read());
  }

///SendTextMessage()
  ///this function is to send a sms message
  void SendTextMessage(TinyGPS &gps)
  {
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print(“Sending Text Msg”);
    Serial.print(“Sending Text Msg”);
    mySerial.print(“AT+CMGF=1\r”);    //Because we want to send the SMS in text mode
    delay(100);
    mySerial.println(“AT + CMGS = “+14148523700"”);//send sms message, be careful need to add a country code before the cellphone number
    delay(100);
    //the content of the message
    mySerial.println(flat, 4); //Latitude
    mySerial.println(”, "); // Space between lat and lon
    mySerial.println(flon, 4); //Longitude
    //end of message
    delay(100);
    mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
    delay(100);
    mySerial.println();
  }
}
// Feed data as it becomes available
bool feedgps() {
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;

}
  return false;
}



SendTextMessage() is defined in loop(). Count the closing braces for SendTextMessage() if you don't believe me.

I just updated the IDE. I was running 1.0.
It’s not that I don’t believe you. I just don’t understand where I need to define it then. Or how to do so.

I just don’t understand where I need to define it then. Or how to do so.

Your code needs to look more like:

/*Note: this code is a demo for how to using gprs shield to send sms message, dial a voice call and 
 send a http request to the website, upload data to pachube.com by TCP connection,
 
 The microcontrollers Digital Pin 7 and hence allow unhindered
 communication with GPRS Shield using SoftSerial Library. 
 IDE: Arduino 1.0 or later
 Replace the following items in the code:
 1.Phone number, don't forget add the country code
 2.Replace the Access Point Name
 3. Replace the Pachube API Key with your personal ones assigned
 to your account at cosm.com
 */


#include <SoftwareSerial.h>
#include <String.h>
#include "TinyGPS.h"                 // Special version for 1.0
#include <LiquidCrystal.h>

SoftwareSerial mySerial(7, 8);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

TinyGPS gps;
SoftwareSerial nss(2, 255);            // Yellow wire to pin 2. (Based on using 
// Parallax 28500-RT PMB-648 GPS SiRF Internal Antenna)

// Define some values used by the LCD panel
int lcd_key     = 0;
int adc_key_in  = 0;
// Define LCD Keypad buttons
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

void setup()
{
  mySerial.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);                 // the GPRS baud rate
  nss.begin(4800);                     // the GRS baud rate

  // Initialize LCD Screen
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0,0);
  // End initialize LCD Screen
}

void loop() {
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 2000) { // Update every 2 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
    SendTextMessage(gps);
    //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()

    if (Serial.available())
      switch(Serial.read())
      {
      case 't':
        SendTextMessage();
        delay(2000);
        lcd.clear();
        break;
      } 
    if (mySerial.available())
      Serial.write(mySerial.read());
  }
}

///SendTextMessage()
///this function is to send a sms message
void SendTextMessage(TinyGPS &gps) 
{
  float flat, flon;
  unsigned long age;
  gps.f_get_position(&flat, &flon, &age);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Sending Text Msg");
  Serial.print("Sending Text Msg");
  mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.println("AT + CMGS = \"+14148523700\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  //the content of the message
  mySerial.println(flat, 4); //Latitude
  mySerial.println(", "); // Space between lat and lon
  mySerial.println(flon, 4); //Longitude
  //end of message 
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
}

// Feed data as it becomes available 
bool feedgps() {
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;

  }
  return false;
}

PaulS: Your code needs to look more like:

Ok, so I have that but now it gives me this:

GPRS_Project.ino: In function 'void loop()':
GPRS_Project:23: error: too few arguments to function 'void SendTextMessage(TinyGPS&)'
GPRS_Project:66: error: at this point in file

I suggest you get a basic textbook on C/C++ programming, because you clearly have no idea what you are doing.

michinyon:
I suggest you get a basic textbook on C/C++ programming, because you clearly have no idea what you are doing.

I’m pretty sure I have an idea as to what I am doing. This is the first time I have ever tried something like this and I am just looking for some help on understanding why I have these errors and how to fix them. However your constructive criticism is much obliged.

Ok, so I have that but now it gives me this:

The IDE does not generate function prototypes correctly for functions that take reference arguments. I keep telling you that you do not need to pass gps (a global variable) to the function. You keep ignoring me. This will be my last response until you stop ignoring me.

PaulS:

Ok, so I have that but now it gives me this:

The IDE does not generate function prototypes correctly for functions that take reference arguments. I keep telling you that you do not need to pass gps (a global variable) to the function. You keep ignoring me. This will be my last response until you stop ignoring me.

Ok, bare with me here.

So does this mean that Because I have

TinyGPS gps;

defined I don't need to place it in the function like I currently have it. So it should look like this?

void SendTextMessage()

rather then this:

void SendTextMessage(TinyGPS &gps)

Ok, bare with me here.

I’ll keep my clothes on. Feel free to take yours off, though. Just don’t post any after pictures.

So does this mean that Because I have … defined I don’t need to place it in the function like I currently have it.

Yes, it does.

So it should look like this? … rather then this:

Yes.

PaulS:

So it should look like this? ... rather then this:

Yes.

Alright, I have done so, but It's still the exact same error, howerver this time It looks like this:

GPRS_Project.ino: In function 'void loop()':
GPRS_Project:23: error: too few arguments to function 'void SendTextMessage()'
GPRS_Project:66: error: at this point in file

Is there anything else I should know, or is there more Variables that I need to remove?

So, you made some changes to your code. It doesn't compile. I, for one, refuse to play guessing games. Post your revised code.

PaulS:
So, you made some changes to your code. It doesn’t compile. I, for one, refuse to play guessing games. Post your revised code.

Here you are:

/*Note: this code is a demo for how to using gprs shield to send sms message, dial a voice call and 
 send a http request to the website, upload data to pachube.com by TCP connection,
 
 The microcontrollers Digital Pin 7 and hence allow unhindered
 communication with GPRS Shield using SoftSerial Library. 
 IDE: Arduino 1.0 or later
 Replace the following items in the code:
 1.Phone number, don't forget add the country code
 2.Replace the Access Point Name
 3. Replace the Pachube API Key with your personal ones assigned
 to your account at cosm.com
 */


#include <SoftwareSerial.h>
#include <String.h>
#include "TinyGPS.h"                 // Special version for 1.0
#include <LiquidCrystal.h>

SoftwareSerial mySerial(7, 8);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

TinyGPS gps;
SoftwareSerial nss(2, 255);            // Yellow wire to pin 2. (Based on using 
// Parallax 28500-RT PMB-648 GPS SiRF Internal Antenna)

// Define some values used by the LCD panel
int lcd_key     = 0;
int adc_key_in  = 0;
// Define LCD Keypad buttons
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

void setup()
{
  mySerial.begin(19200);               // the GPRS baud rate   
  Serial.begin(19200);                 // the GPRS baud rate
  nss.begin(4800);                     // the GRS baud rate

  // Initialize LCD Screen
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0,0);
  // End initialize LCD Screen
}

void loop() {
  bool newdata = false;
  unsigned long start = millis();
  while (millis() - start < 2000) { // Update every 2 seconds
    if (feedgps())
      newdata = true;
  }
  if (newdata) {
    SendTextMessage(gps);
    //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()

    if (Serial.available())
      switch(Serial.read())
      {
      case 't':
        SendTextMessage();
        delay(2000);
        lcd.clear();
        break;
      } 
    if (mySerial.available())
      Serial.write(mySerial.read());
  }
}

///SendTextMessage()
///this function is to send a sms message
void SendTextMessage() 
{
  float flat, flon;
  unsigned long age;
  gps.f_get_position(&flat, &flon, &age);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Sending Text Msg");
  Serial.print("Sending Text Msg");
  mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
  delay(100);
  mySerial.println("AT + CMGS = \"+14148523700\"");//send sms message, be careful need to add a country code before the cellphone number
  delay(100);
  //the content of the message
  mySerial.println(flat, 4); //Latitude
  mySerial.println(", "); // Space between lat and lon
  mySerial.println(flon, 4); //Longitude
  //end of message 
  delay(100);
  mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
  delay(100);
  mySerial.println();
}

// Feed data as it becomes available 
bool feedgps() {
  while (nss.available()) {
    if (gps.encode(nss.read()))
      return true;

  }
  return false;
}

Do these really go together?

    SendTextMessage(gps);
void SendTextMessage()

PaulS: Do these really go together?

    SendTextMessage(gps);
void SendTextMessage()

I didn't catch that. I just changed

SendTextMessage(gps)

to

SendTextMessage()

aaaand it works.