I m working on GPS Locator n i want help in interface GPS and GSM that is use to send latitude and longitude value to the TCP server over internet.I have configured my laptop as a TCp server and GSM module as client
I have the below sketch for GPS , which is working as expected:
#include <Adafruit_GPS.h>
#include <String.h>
#include <SoftwareSerial.h>
SoftwareSerial myserial(3,2); //This is a serial port where TX[3 port] and RX[2 port] are connected
Adafruit_GPS GPS(&myserial); //Create the GPS object
String NMEA1; // Hold the GPS data
String NMEA2; // Hold the GPS data
char c;
void setup() {
Serial.begin(115200); //Turn on serial Monitor
GPS.begin(9600); // Turn on GPS at 9600 Baud rate Speed
GPS.sendCommand("$PGCMD,33,0*6D"); //Turns off the antenna for garbage value
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); //To keep the data sort successfullt
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); // Only RMC and GGA will taken into consideration
delay(3000);
}
void loop() {
readGPS();
}
void readGPS(){
while(!GPS.newNMEAreceived()){
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());
NMEA1=GPS.lastNMEA();
while(!GPS.newNMEAreceived()){
c=GPS.read();
}
GPS.parse(GPS.lastNMEA());
NMEA2=GPS.lastNMEA();
Serial.println(NMEA1);
Serial.println(NMEA2);
Serial.println("");
}
Below is the GSM sketch which I am able to connect via USb connector for Remote TCP server:
AT
AT+CIPSHUT
AT+CIPMUX=0
AT+CGATT=1
AT+CSTT="APN",<Userid>,<Password>
AT+CIICR
AT+CISF
AT+CIPSTART="TCP",<PIBLICIP>,<PORT>
AT+CIPSEND
I want to integrate both GPS and GSM module which will connect and send GPS data over internet to the TCP server.
Please help me to resolve the issue.
Not sure what are all the libraries I need to refer.
For what purpose?
Do I need to include SIM900A.h at arduino sketch.
Most likely.
It does not appear that you have any requirements. Start by making a DETAILED list of what the program is actually supposed to do, with as much detail as possible.
Store the value read from the GPS and print it. That way, you'll KNOW whether there is data coming in from the GPS. If not, then perhaps you have the TX and RX lines swapped. If there is, but it doesn't look right, perhaps you have a baud rate issue.
Debugging by guesswork is the worst possible way to debug code.
Is there is again required decode function to decode the NMEA data?
I'm not sure that I understand your question. The decode() function has to be given each character read from the GPS. It stores the characters in an array, and determines if any given character is the one that says "this is the end of a GPS sentence". When it gets one that is, it parses the stored data, and returns true, indicating that you can now use the parsed data. If the character is not the one that says that a sentence is complete, decode() returns false, meaning that you should not be using the parsed data.
while(gpsSerial.available()) { // check for gps data
if(gps.encode(gpsSerial.read())) { // encode gps data
gps.get_position(&lat,&lon,null); // get latitude and longitude
Except that I'd store the character and print it, too. And, I'd position the curly braces better. And, I'd ditch the comments that add no value.
while(gpsSerial.available())
{
char c = gpsSerial.read();
Serial.print(c);
if(gps.encode(c))
{
gps.get_position(&lat,&lon,null);
With that line in place, you get some serial data that you haven't shared. Without it, you don't get any. One can only conclude, then, that decode() is never returning true. Do you understand what that means? Do you think that it might be important to share what only you can see, like the serial output?
Here is the new set of code: The only task I want to perform is to send the SMS to my number 9007558976:
#include <SoftwareSerial.h>
#include "TinyGPS.h"
#define RXPIN 3
#define TXPIN 4
SoftwareSerial gpsSerial(TXPIN , RXPIN); //4 is for TX and 3 is for RX
TinyGPS gps; // create gps object
const int timesTosend=1;
char phone_no[]="9007558976";
void setup() {
Serial.begin(115200);
gpsSerial.begin(9600); // connect gps sensor
delay(2000);
Serial.println("AT+CMGF=1");
delay(200);
}
void loop() {
static int count = 0;
static long lat=0,lon=0;
if (count < timesTosend)
{
while(gpsSerial.available())
{
char c = gpsSerial.read();
Serial.print(c);
if(gps.encode(c)) { // encode gps data
gps.get_position(&lat,&lon); // get latitude and longitude
Serial.print("AT+CMGS=\"");
Serial.print(phone_no);
Serial.println("\"");
// Wait for '>'
while(Serial.read() != '>');
Serial.print(lat);
Serial.print(", ");
Serial.print(lon);
Serial.write(0x0D); // Carriage Return in Hex
Serial.write(0x0A); // Line feed in Hex
Serial.write(0x1A); // sends ctrl+z end of message
count++;
//The 0D0A pair of characters is the signal for the end of a line and beginning of another.
delay(5000);
}
}
}
}
While compiling I am facing the below error :
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x24
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x47
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x50
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x52
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x4d
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x43
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x2c
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x2c
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x56
An error occurred while uploading the sketch
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x2c
the error has gone.... What I did , I remove the RX of GSM from arduino [RX 0] to another pin 5.
The compilation error gone. But the SMS is not coming at my mobile.
Once again you are failing to take the opportunity to print the message coming from the device, so you are missing what the device might be telling you, in terms of what is wrong.
You REALLY need a Mega for this project, so you can have 2 external serial devices connected and still be able to use Serial for debugging.