Go Down

Topic: How to send GPS coordinates with this code? (Read 10957 times) previous topic - next topic

68mustang

Mar 22, 2016, 10:01 pm Last Edit: Mar 23, 2016, 08:16 pm by 68mustang
Hi, I am using SIM800L module and I succeeded sending simple text message but I cant send variable in message body.

My device (in the future) will be updating GPS coordinates stored in variables and then send those via SMS.

My problem is converting those variables to whatever format is used.

There is the code:

Code: [Select]
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
 
SMSGSM sms;
 
char number[]="123123123";
char message[180]="123";
char text[180];
char pos;
char *p;


String lat;
String lon;
String textSMS;

void setup()
{
  lat = '50.0467656';
  lon = "20.0048731";

  textSMS = ("comgooglemaps://?q="+lat+','+lon);
 // strcpy(text, "http://www.bing.com/maps?");
  strcat(text, textSMS);
 // dtostrf(gps.location.lat(), 1, 6, latitude);
 // strcat(message,latitude);
 
 Serial.begin(9600);
 if (gsm.begin(2400))
   Serial.println("\nstatus=READY");
 else Serial.println("\nstatus=IDLE");
};
 
void loop()
{
 pos=sms.IsSMSPresent(SMS_UNREAD);
 Serial.println((int)pos);
 if((int)pos>0&&(int)pos<=20){
   Serial.print("Incomming message, POS=");
 
   Serial.println((int)pos);
 
   message[0]='\0';
 
   sms.GetSMS((int)pos,number,message,180);
 
   p=strstr(message,"password");
 
   if(p){
 
     Serial.println("success");
 
     sms.SendSMS(number, textSMS);
 
   }
     
     }
 
   
 
   sms.DeleteSMS((int)pos);
 
 
 
 delay(5000);
 
};



How should I change the code to be able to connect those 3 things in message body into 1 link: "comgooglemaps://?q=" + latitude + ',' + longtitude"

so the message look like this: comgooglemaps://?q=50.0467656,20.0048731

I can't convert variable textSMS to paste it in sms.SendSMS();
Thank you!


68mustang


dannable

Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

68mustang

I did it with a little help of others.

In case anybody have a similar issue here is what i needed to do:

Code: [Select]

char text[180];

------


 String textSMS = ("comgooglemaps://?q="+lat+","+lon);
 strcpy(text, textSMS.c_str());


---------
sms.SendSMS(number, text);


68mustang

Hi I changed my code and it looks like this now:

Code: [Select]

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
#include <TinyGPS++.h>
 
SMSGSM sms;

static const int RXPin = 7, TXPin = 8;
static const uint32_t GPSBaud = 9600;

TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);

char message[160];

char datetime[24];
char latitude[12];
char longitude[12];

char number[]="123123123";

char text[160];
char pos;
char *p;
char *c;

 
void setup()
{
 Serial.begin(9600);
 ss.begin(GPSBaud);
 Serial.println("START");
 gsm.begin(2400);
 sms.SendSMS("123123123", "system ok"); // on setup SMS is sent to my number letting me know device is ON
}
 
void loop()
{
     while (ss.available() > 0)
    if (gps.encode(ss.read()))
        if (gps.location.isValid())
  {
       
        strcat(text, "comgooglemaps://?q=");
        dtostrf(gps.location.lat(), 1, 6, latitude);
        strcat(text,latitude);
        strcat(text,",");
        dtostrf(gps.location.lng(), 1, 6, longitude);
        strcat(text,longitude);

  } 
 
 pos=sms.IsSMSPresent(SMS_UNREAD);
 Serial.println((int)pos);
 
 if((int)pos>0&&(int)pos<=20){
   Serial.print("Incomming message, POS=");
   Serial.println((int)pos);
   message[0]='\0';
   sms.GetSMS((int)pos,number,message,180);
   p=strstr(message,"Rotor");
   
   if(p)
   {     
     Serial.println("Success");
     Serial.println(text);
     sms.SendSMS(number, text);  // When anybody send SMS with password=="Rotor"  ==> device sends back coordinates in mobile link to google maps
   }
 }
 
   sms.DeleteSMS((int)pos); 
 
 
 
 delay(5000);
 
}



The problem is that I get empty message from the module when I send SMS with message "Rotor".
Serial.println(text) is also empty.

I am not using GSM Shield. I am using a red SIM800L module and NEO-6M GPS. Both modules are working apart but there is something wrong with converting variable latitude and longitude... ;/

I will appreciate any help :)

KenB001

Hi 68mustang did you get your project working i am having similar problem and would like to see how you fixed it.

islanderx

Hi 68mustang!

Same here, I'm doing a very similar project, I would really appreciate if you would let me know what the issue was.

EMMANUELSAN

Hello, I'm working on a similar project but my problem is the following I'm using the gps 6m neo ublox and grps-gsm sim900 and I want you to send me the coordinates ami phone this is my programming and it does not work for me could help me with this great doubt would help me a lot!

In the method void commands (); I make the call of the variables and continue doing the function of gps.getDataGPRMC but I have that doubt for what reason I only receive blank messages! And not the coordinates
Code: [Select]



#include <SoftwareSerial.h>
#include <String.h>

#include <Gpsneo.h>

Gpsneo gps(11,10);

char time[10];
char status[3];
char latitud[11];
char latitudHemisphere[3];
char longitud[11];
char longitudMeridiano[3];
char speedKnots[10];
char trackAngle[8];
char date[10];
char magneticVariation[10];
char magneticVariationOrientation[3];


SoftwareSerial mySerial(2, 3);
SoftwareSerial ss(11,10);

int rele=6;
int sensor=7;
int buzzer=12;
int led = 13;

char mensaje=0;

boolean Activacion=false;

void setup() {
  
 pinMode(led,OUTPUT);
 pinMode(buzzer,OUTPUT);
 pinMode(rele,OUTPUT);
 
 digitalWrite(led,LOW);
 digitalWrite(rele,HIGH);
 digitalWrite(buzzer,LOW);

          
 mySerial.begin(9600);
 Serial.begin(9600);  

}

void loop() {
//////Obtener coordenadas
  

 recive();
 int s=digitalRead(sensor);

 //Serial.println(s);
 
 if(mensaje=='w'){Activacion=true;}  //Activa modo alarma con el sensor
 if(mensaje=='v'){Activacion=false;} //Desactiva modo alarma con el sensor

 if(s==LOW && Activacion==true){ // Modo sensor
 // digitalWrite(rele,LOW);
  manda();
  delay(10000);
  manda();
  delay(10000);
  manda();
  delay(10000);
  manda();
  delay(10000);
  manda();
  delay(10000);
  }
  
 if(mensaje=='z'){ ///Modo alarma
  digitalWrite(rele,LOW);
  manda();
  delay(10000);
  manda();
  delay(10000);
  manda();
  delay(10000);
  manda();
  delay(10000);
  manda();
  delay(10000);
  }

  if(mensaje=='x'){ ///Modo alarma
  //digitalWrite(rele,LOW);
  manda();
  delay(10000);
  manda();
  delay(10000);
  manda();
  delay(10000);
  manda();
  delay(10000);
  manda();
  delay(10000);
  }

  if(mensaje=='y'){ ///Modo alarma
  digitalWrite(rele,HIGH);
  
  }

}

void manda()
{
  gps.getDataGPRMC(time,
                    status,
                    latitud,
                    latitudHemisphere,
                    longitud,
                    longitudMeridiano,
                    speedKnots,
                    trackAngle,
                    date,
                    magneticVariation,
                    magneticVariationOrientation);
                    
                    
    Serial.println(latitud);
    Serial.println(latitudHemisphere);
    Serial.println(longitud);
    Serial.println(longitudMeridiano);                  
                    
  mySerial.print("AT+CMGF=1\r");    
  delay(500);
  mySerial.println("AT + CMGS = \"7471637775\";");
  delay(500);
  mySerial.println(latitud);
  delay(500);
  mySerial.println(longitud);
  delay(500);
  mySerial.println((char)26);
  delay(500);
  mySerial.println();
  delay(500);   // give module time to send SMS
  mySerial.flush();
}



void recive()
{
 
 mensaje= mySerial.read();
 
  if(mySerial.available()>0){
    Serial.print(mensaje);
   }

}

void llamada()
{

  mySerial.println("ATD + 521746377775;");//dial the number
  delay(100);
  mySerial.println();
 
  }



padiee

Sir can you send me detail circuit diagram and code of these

iPhelps_

#9
Jan 22, 2018, 05:27 pm Last Edit: Jan 22, 2018, 05:38 pm by iPhelps_
Hi everyone,

I'm trying to use some like this, but i'm using an Arduino Uno, with SIM800L at Serial (7,8) and NEO 6M at Serial (10,11). I'm trying to send GPS coordinates by SMS. The code is below:

Code: [Select]
#include <Sim800l.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>

SoftwareSerial GPS(5, 6); // RX, TX (GPS)
SoftwareSerial SMS(7, 8); // RX, TX (SMS)
TinyGPS gps1;
Sim800l Sim800l;

char latBuffer[20];
char longBuffer[20];
char fullBuffer[100];

void setup()
{
  Sim800l.begin();
  GPS.begin(9600);
  delay(1000);
  SMS.begin(9600);
  Serial.begin(9600);

  Serial.println("Waiting...");
  GPS.listen();
  delay(1000);
}

void loop()
{
  bool rec = false;
  bool rec2 = false;

  while (GPS.available() > 0)
  {
    rec = gps1.encode(GPS.read());
    break;
  }

  if (rec)
  {
    Serial.println("----------------------------------------");

    //Latitude e Longitude
    float latitude, longitude;
    unsigned long age;
    gps1.f_get_position(&latitude, &longitude, &age);
    float lat = latitude;
    float lon = longitude;

    if (latitude != TinyGPS::GPS_INVALID_F_ANGLE)
    {

      Serial.print("Latitude: ");
      Serial.println(lat);
    }

    if (longitude != TinyGPS::GPS_INVALID_F_ANGLE)
    {
      Serial.print("Longitude: ");
      Serial.println(lon);
    }

    dtostrf(lat, 0, 4, latBuffer);
    dtostrf(lon, 0, 4, longBuffer);
    sprintf_P(fullBuffer, PSTR("Lat: %s; Lon: %s"), latBuffer, longBuffer);
    Serial.println(fullBuffer); //show in Serial

    GPS.end();
    delay(1000);
    SMS.listen();
    delay(100);

    while (SMS.available() > 0)
    {
      Sim800l.sendSms("+XXXXXXXXXX", fullBuffer);
      delay(1000);
      GPS.begin(9600);
      delay(1000);
      GPS.listen();
      delay(1000);
    }
  }
}

 

What I get on Serial:

Code: [Select]
Waiting...
----------------------------------------
Latitude: -21.98
Longitude: -47.88
Lat: -21.9841; Lon: -47.8832


And it stops.

I tried everything I've read here, ".listen()" commands, "delay()", but, it seems that SMS Serial is never available. I edited the SIM800L library to set pins 6 and 7 for RX and TX. It worked when it's alone, but when I attach the GPS shield, it stops.

Did someone have the same problem?

Thanks!

iPhelps_


Go Up