Hello, I have a node-red-contrib-file-function which allows me to create a function on nodered outside the nodered itself. My application is simple, I just read data from my influxDB and do some calculations from the data acquired and writes it to influx again (different measurement), however, from time to time (at random interval), I got this error: Cannot read property of '1' undefined.
This is actually my code, on the function "getVal" , that is where my array with index of "1" having an issue.
> //Don't Edit ====================================================================
var res = msg.payload.results
var numVal = res[0].series[0].values
var i
m_out = []
//================================================================================
// EDIT THIS FOR YOUR CALCULATION ==============================================================
//Measurement is the Tagname
//value: is your calculation formula
//Description is the description of your Tag
for (i=0;i<=numVal.length-1;i++){
var script = {
payload: {
measurement: "CAL3",
fields:{
value: Math.sqrt(getval("Counter",i))
},
timestamp: getStamp(i)
}
}
m_out.push(script)
}
//==============================================================================================
//DON'T EDIT ==================================================================================
function getval(tagname,j){
for(var x in res){
if (res[x].series[0].name == tagname){
return res[x].series[0].values[j][1] -- > This is where the error is.
}
}
}
function getStamp(j){
if (j == numVal.length -1) {
global.set("startTime",res[0].series[0].values[j][0])
}
return new Date(res[0].series[0].values[j][0]).getTime() * 1000000
}
//================================================================================================
return [m_out]
''
Now my question is what could be the possible reason that I am getting this error?
The node before this node is simply getting the database from influxDB and the results is stored in "res" variable which can be seen in my code above. This is what the the database read looks like:
Hopefully you can help me. THank you.
Regards,
Henjoe