Arduino Uno, GPS Neo 6M, GSM SIM 800A to get the latitude and longitude and send to Firebase

I'm using Arduino Uno R3, GPS and GSM to get the latitude and longitude then send to Firebase, but I can only get the result for both latitude and longitude as 0.0000. I have try the GPS with the TinyGPS sketch before and it works. So, what is the problem for this? Hope can get helps.

#define TINY_GSM_MODEM_SIM800    
#define TINY_GSM_RX_BUFFER 256
 
#include <TinyGsmClient.h>     
#include <ArduinoHttpClient.h>      
#include <TinyGPS++.h>    
#include <SoftwareSerial.h>

#define SerialMonitor Serial

#define ARDUINO_GPS_RX 11     
#define ARDUINO_GPS_TX 10    
TinyGPSPlus tinyGPS;    
SoftwareSerial ss(ARDUINO_GPS_TX , ARDUINO_GPS_RX);    
#define gpsPort ss
  
#define rxPin 3    
#define txPin 2    
SoftwareSerial sim800(txPin,rxPin);    
 
const char FIREBASE_HOST[]  = "my_firebase_host";    
const String FIREBASE_AUTH  = "my_firebase_auth";    
const String FIREBASE_PATH  = "/";    
const int SSL_PORT          = 443;    

char apn[]  = "internet";
char user[] = "";
char pass[] = "";
 
TinyGsm modem(sim800);    

TinyGsmClientSecure gsm_client_secure_modem(modem, 0);    
HttpClient http_client = HttpClient(gsm_client_secure_modem, FIREBASE_HOST, SSL_PORT);    
 
unsigned long previousMillis = 0;    
  
void setup()    
{    
  Serial.begin(9600);    
  gpsPort.begin(9600);    
  Serial.println(F("gps serial initialize"));    
 
  sim800.begin(9600);    
  Serial.println(F("SIM800A serial initialize"));    
 
  Serial.println(F("Initializing modem..."));    
  modem.init();    
  String modemInfo = modem.getModemInfo();   
  Serial.print(F("Modem: "));   
  Serial.println(modemInfo);    
 
  http_client.setHttpResponseTimeout(10 * 1000);     
}    
 
void loop()    
{
 
  Serial.print(F("Connecting to "));    
  Serial.print(apn);    
  if (!modem.gprsConnect(apn, user, pass))    
  {    
    Serial.println(F(" fail"));    
    //delay(1000);    
    return;    
  }    
  Serial.println(F(" OK"));    
 
  http_client.connect(FIREBASE_HOST, SSL_PORT);    
 
  while (true) {    
    if (!http_client.connected())    
    {    
      Serial.println();   
      http_client.stop();// Shutdown    
      Serial.println(F("HTTP  not connected"));    
      break;    
    }    
    else    
    {   
      gps_loop();    
    }   
  }   
}   

void PostToFirebase(const char* method, const String & path , const String & data, HttpClient* http)   
{
  String response;   
  int statusCode = 0;    
  http->connectionKeepAlive();    
  String url;   
  if (path[0] != '/')   
  {   
    url = "/";   
  }   
  url += path + ".json";   
  url += "?auth=" + FIREBASE_AUTH;    
  Serial.print("POST:");   
  Serial.println(url);    
  Serial.print("Data:");    
  Serial.println(data);   
 
  String contentType = "application/json";    
  http->put(url, contentType, data);    
  
  statusCode = http->responseStatusCode();    
  Serial.print(F("Status code: "));    
  Serial.println(statusCode);    
  response = http->responseBody();   
  Serial.print(F("Response: "));   
  Serial.println(response);    
  
  if (!http->connected())   
  {   
    Serial.println();   
    http->stop();// Shutdown   
    Serial.println(F("HTTP POST disconnected"));    
  }   
 
}

 void gps_loop()   
{
  boolean newData = false;   
  for (unsigned long start = millis(); millis() - start < 2000;){   
    while (ss.available()){   
      if (tinyGPS.encode(ss.read())){   
        newData = true;   
        break;  
      }  
    }  
  }    
  
  if(true){   
  newData = false;    
  
  String latitude, longitude;   
  
  latitude = String(tinyGPS.location.lat(), 6);    
  longitude = String(tinyGPS.location.lng(), 6);    
     
  
  Serial.print("Latitude= ");    
  Serial.print(latitude);   
  Serial.print(" Longitude= ");     
  Serial.println(longitude);   
      
  String gpsData = "{";   
  gpsData += "\"lat\":" + latitude + ",";   
  gpsData += "\"lng\":" + longitude + "";   
  gpsData += "}";   
  
  PostToFirebase("PATCH", FIREBASE_PATH, gpsData, &http_client);   
    
  }
 
}

using two software Serial instances is looking for trouble. Even with one you'll be struggling

get an Arduino MEGA and use hardware Serial ports

First, you need to be outdoors, with a clear view of the sky, for the GPS to work.

Second, your sketch won't work, because you need to read the GPS serial very frequently, or you will miss characters. The organization of your program makes that nearly impossible.

Third, only one instance of SoftwareSerial can be listening at a time.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.