stanleyhuangyc / Freematics

Official source code repository for Freematics
https://freematics.com
419 stars 345 forks source link

send a message to gsm and get the coordinates using arduino #110

Open Dineshs718 opened 4 years ago

Dineshs718 commented 4 years ago

The code is here to receive the GPS location when we send the message to GSM. but it is not working. kindly please help me get the location when i send the message to GSM. Thank you.

CODE:

include "TinyGPS++.h"

include "SoftwareSerial.h"

SoftwareSerial serial_connection(10, 11); SoftwareSerial myserial(2, 3); TinyGPSPlus gps; String message; void setup() { Serial.begin(9600); myserial.begin(9600); serial_connection.begin(9600); Serial.println("GPS Start"); myserial.println("AT+CNMI=2,2,0,0,0"); delay(1000); }

void loop() { if(myserial.available()>0) { message = myserial.readString(); delay(10); } if(message.indexOf("GET LOCATION") > -1) { sms(); } }

void sms() { while(serial_connection.available()) { gps.encode(serial_connection.read()); } if(gps.location.isUpdated()) {

myserial.println("AT+CMGF=1");
delay(1000);
myserial.println("AT+CMGS=\"+918148417100\"\r"); delay(1000); myserial.println(""); myserial.println(gps.location.lat(), 6); delay(100); myserial.println(","); myserial.println(gps.location.lng(), 6); delay(100); myserial.println((char)26); delay(1000); Serial.println(""); Serial.println(gps.location.lat(), 6); Serial.println(","); Serial.println(gps.location.lng(), 6);

Serial.println("");
delay(1000);

} } GPS GSM INTERFACING.txt