Slowdown in Retrieving tags from firebase in Real-time

(added to FAQ)

But the OP indicated they wanted the latest / last timestamp ?

In my example, they get the latest added while they are monitoring.

Am I moving the target to fit where the arrow landed?

In my example, I get Firebase to do all the grunt work, and just return the latest/last timestamp value of the tag (that may or may not be the same as the timestamp value - in an earlier screenshot of the data the tag and the timestamp value were different)

Your arrows are rarely, if ever, wide of the mark though :wink:

I will leave it up to the OP which solution fits him.

I have not heard back from him if he has control over the indexing in the database, or if he is stuck at the receiving end with no control.

I would check into Firebase docs to see what they think of indexing on a steadily ascending value like a milliseconds timestamp. Those tend to skew B-tree indexes, unless the technology has improved since I last saw one.

If he goes with an index, it would be interesting to see if the extra index slows down his fast arriving inserts.

Your query definitely gets just the last value, so if he is bouncing among different data collections, that's the way to go.

Sorry bout replying late, I was busy with the other aspects of the project, the thing is, I'm trying to build a real time monitoring system so that the user can see their reading on the MIT application, in real time as they are using the sensors, so if any change in data occurs, they can see it on the app, from firebase, the data is continuously generating when the ESP32 is connected to the internet. so I need the data on the app to be transmitting to the app continuously in real time.

Let us take a few steps back.

Do you want all the readings for a user returned to the app, or just the latest/last reading available for a user, at any given time ?

How often is a new reading generated for a user ?

The readings are being updated on firebase every 6 seconds, I require the latest timestamp, whenever it is updated on firebase to be displayed on the app.

image

Setup your indexOn as I showed above:

image

Did do the steps you provided and I have gotten following output,


Screenshot 2023-05-18 222013

As you can see, I did your steps and I have recieved the latest timestamp, however, I do not require the entire data of the timestamp project bucket, rather, I need an individual tag inside it, just like bpm, spo and temperature

That's the same JSON I extract fields from in my earlier post at

Start at the JSONDecodeWithDictionaries.

Why are these two numbers not the same ?

image

You have two choices:

  1. Make several calls to firebase after you get the latest record for each of the items you want data for (by which time the next record will have arrived....)

  2. Extract the values from the json returned, as @ABG has suggested (or something like that) within the app