-
-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A way to set the timestamp inside a json object? #91
Comments
Please share the code that you create the JSON object with timestamp. |
No more feedback? |
Hi @mobizt
I'm away from the computer till later today. I'll add my code asap
…On Sun, Aug 9, 2020, 08:01 mobizt ***@***.***> wrote:
No more feedback?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#91 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFKTX5UWV6NPXPHTBAVRYDR7Y3TFANCNFSM4PX3HEVQ>
.
|
Hi @mobizt , thanks for waiting here is the code. It does not compile (error on the timestamp line) ... as you have seen, I have tried to do it with a FirebaseData too, no luck. probably it's something trivial but I have difficulty understanding the separation of concerns between FirebaseJson objects and FirebaseData ones. Ideally, I would like to create in memory the JSON object, then push it to a /...../clientID/readings path which will contain N (an array) of the objects I am building
|
That is because you use the wrong syntax. The setTimestamp function is not available (not existed) for FirebaseJson object. The data types i.e. bool, int, float, double, string, JSON object and JSON array object are supported with set and add function of FirebaseJson and FirebaseJsonArray. The FirebaseJson is the JSON object (class) that used for JSON data manipulation (create, edit and parsing) The FirebaseJsonData (similar to FirebaseData object) is the class object that holds the parsing result when you want to get or extract the value from specific key in the FirebaseJson object. The Firebase.setTimestamp function is for Firebase class only. This timestamp value was hidden from Firebase web console but you can read its double value (UNIX timestamp value of milliseconds) from specific node with the FirebasegetDouble function as seen in Timestamp.ino example. To check all supported function please see this. If you want to set the timestamp to the JSON object, you just use
Where as xxxxxxxxxxxx is the integer number of timestamp which you need to assign or get it from the system time of the device (NTP server or RTC chip). This is total difference from Firebase.setTimestamp which you don't need to provide the timestamp value to the function, Firebase will be set it for you automatically at the server side. |
Hi @mobizt , I understand a little bit better, and that I had a confusion between client set timestamp and firebase set timestamp. So, what I want to achieve, is to create an array of JSON objects. each of the objects is made like this:
So, I seem to understand that
Thanks |
ok, this is the current version of the code.....
It works. And I also saw that I can construct the object in memory and push it in one go with Firebase.push. But I still need to set the readingsDateTime key/value with the Firebase server value . This bit I do not know how to do in a short way. |
You can't set the server value in to any json data. You need to make a single request for set server value timestamp. Please read the Firebase REST API document. |
Ok, so I need to set it on a different call, then read it and put that
value in the json, right?
…On Tue, Aug 11, 2020, 02:02 mobizt ***@***.***> wrote:
You can't set the server value in to any json data.
You need to make a single request for set server value timestamp.
Please read the Firebase REST API document.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#91 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFKTX2FHM2KJSTE3LZ7WYTSACC77ANCNFSM4PX3HEVQ>
.
|
Yes. |
The point is, I do not trust the client devices to give me an accurate and
consistent timestamp. This is why I need to find the equivalent of
Firebase::serverTimestamp (if I recall correctly)
EDIT: of this: firebase.database.ServerValue.TIMESTAMP
On Tue, Aug 11, 2020, 02:04 Massimiliano Bariola <m.bariola@gmail.com>
wrote:
… Ok, so I need to set it on a different call, then read it and put that
value in the json, right?
On Tue, Aug 11, 2020, 02:02 mobizt ***@***.***> wrote:
> You can't set the server value in to any json data.
>
> You need to make a single request for set server value timestamp.
>
> Please read the Firebase REST API document.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#91 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABFKTX2FHM2KJSTE3LZ7WYTSACC77ANCNFSM4PX3HEVQ>
> .
>
|
Ok got it. Thanks!
…On Tue, Aug 11, 2020, 02:05 mobizt ***@***.***> wrote:
Yes.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#91 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFKTX6UIT7WMDB5UX747MDSACDNRANCNFSM4PX3HEVQ>
.
|
For server timestamp, the pay load for the request sent to server must be {".sv":"timestamp"} which should not mixed by any user data. |
I am unsure how to use it. Can you provide a line of code passing that
payload?
Alternatively, does Firebase provide a current timestamp that can be read?
(so that I can skip the "setting the timestamp first" part)? Thanks
…On Tue, Aug 11, 2020, 02:10 mobizt ***@***.***> wrote:
For server timestamp, the pay load for the request sent to server must be
*{".sv":"timestamp"}* which should not mixed by any user data.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#91 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFKTX3NJDMUKOJXA66LGELSACD6XANCNFSM4PX3HEVQ>
.
|
No, I only explain what the server timestamp payload (data that being send to server) should be. When you call the Firebasse.setTimestamp function, the library sent this JSON {".sv":"timestamp"} to Firebase server. |
Hi @mobizt , yes that I understood, but had problems to find out how to make sure to pass that special value at the time of object creation. So I experimented a little with what you said, and found a way. I don't know if it's the most elegant one, but it works and it does all with just one call to firebase
Thanks for your input, it nudged me in the right direction. Cheers! |
You can trust the device time as you can get the time from NTP server that give you the same and accurate timestamp for every client device. The millisecond timestamp is only the second timestamp multiplied by 1000. Some Time library provides more precision timestamp from NTP server with the request/response time delay compensation. |
Unfortunately I am developing a battery powered device and thus it is most of the time in super low power mode and offline. it comes online only to send data in bursts, then goes offline again. Any extra call shortens battery life. But I found a way that works (see comment above)! thanks for the info |
Hi there @mobizt
I need to save a moderately complex JSON object, which has an array of integers, some integers, and some strings. By following your examples, I am able to set a JSON object and commit it in one go.
This JSON object also has a timestamp, but I was not able to set it in the json object to commit. Only to do it in 2 steps: first the object without the timestamp, then fetching the object key and save the timestamp in it by giving a path within the object I just created.
Is there a way to do it in just one step?
to clarify I need to save something like this at /clients/config/[clientName]/current and would like it to happen in one go
Many thanks
The text was updated successfully, but these errors were encountered: