I'm using nodemcu and neo6m gps module. I can't send data to firebase. As a library using tinygps++. Can anyone please help me how can i pass data to firebase.
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include "TinyGPS++.h"
#include "SoftwareSerial.h"
// Set these to run example.
#define FIREBASE_HOST "vessel-monitoring-a21f4.firebaseio.com"
#define FIREBASE_AUTH "EYUZc64JyLMR5cbJc99nZzjah8uwEDxSp3m93Lvr"
#define WIFI_SSID "H17"
#define WIFI_PASSWORD "pass@router"
//GPS
SoftwareSerial serial_connection(4, 0); //tx,rx
TinyGPSPlus gps;// GPS object to process the NMEA data
float latt, lngg;
void setup() {
Serial.begin(9600);
serial_connection.begin(9600);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop() {
while (serial_connection.available()) {
gps.encode(serial_connection.read());
}
if (gps.location.isUpdated()) {
latt = gps.location.lat();
lngg = gps.location.lng();
Serial.println(latt, 6);
Serial.println(lngg, 6);
delay(1000);
}
char location_str[25]={0};
sprintf(location_str, "%f, %f", latt, lngg);
String name = Firebase.push("location", location_str);
if (Firebase.failed()) {
Serial.print("setting /location failed:");
Serial.println(Firebase.error());
return;
}
delay(1000);
}
Firebase.pushyou add a new location to the "location"-collection with every call. Is that, what you intended to do? If you just want to set a string to the location attribute useFirebase.setString("location", location_str);. It would also be a good idea to move the code that writes into the Firebase into theif (gps.location.isUpdated())block. IMHO You only have to write into the Firebase if the location has been changed. Btw I would understand the behavior of the code better, if I'd know whether theSerial.println(latt, 6);andSerial.println(lngg, 6);prints out someth. – Peter Paul Kiefer Mar 04 '20 at 13:45