I have an ESP32 connected to a NEO-6M GPS Module. I'm trying to get the Latitude and Longitude of my Location so I can put it in my Database in making a GPS Map in my app. My code seems to be okay, no errors or anything, but it still havent given me no data. Both lat and lng just return 0.000000. I heard that I need to go outside or to another area and or waiting for at least an hour or more so the GPS module can have a better chance in getting data, but I'm not sure. Any solutions? Are there any modules you recommend in getting the data faster?
Here is my wiring:
VCC - 3V3
RX - TX2
TX - RX2
GND - GND
And here is the code
#include <Arduino.h>
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include <TinyGPS++.h>
#include <TinyGPSPlus.h>
#include <Wire.h>
//-------------------------------------------------------//
#include <Firebase_ESP_Client.h>
//Provide the token generation process info.
#include "addons/TokenHelper.h"
//Provide the RTDB payload printing info and other helper functions.
#include "addons/RTDBHelper.h"
//Provide the token generation process info.
#include "addons/TokenHelper.h"
//Provide the RTDB payload printing info and other helper functions.
#include "addons/RTDBHelper.h"
// Insert Firebase project API Key
#define API_KEY "***********"
// Insert RTDB URLefine the RTDB URL */
#define DATABASE_URL "***********"
//Define Firebase Data object
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
unsigned long sendDataPrevMillis = 0;
int count = 0;
bool signupOK = false;
int NoGPSData =0;
//-------------------------------------------------------//
#define WIFI_SSID "***********"
#define WIFI_PASSWORD "***********
#define RXD2 16
#define TXD2 17
HardwareSerial neogps(1);
TinyGPSPlus gps;
void setup() {
Serial.begin(115200);
//Begin serial communication Arduino IDE (Serial Monitor)
//Begin serial communication Neo6mGPS
neogps.begin(9600, SERIAL_8N1, RXD2, TXD2);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
//-------------------------------------------------------//
/* Assign the api key (required) */
config.api_key = API_KEY;
/* Assign the RTDB URL (required) */
config.database_url = DATABASE_URL;
/* Sign up */
if (Firebase.signUp(&config, &auth, "", "")){
Serial.println("ok");
signupOK = true;
}
else{
Serial.printf("%s\n", config.signer.signupError.message.c_str());
}
/* Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
//-------------------------------------------------------//
delay(300);
}
void loop() {
float latitude = gps.location.lat();
float longitude = gps.location.lng();
boolean newData = false;
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (neogps.available())
{
if (gps.encode(neogps.read()))
{
newData = true;
}
}
}
//If newData is true
if(newData == true && gps.location.lat() > 0 && gps.location.lng() > 0)
{
newData = false;
Serial.print("Latitude: ");
Serial.println(gps.location.lat(),6);
Serial.print("Longitude: ");
Serial.println(gps.location.lng(),6);
//Serial.println(gps.satellites.value());
if (Firebase.RTDB.setInt(&fbdo, "test/Location/GPSCheck",1)){
}
else {
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
if(Firebase.RTDB.setFloat(&fbdo,"test/Location/latitude",latitude)){
}else{
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
if(Firebase.RTDB.setFloat(&fbdo,"test/Location/longitude",longitude)){
}else{
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
//-------------------------------------------------------//
}
else
{
if (Firebase.RTDB.setInt(&fbdo, "test/Location/GPSCheck",NoGPSData )){
}
else {
Serial.println("FAILED");
Serial.println("REASON: " + fbdo.errorReason());
}
Serial.println("No Data");
}
delay(100);
}