FireBase: Get Latitude and Longitude, different bucket id, how?

Hello Fenil

I see you have a number of Lat-Long Data Sets in FireBase.

  1. What exactly is your issue in downloading the data you need?
  2. Is the data to be available to several Users or just you?
  3. "Different Bucket ID" - not entirely sure of your issue @TIMAI2

Thanks For your reply, i have taken data from the GPS module throw the GSM and when i get data each and every time data store in new bucket but i didn't want this type i just want as new data come old data can clear and replace with new data it can be a possible top do? and if it possible the how can i do this?

So I think this is basically a FireBase issue you have and the best person to help you with that is my fellow Power User @TIMAI2

Hopefully Tim can solve this for you.

How are you uploading the data? Via an Arduino microcontroller? Ensure the Sketch is not creating a new bucket ID at each loop.

Please show your relevant blocks for sending data to Firebase.

yes Via an Arduino microcontroller and creating a new bucket ID at each loop.
i am get data new bucket and
print on scren data with update new bucket ID data have change to value

//Enabling SSL 1.0
if(USE_SSL == true){
SIM800.println("AT+HTTPSSL=1");
waitResponse();
delay(DELAY_MS);
}
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Setting up parameters for HTTP session
SIM800.println("AT+HTTPPARA="CID",1");
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Set the HTTP URL - Firebase URL and FIREBASE SECRET
SIM800.println("AT+HTTPPARA="URL","+FIREBASE_HOST+".json?auth="+FIREBASE_SECRET);
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Setting up re direct
SIM800.println("AT+HTTPPARA="REDIR",1");
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Setting up content type
SIM800.println("AT+HTTPPARA="CONTENT","multipart/form-data;boundary=----8283"\r\n");
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Setting up Data Size
//+HTTPACTION: 1,601,0 - error occurs if data length is not correct

SIM800.println("AT+HTTPDATA=" + String(data.length()) + ",10000");
waitResponse("DOWNLOAD");
//delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Sending Data
SIM800.println(data);
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Sending HTTP POST request
SIM800.println("AT+HTTPACTION=1");

for (uint32_t start = millis(); millis() - start < 20000;){
while(!SIM800.available());
String response = SIM800.readString();
if(response.indexOf("+HTTPACTION:") > 0)
{
Serial.println(response);
break;
}
}

OK, you are sending data direct from the arduino to firebase ? ( I do not know much about this, but am guessing this uses the REST API). You need to use http PUT to overwrite existing data.

Do you have an authenticated user on firebase to save/access the data ?
Do you have secure rules in place (on firebase) ?

Does that actually work with Arduino? You would normally state the milliseconds thus: delay(20); Perhaps we simply don't see your initialisation of DELAY_MS as an integer.

Is that true?

  1. I can't see that in your Sketch code
  2. Wouldn't that be the cause of the issue if you only want the data to overwrite existing data?

#include <TinyGPS++.h>
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM

void init_gsm();
void gprs_connect();
boolean gprs_disconnect();
boolean is_gprs_connected();
void post_to_firebase(String data);
boolean waitResponse(String expected_answer="OK", unsigned int timeout=2000);
TinyGPSPlus gps;
volatile float minutes, seconds;
volatile int degree, secs, mins;
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
#include <SoftwareSerial.h>
//GSM Module RX pin to Arduino 3
//GSM Module TX pin to Arduino 2
#define rxPin 9
#define txPin 10
SoftwareSerial SIM800(rxPin,txPin);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM

const String APN = "VI Net Speed";
//const String APN = "airtelgprs.com";
const String USER = "";
const String PASS = "";

const String FIREBASE_HOST = "https://arduin------------------------------southeast1.firebasedatabase.app/";
const String FIREBASE_SECRET = "l------------------------------------";
const String FIREBASE_PATH = "/";

#define USE_SSL true
#define DELAY_MS 500

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Function: setup() start
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void setup() {

//Begin serial communication with Serial Monitor
Serial.begin(9600);

//Begin serial communication with SIM800
SIM800.begin(9600);

Serial.println("Initializing SIM800...");
init_gsm();
}

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Function: loop() start
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void loop() {
smartDelay(1000);
unsigned long start;
double lat_val, lng_val, alt_m_val;
bool loc_valid, alt_valid;
lat_val = gps.location.lat();
loc_valid = gps.location.isValid();
lng_val = gps.location.lng();
alt_m_val = gps.altitude.meters();
alt_valid = gps.altitude.isValid();
if (!loc_valid)
{
Serial.print("Latitude : ");
Serial.println("");
Serial.print("Longitude : ");
Serial.println("
");
delay(4000);
}else
{
String data = get_temprature();
Serial.println(data);

if(!is_gprs_connected()){
gprs_connect();
}

post_to_firebase(data);

}
delay(1000);
}

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
String get_temprature()
{smartDelay(1000);
unsigned long start;
double lat_val, lng_val, alt_m_val;
bool loc_valid, alt_valid;
lat_val = gps.location.lat();
loc_valid = gps.location.isValid();
lng_val = gps.location.lng();
alt_m_val = gps.altitude.meters();
alt_valid = gps.altitude.isValid();
Serial.println("GPS READING: ");
DegMinSec(lat_val);
Serial.print("Latitude in Decimal Degrees : ");
Serial.println(lat_val, 6);

DegMinSec(lng_val); 
Serial.print("Longitude in Decimal Degrees : ");
Serial.println(lng_val, 6);
delay(4000);

//Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
String h = String(lat_val, 6);
String t = String(lng_val, 6);
//String h= 22.52528;
// String t =20525;

String Data = "{";
//Data += ""temprature":"" + t + " °C",";

//Data += ""humidity":"" + h + " %"";

Data += ""Latitude":"" + t + "",";

Data += ""Longitude":"" + h + """;

Data += "}";
// String Data = t ;

Serial.println(Data);
return Data;
}
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (Serial.available())
gps.encode(Serial.read());
} while (millis() - start < ms);
}

void DegMinSec( double tot_val)
{
degree = (int)tot_val;
minutes = tot_val - degree;
seconds = 60 * minutes;
minutes = (int)seconds;
mins = (int)minutes;
seconds = seconds - minutes;
seconds = 60 * seconds;
secs = (int)seconds;
}

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Function: post_to_firebase() start
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void post_to_firebase(String data)
{
/* 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);
*/
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Start HTTP connection
SIM800.println("AT+HTTPINIT");
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Enabling SSL 1.0
if(USE_SSL == true){
SIM800.println("AT+HTTPSSL=1");
waitResponse();
delay(DELAY_MS);
}
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Setting up parameters for HTTP session
SIM800.println("AT+HTTPPARA="CID",1");
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Set the HTTP URL - Firebase URL and FIREBASE SECRET
SIM800.println("AT+HTTPPARA="URL","+FIREBASE_HOST+".json?auth="+FIREBASE_SECRET);
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Setting up re direct
SIM800.println("AT+HTTPPARA="REDIR",1");
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Setting up content type
SIM800.println("AT+HTTPPARA="CONTENT","multipart/form-data;boundary=----8283"\r\n");
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Setting up Data Size
//+HTTPACTION: 1,601,0 - error occurs if data length is not correct

SIM800.println("AT+HTTPDATA=" + String(data.length()) + ",10000");
waitResponse("DOWNLOAD");
//delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Sending Data
SIM800.println(data);
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Sending HTTP POST request
SIM800.println("AT+HTTPACTION=1");

for (uint32_t start = millis(); millis() - start < 20000;){
while(!SIM800.available());
String response = SIM800.readString();
if(response.indexOf("+HTTPACTION:") > 0)
{
Serial.println(response);
break;
}
}

delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//+HTTPACTION: 1,603,0 (POST to Firebase failed)
//+HTTPACTION: 0,200,0 (POST to Firebase successfull)
//Read the response
SIM800.println("AT+HTTPREAD");
waitResponse("OK");
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Stop HTTP connection
SIM800.println("AT+HTTPTERM");
waitResponse("OK",1000);
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
}

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Initialize GSM Module
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void init_gsm()
{
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Testing AT Command
SIM800.println("AT");
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Checks if the SIM is ready
SIM800.println("AT+CPIN?");
waitResponse("+CPIN: READY");
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Turning ON full functionality
SIM800.println("AT+CFUN=1");
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Turn ON verbose error codes
SIM800.println("AT+CMEE=2");
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Enable battery checks
SIM800.println("AT+CBATCHK=1");
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Register Network (+CREG: 0,1 or +CREG: 0,5 for valid network)
//+CREG: 0,1 or +CREG: 0,5 for valid network connection
SIM800.println("AT+CREG?");
waitResponse("+CREG: 0,");
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//setting SMS text mode
SIM800.print("AT+CMGF=1\r");
waitResponse("OK");
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
}

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Connect to the internet
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void gprs_connect()
{
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//DISABLE GPRS
SIM800.println("AT+SAPBR=0,1");
waitResponse("OK",60000);
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Connecting to GPRS: GPRS - bearer profile 1
SIM800.println("AT+SAPBR=3,1,"Contype","GPRS"");
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//sets the APN settings for your sim card network provider.
SIM800.println("AT+SAPBR=3,1,"APN","+APN);
waitResponse();
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//sets the user name settings for your sim card network provider.
if(USER != ""){
SIM800.println("AT+SAPBR=3,1,"USER","+USER);
waitResponse();
delay(DELAY_MS);
}
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//sets the password settings for your sim card network provider.
if(PASS != ""){
SIM800.println("AT+SAPBR=3,1,"PASS","+PASS);
waitResponse();
delay(DELAY_MS);
}
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//after executing the following command. the LED light of
//sim800l blinks very fast (twice a second)
//enable the GPRS: enable bearer 1
SIM800.println("AT+SAPBR=1,1");
waitResponse("OK", 30000);
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
//Get IP Address - Query the GPRS bearer context status
SIM800.println("AT+SAPBR=2,1");
waitResponse("OK");
delay(DELAY_MS);
//MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
}

/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • Function: gprs_disconnect()

  • AT+CGATT = 1 modem is attached to GPRS to a network.

  • AT+CGATT = 0 modem is not attached to GPRS to a network
    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
    boolean gprs_disconnect()
    {
    //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
    //Disconnect GPRS
    SIM800.println("AT+CGATT=0");
    waitResponse("OK",60000);
    //delay(DELAY_MS);
    //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
    //DISABLE GPRS
    //SIM800.println("AT+SAPBR=0,1");
    //waitResponse("OK",60000);
    //delay(DELAY_MS);
    //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM

    return true;
    }

/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • Function: gprs_disconnect()

  • checks if the gprs connected.

  • AT+CGATT = 1 modem is attached to GPRS to a network.

  • AT+CGATT = 0 modem is not attached to GPRS to a network
    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
    boolean is_gprs_connected()
    {
    SIM800.println("AT+CGATT?");
    if(waitResponse("+CGATT: 1",6000) == 1) { return false; }

    return true;
    }

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Handling AT COMMANDS
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//boolean waitResponse(String expected_answer="OK", unsigned int timeout=2000) //uncomment if syntax error (arduino)
boolean waitResponse(String expected_answer, unsigned int timeout) //uncomment if syntax error (esp8266)
{
uint8_t x=0, answer=0;
String response;
unsigned long previous;

//Clean the input buffer
while( SIM800.available() > 0) SIM800.read();

//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
previous = millis();
do{
//if data in UART INPUT BUFFER, reads it
if(SIM800.available() != 0){
char c = SIM800.read();
response.concat(c);
x++;
//checks if the (response == expected_answer)
if(response.indexOf(expected_answer) > 0){
answer = 1;
}
}
}while((answer == 0) && ((millis() - previous) < timeout));
//NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

Serial.println(response);
return answer;
}

full code

So, as per Tim's note, if you change the post-to function to "PUT", does that yield the result required?

[lines 8, 78, 150 plus various comment lines]

We are print this result as well as we are most intrested to share latitude and longitude on firbase server withoust making chiled key.