Time Stamp and Influx DB problem

You said:

Can you please provide an example message that does not work. Why is that so difficult? There are a lot of different issues discussed earlier and I want to make sure I understand exactly what you think should work.

The OP was trying to send this to the "influx out" node :

[
   {
       "time":1564134384,
       "Concentration_C02":4080,
       "Temperature":40.8,
       "Relative_Humidity":102,
       "Frame_Index":2
   },
   {
       "Device":"test_datalog",
       "Type_Produit":"Insafe_Carbon_Sigfox",
       "Type_Message":"Datalog"
   }
]

That's an array of objects.
It should have been an array of array(s) of objects :

[
   [
       {
           "time":1564134384,
           "Concentration_C02":4080,
           "Temperature":40.8,
           "Relative_Humidity":102,
           "Frame_Index":2
   },
       {
           "Device":"test_datalog",
           "Type_Produit":"Insafe_Carbon_Sigfox",
           "Type_Message":"Datalog"
   }
   ]
]

The discussion around the time format issue is not relevant : if the node is configured to handle "ms precision" (actually resolution) it works perfectly with the timestamp provided.

The first one works perfectly for me

image

[{"id":"716392eedd5af1a4","type":"influxdb out","z":"bdd7be38.d3b55","influxdb":"b0493664.35a528","name":"","measurement":"arraytest","precision":"","retentionPolicy":"","database":"database","precisionV18FluxV20":"ms","retentionPolicyV18Flux":"","org":"organisation","bucket":"bucket","x":550,"y":1860,"wires":[]},{"id":"e22c8b83bffe33aa","type":"inject","z":"bdd7be38.d3b55","name":"Write it","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":1860,"wires":[["a39499e7aa7f037c"]]},{"id":"a39499e7aa7f037c","type":"function","z":"bdd7be38.d3b55","name":"Build payload","func":"msg.payload = [\n    {\n        \"time\": 1564134384,\n        \"Concentration_C02\": 4080,\n        \"Temperature\": 40.8,\n        \"Relative_Humidity\": 102,\n        \"Frame_Index\": 2\n    },\n    {\n        \"Device\": \"test_datalog\",\n        \"Type_Produit\": \"Insafe_Carbon_Sigfox\",\n        \"Type_Message\": \"Datalog\"\n    }\n]\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":1860,"wires":[["716392eedd5af1a4"]]},{"id":"b0493664.35a528","type":"influxdb","hostname":"localhost","port":"8086","protocol":"http","database":"Testing","name":"","usetls":false,"tls":"ced18875.cf10b8","influxdbVersion":"1.x","url":"http://localhost:8086","rejectUnauthorized":true},{"id":"ced18875.cf10b8","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":true}]
> select * from arraytest
name: arraytest
time       Concentration_C02 Device       Frame_Index Relative_Humidity Temperature Type_Message Type_Produit
----       ----------------- ------       ----------- ----------------- ----------- ------------ ------------
1564134384 4080              test_datalog 2           102               40.8        Datalog      Insafe_Carbon_Sigfox

[Edit] Of course that is a silly time value, but if you set the precision to seconds in the influx node then it is good.

@pagaille are you happy that this does indeed work? If so I will close this thread.

Didn’t had time yet to check what was wrong with my setup. Will confirm.

Make sure you are using the latest versions of node red and the influx node. A lot has changed since the start of this thread.

I write the data points (measurements) along with timestamps into influxdb on node-red, but unfortunately my data points are stored with host's timestamps only!

Here is my function to add timestamp to data:

timestamp= new Date().getTime() * 1e6;

topic_array = ['NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProduction"',
                'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionStart"',
                'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionEnd"'
				];
				
meas_array = ['ExGrafanaDbMachineState1DataModeTimeProduction',
                'ExGrafanaDbMachineState1DataModeTimeProductionStart',
				'ExGrafanaDbMachineState1DataModeTimeProductionEnd'
				];



function append_array(topic_array, meas_array, timestamp){
    var totalCount = topic_array.length ;
    //const appended_array = [];
    //append dicts to array
    for (var i = 0; i < totalCount; i++){
    	msg= {topic: topic_array[i],measurement: meas_array[i], timestamp: timestamp};
    	node.send(msg);
        }
    //return msg;
}

append_array(topic_array, meas_array, timestamp) ;

Node-Red Debug Logs:

The Data explored using Flux shows different timestamp than what is written from Node-Red:

Why is the timestamp not updated (different than in Node-Red) in the InfluxDB? What is wrong in here?

Please help, each suggestions/tips are very much appreciated!

Regards,
Mukara

You are using timestamp= new Date().getTime() * 1e6 so it is using the host time. You have shown us the timestamps in the database but haven't told us what timestamps you expect to see.

When pasting terminal output in future please use the </> button at the top of the forum entry window and paste the terminal output there.

I expect the timestamp printed on node-red debug log & influxdb should be same/identical (see both yellow marked texts)! But It is somehow varied what could be the problem here! See the above highlighted sections, the timestamp marked in nodered is different from timestamp marked in influxdb console!

Regards.
Mukara

Normally with the influxdb out node the time written is the current system time. If you want to pass in a time then look at the terminal output you posted and you will see that the field containing the timestamp is actually called time so if you want to write time and value then the payload must be something like
{time: 1655... , value: "2022-06-14 14:00:51"}

I used the key 'time' instead of 'timestamp' as you mentioned, now the flow doesn't even write to influxdb I guess:

Function Node (HG6_ExGrafanaDb_MS1_variables):

timestamp = new Date().getTime() *1e6;

function append_array(topic_array, meas_array, timestamp){
    var totalCount = topic_array.length;
    const appended_array = [];
    //append dicts to array
    for (var i = 0; i < totalCount; i++){
    	appended_array.push({topic: topic_array[i],measurement: meas_array[i], time: timestamp});
        }
        return appended_array;
}

const topic_array = [
'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."HeartBeatAlpma"',
'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."MachineNbr"',
'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."MachineType"',
'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."PositionNbr"',
'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."StateCurrent"',
'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."UnitModeCurrent"',
'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProduction"',
'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionStart"',
'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionEnd"',
.
.
.

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Interfaces"."NameOut"',
'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Interfaces"."NameOut2"'
];
				
const meas_array = [
'ExGrafanaDbMachineState1DataMachineDataHeartBeatAlpma',
'ExGrafanaDbMachineState1DataMachineDataMachineNbr',
'ExGrafanaDbMachineState1DataMachineDataMachineType',
'ExGrafanaDbMachineState1DataMachineDataPositionNbr',
'ExGrafanaDbMachineState1DataMachineDataStateCurrent',
'ExGrafanaDbMachineState1DataMachineDataUnitModeCurrent',
'ExGrafanaDbMachineState1DataModeTimeProduction',
'ExGrafanaDbMachineState1DataModeTimeProductionStart',
'ExGrafanaDbMachineState1DataModeTimeProductionEnd',
.
.
.

'ExGrafanaDbMachineState1DataInterfacesNameOut',
'ExGrafanaDbMachineState1DataInterfacesNameOut2'
];

msg = append_array(topic_array, meas_array, timestamp);

return [msg];

Node Flow:

InfluxDB Query result (see the first line which is the most recent data point/measurement):
The data point is not stored in the influxdb after writing the timestamp to the key 'time' !

> select * from ExGrafanaDbMachineState1DataModeTimeProductionEnd order by time desc limit 10
name: ExGrafanaDbMachineState1DataModeTimeProductionEnd
time                value
----                -----

1655220187864937034 2022-06-14 17:23:07
1655220186875425563 2022-06-14 17:23:06
1655220185965875789 2022-06-14 17:23:05
1655220184063970641 2022-06-14 17:23:04
1655220183097884693 2022-06-14 17:23:03
1655220182225878301 2022-06-14 17:23:02
1655220181257648533 2022-06-14 17:23:01
1655220180348378913 2022-06-14 17:23:00
1655220179432214458 2022-06-14 17:22:59
1655220178449215850 2022-06-14 17:22:58
> ^C

What could be wrong here?

PS: even that key 'timestamp' doesn't work anymore, meaning no data with the (specific/modified) timestamp is stored to influxdb!

Regards,
Mukara

The payload shown in your debug in the marked section does not look like the payload I suggested.

You may also find this online timestamp convertor useful. If you paste in the timestamp from influx it will tell you what that is in human readable form.

I guess its in the format as you suggested, instead of value its written as payload!

Node-Red Debug Output (as time & timestamp):

**Timestamp:**
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMa…", timestamp: 1655283227811000000, _msgid: "a1e36f298295c93b", payload: "HG6" … }
15.6.2022, 10:53:46node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."MachineType" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMa…", timestamp: 1655283227811000000, _msgid: "a1e36f298295c93b", payload: "TurningLine1" … }
15.6.2022, 10:53:46node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."PositionNbr" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMa…", timestamp: 1655283227811000000, _msgid: "a1e36f298295c93b", payload: "" … }
15.6.2022, 10:53:46node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."StateCurrent" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMa…", timestamp: 1655283227811000000, _msgid: "a1e36f298295c93b", payload: 0 … }
15.6.2022, 10:53:46node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."UnitModeCurrent" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMa…", timestamp: 1655283227811000000, _msgid: "a1e36f298295c93b", payload: 0 … }
15.6.2022, 10:53:46node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProduction" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMo…", timestamp: 1655283227811000000, _msgid: "a1e36f298295c93b", payload: 0 … }
15.6.2022, 10:53:46node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionStart" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMo…", timestamp: 1655283227811000000, _msgid: "a1e36f298295c93b", payload: "2090-01-01 00:00:00" … }
15.6.2022, 10:53:46node: HG6_grafana_msg
NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionEnd" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMo…", timestamp: 1655283227811000000, _msgid: "a1e36f298295c93b", payload: "2090-01-01 00:00:00" … }

**Time:**
15.6.2022, 11:39:21node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."HeartBeatAlpma" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMa…", time: 1655285962901000000, _msgid: "c82aefc4024b8f08", payload: 184 … }
15.6.2022, 11:39:21node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."MachineNbr" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMa…", time: 1655285962901000000, _msgid: "c82aefc4024b8f08", payload: "HG6" … }
15.6.2022, 11:39:21node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."MachineType" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMa…", time: 1655285962901000000, _msgid: "c82aefc4024b8f08", payload: "TurningLine1" … }
15.6.2022, 11:39:21node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."PositionNbr" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMa…", time: 1655285962901000000, _msgid: "c82aefc4024b8f08", payload: "" … }
15.6.2022, 11:39:21node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."StateCurrent" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMa…", time: 1655285962901000000, _msgid: "c82aefc4024b8f08", payload: 0 … }
15.6.2022, 11:39:21node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."UnitModeCurrent" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMa…", time: 1655285962901000000, _msgid: "c82aefc4024b8f08", payload: 0 … }
15.6.2022, 11:39:21node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProduction" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMo…", time: 1655285962901000000, _msgid: "c82aefc4024b8f08", payload: 0 … }
15.6.2022, 11:39:21node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionStart" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMo…", time: 1655285962901000000, _msgid: "c82aefc4024b8f08", payload: "2090-01-01 00:00:00" … }
15.6.2022, 11:39:21node: HG6_grafana_msgNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionEnd" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataMo…", time: 1655285962901000000, _msgid: "c82aefc4024b8f08", payload: "2090-01-01 00:00:00" … }
15.6.2022, 11:39:21node: HG6_grafana_msg
NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."State"."TimeStopped" : msg : Object
{ topic: "NodeID;ns=3;s="ExGrafanaDb"."M…", measurement: "ExGrafanaDbMachineState1DataSt…", time: 1655285962901000000, _msgid: "c82aefc4024b8f08", payload: 0 … }

Function tested on Visual Studio Code (.js):
This function assembles the Message Object which has to be queried and added to payloads pulled from OPC Client!

timestamp = new Date().getTime() *1e6;

function append_array(topic_array, meas_array, timestamp){

var totalCount = topic_array.length;

const appended_array = [];

//append dicts to array

for (var i = 0; i < totalCount; i++){

appended_array.push({topic: topic_array[i],measurement: meas_array[i], timestamp: timestamp});

//node.send(appended_array);

}

return appended_array;

}

const topic_array = [

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."HeartBeatAlpma"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."MachineNbr"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."MachineType"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."PositionNbr"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."StateCurrent"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."MachineData"."UnitModeCurrent"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProduction"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionStart"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionEnd"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."State"."TimeStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."State"."CountUndefined"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."State"."TimeUndefined"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."State"."TimeIdle"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."State"."TimeExecute"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."State"."CountIdle"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."State"."CountExecute"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."State"."CountStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."PerformanceInformation"."CountItemOutType"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."PerformanceInformation"."CountItemInType"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."PerformanceInformation"."CountItemOut"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."PerformanceInformation"."CountItemIn"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."In"."CountStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."Error"."TimeStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."Error"."Stopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."Error"."CountStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."Safety"."TimeStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."User"."CountStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."User"."Stopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."User"."TimeStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."In"."Stopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."In"."TimeStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."In2"."CountStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."In2"."Stopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."In2"."TimeStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."Out"."CountStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."Out"."Stopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."Out"."TimeStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."Out2"."CountStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."Out2"."Stopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."Out2"."TimeStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."Safety"."CountStopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."StopInformation"."Safety"."Stopped"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Interfaces"."NameIn"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Interfaces"."NameIn2"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Interfaces"."NameOut"',

'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Interfaces"."NameOut2"'

];

const meas_array = [

'ExGrafanaDbMachineState1DataMachineDataHeartBeatAlpma',

'ExGrafanaDbMachineState1DataMachineDataMachineNbr',

'ExGrafanaDbMachineState1DataMachineDataMachineType',

'ExGrafanaDbMachineState1DataMachineDataPositionNbr',

'ExGrafanaDbMachineState1DataMachineDataStateCurrent',

'ExGrafanaDbMachineState1DataMachineDataUnitModeCurrent',

'ExGrafanaDbMachineState1DataModeTimeProduction',

'ExGrafanaDbMachineState1DataModeTimeProductionStart',

'ExGrafanaDbMachineState1DataModeTimeProductionEnd',

'ExGrafanaDbMachineState1DataStateTimeStopped',

'ExGrafanaDbMachineState1DataStateCountUndefined',

'ExGrafanaDbMachineState1DataStateTimeUndefined',

'ExGrafanaDbMachineState1DataStateTimeIdle',

'ExGrafanaDbMachineState1DataStateTimeExecute',

'ExGrafanaDbMachineState1DataStateCountIdle',

'ExGrafanaDbMachineState1DataStateCountExecute',

'ExGrafanaDbMachineState1DataStateCountStopped',

'ExGrafanaDbMachineState1DataPerformanceInformationCountItemOutType',

'ExGrafanaDbMachineState1DataPerformanceInformationCountItemInType',

'ExGrafanaDbMachineState1DataPerformanceInformationCountItemOut',

'ExGrafanaDbMachineState1DataPerformanceInformationCountItemIn',

'ExGrafanaDbMachineState1DataStopInformationInCountStopped',

'ExGrafanaDbMachineState1DataStopInformationErrorTimeStopped',

'ExGrafanaDbMachineState1DataStopInformationErrorStopped',

'ExGrafanaDbMachineState1DataStopInformationErrorCountStopped',

'ExGrafanaDbMachineState1DataStopInformationSafetyTimeStopped',

'ExGrafanaDbMachineState1DataStopInformationUserCountStopped',

'ExGrafanaDbMachineState1DataStopInformationUserStopped',

'ExGrafanaDbMachineState1DataStopInformationUserTimeStopped',

'ExGrafanaDbMachineState1DataStopInformationInStopped',

'ExGrafanaDbMachineState1DataStopInformationInTimeStopped',

'ExGrafanaDbMachineState1DataStopInformationIn2CountStopped',

'ExGrafanaDbMachineState1DataStopInformationIn2Stopped',

'ExGrafanaDbMachineState1DataStopInformationIn2TimeStopped',

'ExGrafanaDbMachineState1DataStopInformationOutCountStopped',

'ExGrafanaDbMachineState1DataStopInformationOutStopped',

'ExGrafanaDbMachineState1DataStopInformationOutTimeStopped',

'ExGrafanaDbMachineState1DataStopInformationOut2CountStopped',

'ExGrafanaDbMachineState1DataStopInformationOut2Stopped',

'ExGrafanaDbMachineState1DataStopInformationOut2TimeStopped',

'ExGrafanaDbMachineState1DataStopInformationSafetyCountStopped',

'ExGrafanaDbMachineState1DataStopInformationSafetyStopped',

'ExGrafanaDbMachineState1DataInterfacesNameIn',

'ExGrafanaDbMachineState1DataInterfacesNameIn2',

'ExGrafanaDbMachineState1DataInterfacesNameOut',

'ExGrafanaDbMachineState1DataInterfacesNameOut2'

];

msg = append_array(topic_array, meas_array, timestamp);

console.log('msg:', msg);

Output format printed on VSC (as suggested by you):

This below formats pulls the payload from OPC client node and those payloads are joined with these msg objects and stored in InfluxDB as shown in Node-Red Flow above!

msg: [
.
.
},
  {
    topic: 'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProduction"',
    measurement: 'ExGrafanaDbMachineState1DataModeTimeProduction',
    timestamp: 1655285210841000000
  },
  {
    topic: 'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionStart"',
    measurement: 'ExGrafanaDbMachineState1DataModeTimeProductionStart',
    timestamp: 1655285210841000000
  },
  {
    topic: 'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionEnd"',
    measurement: 'ExGrafanaDbMachineState1DataModeTimeProductionEnd',
    timestamp: 1655285210841000000
  },
.
.
.

  {
    topic: 'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Interfaces"."NameOut"',
    measurement: 'ExGrafanaDbMachineState1DataInterfacesNameOut',
    timestamp: 1655285210841000000
  },
  {
    topic: 'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Interfaces"."NameOut2"',
    measurement: 'ExGrafanaDbMachineState1DataInterfacesNameOut2',
    timestamp: 1655285210841000000
  }
]

[Done] exited with code=0 in 0.124 seconds

interesting information

No it isn't. For the format I suggested then in the debug output you should see something like
payload: {time: 1655283227811000000, value: "2090-01-01 00:00:00"}

The help text for the influxdb node explains the different formats available. If the payload just contains a string then that is written as the field value and time is set to the current system time.

Edit:
At least that is my understanding.

Yes, I agree the format is not yet correct!

I created a simple flow with static message (works) & with dynamic payload read from OPC server (doesn't work yet)!

I could see the difference in formats which works & which doesn't! I am still thinking how could I make it work! Please help if anybody knows how to resolve this formating issue!

Node-Red flow (working part):
grafik

Node-Red flow (not working part):
The Influx Batch Node throws this below error:
"TypeError: points.forEach is not a function"
grafik

InfluxDB Output verification:

root@influxdb1:/# influx
Connected to http://localhost:8086 version 1.8.6
InfluxDB shell version: 1.8.6
> use test_db
Using database test_db
> select * from weather_sensor
name: weather_sensor
time                humidity light location temp
----                -------- ----- -------- ----
1655291375494000000 51       678   garden   5.5
1655291541567000000 51       678   garden   5.5
1655291605773000000 51       678   garden   5.5
1655291735427749899 51       678   garden   5.5
1655291803727000000 51       678   garden   5.5
1655291827052000000 51       678   garden   5.5
1655291904931000000 51       678   garden   5.5
1655293047730000000 51       678   garden   5.5
1655293048151000000 51       678   garden   5.5
1655293787154000000 51       678   garden   5.5
1655296125339000000 51       678   garden   5.5
1655296161886000000 51       678   garden   5.5
1655297268880000000 51       678   garden   5.5
1655297349698000000 51       678   garden   5.5
1655297454578000000 51       678   garden   5.5
1655297528697000000 51       678   garden   5.5
1655297664220536413 51       678   garden   5.5
1655297807625525134 51       678   garden   5.5
1655297863225884501 51       678   garden1  5.5
**1655297928998000000 51       678   garden1  5.5**  // look at this timestamp, identical to node-red timestamp

Each and every help will be much appreciated :slight_smile: !

PFA node-red flow (.JSON)
flows.json (6.1 KB)

Regards,
Mukara

Are you using the Batch node? I assumed you were using the normal influx out node.

If so then we have to start looking at the problem again, look at the help text for the node to see how it says to format the data.

1 Like

I was trying to use the influxdb batch node, because if I use InfluxDB Out node, the timestamp is not written to the InfluxDB! Only in Batch Node I could write the timestamp along with the payload!

Debug/Output logs:

InfluxDB Out Node format (doesn't save the timestamp):

20.6.2022, 10:01:19node: HG6_grafana_msg

NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProduction" : msg : Object

object

topic: "NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProduction""

measurement: "ExGrafanaDbMachineState1DataModeTimeProduction"

> timestamp: 1655712082942000000 (not saved to db with this sp. timestamp)

_msgid: "1648b7af26e5bb44"

payload: 13482598

statusCode: object

serverTimestamp: "2022-06-20T08:01:23.023Z"

sourceTimestamp: "2022-06-20T08:01:23.023Z"

InfluxDB Batch Node Format (saves only static message to influxdb, dynamic msg from opc server is not in right format yet!):

20.6.2022, 10:09:01node: Debug_AboveNodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionEnd" : msg : Object

object

topic: "NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionEnd""

measurement: "ExGrafanaDbMachineState1DataModeTimeProductionEnd"

_msgid: "ea4fa5c777c5aec9"

payload: "2022-06-20 10:09:04"

statusCode: object

value: 0

serverTimestamp: "2022-06-20T08:09:04.661Z"

sourceTimestamp: "2022-06-20T08:09:04.661Z"

> timestamp: 1655712544621000000 (not saved to db at all)

20.6.2022, 10:09:16node: Debug_Below

msg : Object

object

_msgid: "3f43a196c0366c9d"

payload: array[2]

0: object

measurement: "weather_sensor"

fields: object

temp: 5.5

light: 678

humidity: 51

tags: object

> timestamp: 1655712559958000000 (saved to db with this sp. timestamp)

1: object

measurement: "alarm_sensor"

fields: object

tags: object

> timestamp: 1655712559958000000 (saved to db with this sp. timestamp)

topic: ""

Does anybody know how to format the payload correctly, so that the Influx batch node accepts and stores the data/measurement with specified timestamp!

Here is my function to concatenate/format topic, measurement & timestamp (so far):

timestamp = new Date().getTime() *1e6;

function append_array(topic_array, meas_array, timestamp){
    var totalCount = topic_array.length;
    const appended_array = [];
    //append dicts to array
    for (var i = 0; i < totalCount; i++){
    	appended_array.push({topic: topic_array[i],measurement: meas_array[i], timestamp:timestamp});
        }
        return appended_array;
}

const topic_array = [
'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProduction"',
'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionStart"',
'NodeID;ns=3;s="ExGrafanaDb"."MachineState1"."Data"."Mode"."TimeProductionEnd"',
];
				
const meas_array = [
'ExGrafanaDbMachineState1DataModeTimeProduction',
'ExGrafanaDbMachineState1DataModeTimeProductionStart',
'ExGrafanaDbMachineState1DataModeTimeProductionEnd',

];

msg = append_array(topic_array, meas_array, timestamp);
return [msg];

Any suggestions are very welcome!

Regards,
Mukara

As I said you need to look at the docs for the node and see what it requires. Look at node-red-contrib-influxdb (node) - Node-RED (that link has been already been posted earlier in the thread). Look at the section on the batch node and it shows you how it should be formatted and gives some example flows that you can import.