GPS Format not readable

Hello,
I am using SIM808 with GPS+GSM module.

My result is not providing the result as expected. I want when AT+CGPSSTATUS? value is "Location 3D Fix", then AT+CGPSOUT=2 will fire. I have put this logic in loop. After that the GPS format is not readable.
Whereas when I am performing this action manually from command terminal software it is working fine.
Below is my sketch:

#include <SoftwareSerial.h>
#define RXPIN 5
#define TXPIN 4

SoftwareSerial gpsSerial(TXPIN , RXPIN);  //4 is for TX and 3 is for RX

void setup() {
  Serial.begin(4800);
  gpsSerial.begin(4800); // connect gps sensor
  gpsSerial.println("AT");
  delay(1000);
  printSerialData();
  gpsSerial.println("AT+CGPSPWR=1");
  delay(2000);
  printSerialData();
  gpsSerial.println("AT+CGPSRST=0");
  delay(3000);
  printSerialData();
  gpsSerial.println("AT+CIPSHUT");
  delay(3000);
  printSerialData();
  gpsSerial.println("AT+CIPMUX=0");
  delay(2000);
  printSerialData();
  gpsSerial.println("AT+CGATT=1");
  delay(1000);
  printSerialData();
  gpsSerial.println("AT+CSTT=\"voda.com\",\"\",\"\"");
  delay(1000);
  printSerialData();
  gpsSerial.println("AT+CIICR");
  delay(6000);
  printSerialData();
  gpsSerial.println("AT+CIFSR");
  delay(6000);
  printSerialData(); 
  }
  void loop()
  {
    char c = gpsSerial.println("AT+CGPSOUT=2");
    String gpssatatus = "Location 3D Fix";
    
    //gpsSerial.println(c);
    delay(3000);
    while (gpssatatus != 0)
    {
      gpsSerial.println("AT+CGPSSTATUS?");
      printSerialData();
    }
    gpsSerial.println(c);
    printSerialData();
  }

The below is the output I a getting:

+CGPSSTATUAT+CIPSHUT

+CGPSSTATUS: Location 3D Fix

OK
$GPGGA,140214.AT+CIPMUX=0

+CGPSSTATUS: Location 3D Fix

OK
$GPGGA,140217AT+CGATT=1

+CGPSSTATUS: Location 3D Fix

OK
$GPGGA,140219.AT+CSTT="voda.com","",""

+CGPSSTATUS: Location 3D Fix
AT+CIICR

+CGPSSTATUS: Location 3D Fix

OK
$GPGGA,140222.00AT+CIFSR

+CGPSSTATUS: Location 3D Fix

OK
$GPGGA,140228.00AT+CGPSOUT=2

+CGPSSTATUS: Location 3D Fix

OK
$GPGGA,14023⸮⸮⸮⸮⸮ɚ⸮r⸮$⸮r⸮⸮⸮⸮⸮Db⸮d$ibrb⸮Tt⸮⸮⸮⸮S⸮ը⸮*PU⸮(⸮⸮T*PUCPTUPU⸮CPT*PUCCTUP⸮*H⸮]Z⸮⸮ Fi=-5jZ5⸮⸮Uե⸮5⸮⸮⸮T⸮⸮⸮⸮⸮BT*UU*'Ӭ]Z⸮⸮⸮ix
⸮5Q⸮⸮EQU⸮
Z5E⸮j(ji⸮UU⸮⸮ii⸮*(⸮⸮CPTUPU⸮⸮

Please advice

Thanks-
Pokhraj

    char c = gpsSerial.println("AT+CGPSOUT=2");

What do you expect 'c' to contain?!? I think what you get back is the number of characters sent. I think in this case it will be 12.

    gpsSerial.println(c);

I don't think this is going to do whatever you intended it to do!

I think for that first part you maybe meant:

    const char *c = "AT+CGPSOUT=2";
  gpsSerial.println(c);

Hello
I have written one new sketch from the scratch. It is working as expected. $GPGGA data is coming at serial monitor as expected.

The problem is when I send the data by using AT+CIPSEND, the result is coming "SEND OK". But at the Server window[I am using TC/IP server. GSM is client, and my Laptop is server] it is showing AT+CIPSEND=1, not the string "$GPGGA". Am I doing any mistakes?

Here is the below sketch.

#include <SoftwareSerial.h>
#include<stdio.h>
#include<string.h>
#define DEBUG true
#define RXPIN 5
#define TXPIN 4

SoftwareSerial mySerial(TXPIN , RXPIN);  //4 is for TX and 3 is for RX

void setup() {
  Serial.begin(4800);
  mySerial.begin(4800); // connect gps sensor
  sendData("AT+CIPSHUT\r\n",1000,DEBUG);
sendData("AT+CIPMUX=0\r\n",1000,DEBUG);
sendData("AT+CGATT=1\r\n",1000,DEBUG);
sendData("AT+CSTT=\"voda.com\",\"\",\"\"\r\n",1000,DEBUG);
sendData("AT+CIICR\r\n",2000,DEBUG);
sendData("AT+CIFSR\r\n",1000,DEBUG);
sendData("AT+CIPSTART=\"TCP\",\"xxx.xxx.xxx.3\",\"4001\"\r\n",1000,DEBUG);

  }
  void loop()
  {
getgps();
   while(1)
   {
        //sendData( "AT+CGPSOUT=2",1000,DEBUG);
        String gpsoutput="AT+CGPSOUT=2";
        String cipSend ="AT+CIPSEND=";
        cipSend +=String(gpsoutput.length());
        cipSend +="\r\n";
        sendData(cipSend,500,DEBUG);
     delay(2000);   
        //delay(3000);
   }
  }




void getgps(void)
{
   sendData( "AT+CGNSPWR=1",1000,DEBUG); 
   sendData( "AT+CGNSSEQ=GGA",1000,DEBUG); 
}

String sendData(String command, const int timeout, boolean debug)
{
    String response = "";    
    mySerial.println(command); 
    long int time = millis();   
    while( (time+timeout) > millis())
    {
      while(mySerial.available())
      {       
        char c = mySerial.read(); 
        response+=c;
      }  
    }    
    if(debug)
    {
      Serial.print(response);
    }    
    return response;
}

Please advice.

It might help to log both the Command (as sent) and the response:

#include <SoftwareSerial.h>

const boolean DEBUG = true;
#define RXPIN 5
#define TXPIN 4

SoftwareSerial mySerial(TXPIN , RXPIN);  //4 is for TX and 3 is for RX

void setup() {
  Serial.begin(4800);
  mySerial.begin(4800); // connect gps sensor
  
  sendData("AT+CIPSHUT\r\n", 1000, DEBUG);
  sendData("AT+CIPMUX=0\r\n", 1000, DEBUG);
  sendData("AT+CGATT=1\r\n", 1000, DEBUG);
  sendData("AT+CSTT=\"voda.com\",\"\",\"\"\r\n", 1000, DEBUG);
  sendData("AT+CIICR\r\n", 2000, DEBUG);
  sendData("AT+CIFSR\r\n", 1000, DEBUG);
  sendData("AT+CIPSTART=\"TCP\",\"xxx.xxx.xxx.3\",\"4001\"\r\n", 1000, DEBUG);

  // formerly in void getgps(void)
  sendData( "AT+CGNSPWR=1", 1000, DEBUG);
  sendData( "AT+CGNSSEQ=GGA", 1000, DEBUG);
}

void loop()
{
  //sendData( "AT+CGPSOUT=2",1000,DEBUG);
  String gpsoutput = "AT+CGPSOUT=2";
  String cipSend = "AT+CIPSEND=";
  cipSend += String(gpsoutput.length());
  cipSend += "\r\n";
  sendData(cipSend, 500, DEBUG);
  delay(2000);
}

String sendData(String command, const int timeout, boolean debug)
{
  String response = "";
  if (debug) {
    Serial.print(F("Command: \""));
    Serial.print(command);
    Serial.println("\"");
  }
  mySerial.println(command);

  long int time = millis();
  while (millis() - time < timeout)
  {
    while (mySerial.available())
    {
      char c = mySerial.read();
      response += c;
    }
  }
  if (debug)
  {
    Serial.print(F("Response: \""));
    Serial.print(response);
    Serial.println("\"");
  }
  return response;
}
#define RXPIN 5
#define TXPIN 4

SoftwareSerial gpsSerial(TXPIN , RXPIN);  //4 is for TX and 3 is for RX

When the comments don't match the code, the programmer looks foolish. That's not what you want, is it?

I ran the sketch. Here the output I am getting at serial monitor:

Response: "
SEND OK
$GPGGA,191304.000,2227.7441,N,08822.3991,E,1,9,1.00,AT+CIPSEND=12


> $GPGGA,191306.000,2227.7441,N,08822.3991,E,1,9,1.00,16.2,M,-55.7,M,,*46
"
Command: "AT+CIPSEND=12
"
Response: "$GPGGA,191307.000,2227.7441,N,08822.3991,E,1,9,1.00,16.2,M,-55.AT+CIPSEND=12

$GPGGA,191309.000,2227.7441,N,08822.3990,E,1,9,1.00,16.2,M,-55.7,M,,*48
"
Command: "AT+CIPSEND=12
"
Response: "
SEND OK
$GPGGA,191310.000,2227.7441,N,08822.3990,E,1,9,1.00,AT+CIPSEND=12


> $GPGGA,191312.000,2227.7441,N,08822.3990,E,1,9,1.00,16.2,M,-55.7,M,,*42
"
Command: "AT+CIPSEND=12
"
Response: "$GPGGA,191313.000,2227.7441,N,08822.3990,E,1,9,1.00,16.2,M,-55.AT+CIPSEND=12

$GPGGA,191315.000,2227.7441,N,08822.3990,E,1,9,1.00,16.2,M,-55.7,M,,*45
"

But at the server program I am getting as below:

1AT+CIPSEND=1AT+CIPSEND=1AT+CIPSEND=1AT+CIPSEND=1AT+CIPSEND=1AT+CIPSEND=1

But I am not able to see any GPGGA value at Server program

Please advice

Thanks-
Pokhraj

You said that it works if you issue the commands manually. Do all the commands you send manually get the same responses as they do when the sketch sends them?

Do all the commands you send manually get the same responses as they do when the sketch sends them?

Yes... All the commands gives the same responses except AT+CIPSEND.

Manually, I am performing as below:

AT+CIPSEND <Press Enter>
> Sign is coming at command prompt
>Hello test
Press [ctrl+z]
SEND OK

I am able to find the above test Hello test at the server software.

Thanks-
Pokhraj

In your sketch you send "AT+CIPSEND=12" which is different from the "AT+CIPSEND" you do manually. What does the "=12" mean?

That is what I am not sure about. Is it datalength or bytes?

Thanks-
Pokhraj

How do I get the UART data to a string variable?
For example if I want to capture the UART data such as $GPGGA value to a string variable how do I do that?

Below is my sketch:

#include <SoftwareSerial.h>
#include<stdio.h>
#include<string.h>
#define DEBUG true
#define RXPIN 5
#define TXPIN 4

SoftwareSerial mySerial(TXPIN , RXPIN);
char test = mySerial.print();