1

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);
}
  • Please show the code you have problems with, and tell us something about what goes wrong. – StarCat Mar 04 '20 at 11:06
  • I update the code in the post. The problem is I got 0 value for lat, lng in firebase. Sometimes it provides the correct value in firebase(the ratio is too low). – Sayedur Rahman Mar 04 '20 at 11:48
  • With Firebase.push you 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 use Firebase.setString("location", location_str);. It would also be a good idea to move the code that writes into the Firebase into the if (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 the Serial.println(latt, 6); and Serial.println(lngg, 6); prints out someth. – Peter Paul Kiefer Mar 04 '20 at 13:45
  • 1
    I don't understand more about your comment. Can you please help me to arrange the code, where i can store lat, lng in firebase database with nodemcu. – Sayedur Rahman Mar 04 '20 at 14:35

0 Answers0