I have a python 3.7 based cloud function. I have a value for seconds since epoch. I can add a series of entries for a document as string, integer etc. I can not add a timestamp though.
Here is a simple code snippet.
db = firestore.Client(project=project_id)
# the event dictionary already has some values in it. Add a timestamp.
#
# This is a reference to javascript api. Oddly enough this page does not have
# python listed.
# https://firebase.google.com/docs/reference/js/firebase.firestore.Timestamp
#
# This will add a timestamp as a string value.
event['mqtt_timestamp_rfc3339'] = mqtt_timestamp_rfc3339 # add the timestamp as a string
# this adds a the value as a number of seconds since epoch
event['timestamp_secs'] = mqtt_timestamp # add the timestamp as timestamp class
# This fails.
# firestore.types.Value.timestamp_value(seconds=mqtt_timestamp.timestamp())
# This actually updates the collection
doc_ref = db.collection(u'sensor-data').add(event)
The only thing I have seen so far from the example code is adding a timestamp which appears to be server time. In this case, I have a device which relays its info to a second device which in turn updates to pub/sub. I don't really care about when the cloud function is called. I want to know when the first device generated the event which could be considerable minutes before.
