Hi all,
I want to retrieve a selection of data from a database managed by InfluxDB. The goal is to give a base date and add an interval (or subtract an interval ), to extract the data from this selection.
Here is the flow:
[
{
"id": "12065710fa4a2085",
"type": "debug",
"z": "22872ad18901ecfc",
"name": "out2",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 850,
"y": 4180,
"wires": []
},
{
"id": "3bd10a6e410ab1c9",
"type": "function",
"z": "22872ad18901ecfc",
"name": "Query data",
"func": "//for the example :\nflow.set(\"dataType\",\"phMesure\")\nflow.set(\"interval\", 3600000)//=1h\nflow.set(\"debut\", msg.payload)\nflow.set(\"fin\", msg.payload)\n\n//start program :\nlet dataType = flow.get(\"dataType\")\nlet finString\nlet debutString\nlet interval =flow.get(\"interval\")//3600000 //=1h\nlet debut = flow.get(\"debut\")//\nlet fin = flow.get(\"fin\")//\n//node.warn(debutString);\n\n//select data range\nif(msg.topic ==\"debut\"){//From Date + interval\n finString = millisToDate(debut+interval)//----------> Fonction\n debutString = millisToDate(debut)\n}\nif (msg.topic == \"fin\") {//From Date - interval\n debutString= millisToDate(fin - interval)//----------> Fonction\n finString = millisToDate(fin)\n}\n//for DEBUG :\nmsg.interval=interval\nmsg.debutString = debutString\nmsg.finString = finString\n\n//Send To InfluxDB node:\nmsg.query = `from(bucket: \"rlinkBucket\")\n |> range(start:`+ debutString + `,stop:` + finString + `)\n |> filter(fn: (r) => r[\"_measurement\"] == \"COMBO\")\n |> filter(fn: (r) => r[\"_field\"] == \"`+ dataType + `\")`;\n\nreturn msg;\n/* Tx msg.\npayload: 2023-03-20T11:08:33.838Z\ntopic: \"debut\"\ninterval: 3600000\ndebutString: \"2023-03-20T11:08:33.838Z\"\nfinString: \"2023-03-20T12:08:33.838Z\"\n*/\n/*Tx: msg.query\nfrom(bucket: \"rlinkBucket\")\n |> range(\n start:Mon Mar 20 2023 12:08:33 GMT+0100 (Central European Standard Time),\n stop:Mon Mar 20 2023 13:08:33 GMT+0100 (Central European Standard Time))\n |> filter(fn: (r) => r[\"_measurement\"] == \"COMBO\")\n |> filter(fn: (r) => r[\"_field\"] == \"phMesure\")\n*/\n\n\n////////// FONCTION ///////////\nfunction millisToDate(millis){\n let d = new Date(0);\n d.setUTCMilliseconds(millis);\n return d;\n}\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 600,
"y": 4180,
"wires": [
[
"12065710fa4a2085"
]
]
},
{
"id": "2a686be307d08281",
"type": "inject",
"z": "22872ad18901ecfc",
"name": "1679230860000 fin",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "fin",
"payload": "1679310513838",
"payloadType": "num",
"x": 330,
"y": 4170,
"wires": [
[
"3bd10a6e410ab1c9"
]
]
},
{
"id": "c82e1995ba61fca2",
"type": "inject",
"z": "22872ad18901ecfc",
"name": "1679230860000 debut",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "debut",
"payload": "1679310513838",
"payloadType": "num",
"x": 340,
"y": 4140,
"wires": [
[
"3bd10a6e410ab1c9"
]
]
}
]
In the msg.debutString "Start:" (same for finString "Stop:") we can see the start date in the form
"2023-03-20T11:08:33.838Z"
but when included in the msg.query it changes to "start:
Mon Tue 20 2023 12:08:33 GMT+0100 (Central European Standard Time)"
(Of course the InfluxDB node gives me an error! )
Why is the String modified? Do you have a solution ? THANKS