问题
I have some problem with my project. I am using SIM800L and GPS Neo6MV2 with arduino genuine uno. My project is sending GPS location by message. But, the message i received only contained long = 0,000000 lat = 0, 000000. Here is my code:
#include <TinyGPS++.h>
TinyGPSPlus gps;
//float latitude, longitude;
int myled=13;
#include <SoftwareSerial.h>
SoftwareSerial SIM800L(7, 8);
//SoftwareSerial gps_serial(2,3);
String response;
int lastStringLength = response.length();
String latitude, longitude;
String link;
void setup() {
Serial.begin(9600);
Serial.println("GPS Mulai");
SIM800L.begin(9600);
SIM800L.println("AT+CMGF=1");
Serial.println("SIM800L started at 9600");
delay(1000);
Serial.println("Setup Complete! SIM800L is Ready!");
SIM800L.println("AT+CNMI=2,2,0,0,0");
gps.encode(Serial.read());
latitude = gps.location.lat();
longitude = gps.location.lng();
}
void loop() {
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}
if (SIM800L.available()>0){
response = SIM800L.readStringUntil('\n');
}
if(lastStringLength != response.length()){
}
if(response.indexOf("ON") == 4){
SIM800L.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
SIM800L.println("AT+CMGS=\"082232949301\"\r"); // Replace x with mobile number
delay(1000);
SIM800L.println("https://www.google.com/maps?q=" + latitude+","+longitude) ;// The SMS text you want to send
delay(100);
SIM800L.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
}
Could you help me to resolve this?
来源:https://stackoverflow.com/questions/51888222/my-gps-cant-share-the-location-by-sms