Hi folks,
I've been programming a simple flow for regularly storing temperature forecasts to Influxdb. The flow is basically as follows: 1. Get the forecast temperature for the next 24+ hours with an hourly timestamp from a REST API, 2. Format the points so that they can be fed to Influxdb 3. Write to Influxdb with a precision of a millisecond. This part works OK.
Now, the problem is that when I look at the stored values from Influxdb dashboard, the timestamp (_time field in influxdb) is not on the hour, it's something past. When I first started experimenting with this, all timestamps were 10 minutes past the hour. When I tested it further, at some point all written timestamps were 2 minutes 50 seconds past the hour. And now, it seems to have more of an arbitrary timestamp, a few minutes and seconds past the hour.
What could be the cause of this and is there any way to fix it? Is it a problem with Influxdb dashboard itself?
I'm running Node-Red v. 3.0.2 and Influxdb 2.4.0, both on their own servers.
Here's a sample flow for demo purposes. I have excluded the REST API stuff, and added a few example values/timestamps available in simple tables in the same format they arrive from the REST API.
[{"id":"86657d4a52a58e19","type":"inject","z":"07cd862b6e42e2a6","name":"Start","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":680,"wires":[["f1ba83fec0487321"]]},{"id":"f1ba83fec0487321","type":"function","z":"07cd862b6e42e2a6","name":"Build Influxdb data structure","func":"var payloadArray = [];\n\n// Set hourly timestamps\nvar timeISO = [\n \"2022-10-12T13:00:00Z\",\n \"2022-10-12T14:00:00Z\",\n \"2022-10-12T15:00:00Z\",\n \"2022-10-12T16:00:00Z\",\n \"2022-10-12T17:00:00Z\",\n ];\n\n// Set temperatures\nvar temperatures = [\n \"8.87\",\n \"9.12\",\n \"9.2\",\n \"9.86\",\n \"10.16\"\n ]\n\n\nfor ( var i = 0; i < 5; i++ )\n{\n// Set UNIX timestamp in milliseconds\n var timeUNIX = new Date( timeISO[ i ] ).getTime();\n\n// Change temperature to float with one decimal \n var forecastTemperature = Number( temperatures[ i ]);\n forecastTemperature = Math.round( forecastTemperature * 10 ) / 10;\n\n// Construct one influxdb point\n var pointArray = [\n { \n \"time\": timeUNIX,\n \"tempForecast\": forecastTemperature\n }\n ];\n \n payloadArray.push( pointArray );\n}\n\nmsg.payload = payloadArray;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":680,"wires":[["66d46c36639a1018","c58d644ae3528f82"]]},{"id":"66d46c36639a1018","type":"debug","z":"07cd862b6e42e2a6","name":"Debug payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":700,"y":720,"wires":[]},{"id":"c58d644ae3528f82","type":"influxdb out","z":"07cd862b6e42e2a6","influxdb":"42cad80c275bcd67","name":"Write to Influxdb","measurement":"temperature","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"Koti","bucket":"Weather","x":700,"y":640,"wires":[]},{"id":"42cad80c275bcd67","type":"influxdb","hostname":"influxdbsrv","port":"8086","protocol":"http","database":"database","name":"Influxdb server","usetls":false,"tls":"","influxdbVersion":"2.0","url":"http://influxdbsrv:8086","rejectUnauthorized":true,"credentials":{}}]
A Screenshot from Influxdb dashboard showing the funny timestamps after flow execution:
What if the values are queried?
If I make a query from a influxdb In node, say the following:
from( bucket: "Weather" )
|> range( start: 2022-10-12T13:01:00Z, stop: 2022-10-12T17:01:00Z)
According to the timestamps shown in Influxdb dashboard, it should return the first four values. But instead, it returns the last four, which is basically right from the use case perspective (hours 14, 15, 16 and 17 included), but doesn't work well from the development perspective, if I want to check a graph or the values from Influxdb dashboard.