0

Sending GPS coordinates as an SMS message
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Sending GPS coordinates as an SMS message

by Joe3502 on Sat Jan 19, 2019 7:27 pm

hello I just got my adafruit FON808 board to call a phone number when I push a button. Awesome! I would like to take this a step further and not only have it call me but also send me an SMS message with GPS coordinates along with it. Is this possible or can I only gather GPS information through the test code? Here is my code just in case you would want to look at it:
Code: Select all | TOGGLE FULL SIZE
#include "Adafruit_FONA.h"

#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);


// constants won't change:
const int buttonPin = 5;     // button for auto emergency distress
const int ledPin =  12;      // LED for distress will be called

// variables will change:
int buttonState = 0;         // start button HIGH

void setup() {
  fonaSerial->begin(4800);
  fona.begin(*fonaSerial);
  pinMode(ledPin, OUTPUT);  // initialize the LED pin as an output
  pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == LOW) {
    digitalWrite(ledPin, LOW);
    fona.hangUp();}
  else {
    digitalWrite(ledPin, HIGH);
    delay(15000);
     fona.sendSMS("5555555555", "Hi!");
     fona.callPhone("5555555555");
  }
}


Joe3502
 
Posts: 19
Joined: Mon Jan 14, 2019 5:45 pm

Re: Sending GPS coordinates as an SMS message

by franklin97355 on Sat Jan 19, 2019 7:43 pm

Once you get the GPS data in a string you would replace 'Hi' with that string.
Code: Select all | TOGGLE FULL SIZE
 fona.sendSMS("5555555555", "Hi!");

franklin97355
 
Posts: 20975
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: Sending GPS coordinates as an SMS message

by Joe3502 on Sat Jan 19, 2019 7:52 pm

okay cool. so by string you mean
Code: Select all | TOGGLE FULL SIZE
float latitude, longitude, speed_kph, heading, speed_mph, altitude;

Joe3502
 
Posts: 19
Joined: Mon Jan 14, 2019 5:45 pm

Re: Sending GPS coordinates as an SMS message

by jim_lee on Sun Jan 20, 2019 4:13 am

No.. A character string. String of text? A text version of the numbers in human readable form.

-jim lee

jim_lee
 
Posts: 530
Joined: Thu May 24, 2012 8:24 pm

Re: Sending GPS coordinates as an SMS message

by Joe3502 on Thu Jan 24, 2019 8:35 pm

okay this is what I have so far...I put the sting in with the data just above the void setup part of the code.
Code: Select all | TOGGLE FULL SIZE
#include "Adafruit_FONA.h"

#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);


// constants won't change:
const int buttonPin = 5;     // button for auto emergency distress
const int ledPin =  12;      // LED for distress will be called

// variables will change:
int buttonState = 0;         // start button HIGH

String state,timegps,latitude,longitude;

void setup() {
  fonaSerial->begin(4800);
  fona.begin(*fonaSerial);
  fona.enableGPRS(true);
  pinMode(ledPin, OUTPUT);  // initialize the LED pin as an output
  pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == LOW) {
    digitalWrite(ledPin, LOW);
    fona.hangUp();}
  else {
    digitalWrite(ledPin, HIGH);
    delay(10000);
     fona.sendSMS("55555555555", "Hello");
     delay(2500);
     fona.callPhone("5555555555");
  }
}


I have already stated in the code what I want the String to consist of. I am just not understanding how to take the GPS information from the board and get it to send an SMS message. What I am asking is how do I get the GPS information coded so that when I code the fona.sendSMS("5555555555", "I want my GPS stuff here") to work .

Joe3502
 
Posts: 19
Joined: Mon Jan 14, 2019 5:45 pm

Re: Sending GPS coordinates as an SMS message

by adafruit_support_mike on Fri Jan 25, 2019 4:15 am

The microcontroller will get the GPS data from the phone through its SoftwareSerial interface.

By the time you know you have GPS information to send, it's already a string in the microcontroller's memory. Transmitting it as an SMS message is pretty much the same as sending it to Serial.print().

adafruit_support_mike
 
Posts: 58410
Joined: Thu Feb 11, 2010 2:51 pm

Re: Sending GPS coordinates as an SMS message

by Joe3502 on Sun Jan 27, 2019 12:15 am

I tried everything and still don't know what I am doing wrong...
here is my updated code...
Code: Select all | TOGGLE FULL SIZE
#include "Adafruit_FONA.h"

#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

float latitude, longitude, speed_kph, heading, speed_mph, altitude;

// constants won't change:
const int buttonPin = 5;     // button for auto emergency distress
const int ledPin =  12;      // LED for distress will be called

// variables will change:
int buttonState = 0;         // start button HIGH

void setup() {
  fonaSerial->begin(4800);
  fona.begin(*fonaSerial);
  fona.enableGPRS(true);
  pinMode(ledPin, OUTPUT);  // initialize the LED pin as an output
  pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  float latitude, longitude, speed_kph, heading, speed_mph, altitude;
  boolean gps_success = fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == LOW) {
    digitalWrite(ledPin, LOW);
    fona.hangUp();}
  else {
    digitalWrite(ledPin, HIGH);
    fona.getGPS(&latitude, &longitude, &speed_kph, &heading, &altitude);
    delay(10000);
     fona.sendSMS("5555555555", &latitude, &longitude, &speed_kph, &heading, &altitude);
     delay(2500);
     fona.callPhone("5555555555");
  }
}


am i doing something wrong? no matter what I do it wont compile...

Joe3502
 
Posts: 19
Joined: Mon Jan 14, 2019 5:45 pm

Re: Sending GPS coordinates as an SMS message

by adafruit_support_mike on Sun Jan 27, 2019 2:56 am

The version of .getGPS() you're using above reads values from the GPS string and converts them to floating point numbers. Use this version instead:

Code: Select all | TOGGLE FULL SIZE
    char gps_string[ 140 ];
   
    fona.getGPS( 0, gps_string, 140 );
    fona.sendSMS( "5555555555", gps_string );

adafruit_support_mike
 
Posts: 58410
Joined: Thu Feb 11, 2010 2:51 pm

Re: Sending GPS coordinates as an SMS message

by Joe3502 on Sun Jan 27, 2019 3:12 am

where would I put the
Code: Select all | TOGGLE FULL SIZE
char gps_string[ 140 ];
at? would that go under the void loop or under the else statement? I am getting a 0 followed by a ton of commas (0,,,,,,,,,,,) when i put it under the void loop. Also, do i need the boolean or no?

Joe3502
 
Posts: 19
Joined: Mon Jan 14, 2019 5:45 pm

Re: Sending GPS coordinates as an SMS message

by adafruit_support_mike on Mon Jan 28, 2019 3:55 am

You can declare the string buffer as a global variable, or you can declare it in the same function where it's used.

As for the conditional, that depends on what you want the code to do. The code above uses it to check a pushbutton and hang up the connection.

It sounds like you're trying to paste together pieces of code copied from other sketches. It's usually harder to make that work than to write new code from scratch.

Almost every line of code in a program depends on other parts of the program. Things break when they're copied because the parts they rely on didn't get copied too. Reading a program and understanding it well enough to know how the lines depend on each other is at least as hard as writing new code to do the same thing.

There is a place for copying though: re-typing an existing program line by line and character by character. It forces you to read the code line by line and character by character, and then you start to see how some of the pieces are connected. That can be tremendously helpful when you're dealing with something new, and don't even know how to start. After you've hand-copied it, you can go back and re-read it to start figuring out how it works. As you learn, you can test your understanding by writing your own code and running it to see if it does what you expect.

adafruit_support_mike
 
Posts: 58410
Joined: Thu Feb 11, 2010 2:51 pm

Re: Sending GPS coordinates as an SMS message

by Joe3502 on Mon Jan 28, 2019 12:15 pm

okay we will look into this more. I was just confused as to why it was sending me commas instead of the string that I defined. Where does the float go? Does the float go under the loop or the setup? Another question...do I have to define what the gps_string is? Also the code that I presented to you was written from scratch but using the FONAtest code as a reference. I didn't mean to annoy you in any way...I am just trying to learn how to do this. This is a school project and our teacher knows some about arduino but not enough to help us with this project. The adafruit manual for the Fona 808 just shows you how to do things through the serial monitor, which I was able to make everything work via the serial monitor, but I wanted to get away from the serial monitor and use it standalone. This forum is the only thing I can rely on as far as this project goes.


Update...we got the thing to send us the string, but it doesn't include latitude and longitude. It sends us the date and time only. It sends it to us in this format
1,0,20190128213123.000,,,,0.00,0.0,0,,,,,,0,0,,,,,

Is there any way to get it to send coordinates with it? Here is the code that we have now...
Code: Select all | TOGGLE FULL SIZE
#include "Adafruit_FONA.h"

#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);


// constants won't change:
const int buttonPin = 5;     // button for auto emergency distress
const int ledPin =  12;      // LED for distress will be called

// variables will change:
int buttonState = 0;         // start button HIGH
char gps_string[ 140 ];

void setup() {
  fonaSerial->begin(4800);
  fona.begin(*fonaSerial);
  fona.enableGPS(true);
  pinMode(ledPin, OUTPUT);  // initialize the LED pin as an output
  pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
}

void loop() {
  buttonState = digitalRead(buttonPin);
  fona.getGPS( 0, gps_string, 140 );
 
if (buttonState == LOW) {
    digitalWrite(ledPin, LOW);
    fona.hangUp();}
else {
    digitalWrite(ledPin, HIGH);
      delay(5000);
    fona.sendSMS("7247147099", gps_string );
     delay(2500);
    fona.callPhone("7247147099");
  }
}
Last edited by Joe3502 on Mon Jan 28, 2019 5:45 pm, edited 4 times in total.

Joe3502
 
Posts: 19
Joined: Mon Jan 14, 2019 5:45 pm

Re: Sending GPS coordinates as an SMS message

by DuckusPuppicus on Mon Jan 28, 2019 12:47 pm

sorry for my previous post
Last edited by DuckusPuppicus on Mon Jan 28, 2019 5:49 pm, edited 1 time in total.

DuckusPuppicus
 
Posts: 1
Joined: Mon Jan 28, 2019 12:46 pm

Re: Sending GPS coordinates as an SMS message

by jim_lee on Mon Jan 28, 2019 3:37 pm

He IS telling you what to do. And seems to me to be doing a pretty good job of it. In no way is he being condescending. You just don't yet have the background to understand what he's trying to tell you.

And no, I don't work for Adafruit. But its really hard to watch someone come in here and blast the one person that is trying to help them.

-jim lee

jim_lee
 
Posts: 530
Joined: Thu May 24, 2012 8:24 pm

Re: Sending GPS coordinates as an SMS message

by adafruit_support_mike on Tue Jan 29, 2019 3:13 am

There's a difference between "I'm having trouble solving this problem" and "someone solve this problem for me." We're willing to help with the first one, but we don't do the second one.

It's fairly easy to tell the two apart with a 'show your work' policy.

So far you've contributed little to solving the problem you're having with your code. You've shown what you have, and you've said that it doesn't work, but you haven't said anything about options you've tried, or what you think is going wrong. You've asked for solutions and said, "that doesn't work either."

The question you asked about declaring the character array suggests you don't understand the basic ideas of variable scope, or don't want to bother thinking about them when you can ask someone else to give you the answer.

I have the impression that you're fairly new to programming and are trying to follow a path that's guaranteed to fail. I don't think you understand the code you've posted well enough to modify it successfully. Those are problems that can be solved, but not by the approach you've taken so far.

If you want to listen to the advice I can give you, we can continue. If not, we're done here. My responsibility stops at making sure the hardware is functional.

adafruit_support_mike
 
Posts: 58410
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.