mobizt / Firebase-Arduino-WiFiNINA

Firebase Arduino Library for ARM/AVR WIFI Dev Boards based on WiFiNINA
MIT License
65 stars 12 forks source link

How to read Firebase timestamps #27

Closed matzesoft closed 3 years ago

matzesoft commented 3 years ago

Hi. I am currently trying to read timestamps stored in Firebase on my Arduino Nano 33 IoT. However timestamps are very high numbers. The current timestamp I am writing this message for example is: 1634573019348.

Using the getInt() function doesn't work because the return value only reaches up to 2147483647, which is the highest a long variable can get. Using unsigned long should work, however this data type as it looks to me is not supported by the library.

Is there any other way to read timestamps? Thanks for your help :)

mobizt commented 3 years ago

The library was updated to v1.2.0 which supports double and 64-bit signed/unsigned integer.

https://github.com/mobizt/Firebase-Arduino-WiFiNINA/blob/979cc49994940521bb06a070e260c741338bfc2b/examples/Basic/Basic.ino#L63-L70

fbdo.int64Data() returns long long data type fbdo.uint64Data() returns unsigned long long data type

The timestamp in milliseconds can't store in unsigned long (32-bit) unless unsigned long long (64-bit) or long long (64-bit).

mobizt commented 3 years ago

To get 64-bit number, you can use getInt.

matzesoft commented 3 years ago

Oups, yeah your right unsigned long is still to small. But thanks for updating the library. Got it working now.