Using InfluxDB 1.8 with node red

I am very new to Node-red. I am using node-red version v1.3.5 and Influxdb 1.8.10
I am trying to get data into node red from Influx. I am able to run the following query in node-red function node and it works well:
msg.query='select * from em001'
my measurement name in influx is em001.
now if I want to add WHERE clause, it gets bit complicated.
I tried the following command at influx CLI and it works perfectly fine:
<select * from em001 where type='para1'>
it shows me all the data with tag type of para1.
I added this query to node red function node but it does not work:
msg.query='select * from em001 where type='paral1''
its not possible to use single quotes at 'para1' in the function node. I can use double quotes but these are not accepted by Influxdb and I always get error / empty query.

My flow is as below:

[
{
"id": "614a6e42.9a771",
"type": "influxdb in",
"z": "5e1050a9.7d05e",
"influxdb": "f0eb6285.91715",
"name": "",
"query": "",
"rawOutput": false,
"precision": "",
"retentionPolicy": "",
"org": "organisation",
"x": 620,
"y": 160,
"wires": [
[
"24212ff0.b802b"
]
]
},
{
"id": "1cd9712c.5bba8f",
"type": "inject",
"z": "5e1050a9.7d05e",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 210,
"y": 180,
"wires": [
[
"2c72f17c.662ffe"
]
]
},
{
"id": "2c72f17c.662ffe",
"type": "function",
"z": "5e1050a9.7d05e",
"name": "",
"func": "msg.query = 'select * from em001 where type=para1';\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": ,
"x": 380,
"y": 180,
"wires": [
[
"614a6e42.9a771"
]
]
},
{
"id": "24212ff0.b802b",
"type": "debug",
"z": "5e1050a9.7d05e",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 880,
"y": 180,
"wires":
},
{
"id": "f0eb6285.91715",
"type": "influxdb",
"hostname": "127.0.0.1",
"port": "8086",
"protocol": "http",
"database": "EMS",
"name": "",
"usetls": false,
"tls": "",
"influxdbVersion": "1.x",
"url": "http://localhost:8086",
"rejectUnauthorized": true
}
]

Kindly help me to resolve this issue. Thanks in advance.

Hi @saxenaramesh, I hope you are having fun with Node-Red.

The flow that you posted cannot be imported because you didn't use the "preformatted text" button.
Can you post it again:
Export the flow in Node-Red
Click the preformatted text button </>
Paste your flow over the highlighted text.

If you are new to Node-Red, why are you using an old version? The current version is 2.1.4.

Hi jbudd,

thanks for quick reply. my flow is as below (now with preformatted option)

[
    {
        "id": "614a6e42.9a771",
        "type": "influxdb in",
        "z": "5e1050a9.7d05e",
        "influxdb": "f0eb6285.91715",
        "name": "",
        "query": "",
        "rawOutput": false,
        "precision": "",
        "retentionPolicy": "",
        "org": "organisation",
        "x": 620,
        "y": 160,
        "wires": [
            [
                "24212ff0.b802b"
            ]
        ]
    },
    {
        "id": "1cd9712c.5bba8f",
        "type": "inject",
        "z": "5e1050a9.7d05e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 210,
        "y": 180,
        "wires": [
            [
                "2c72f17c.662ffe"
            ]
        ]
    },
    {
        "id": "2c72f17c.662ffe",
        "type": "function",
        "z": "5e1050a9.7d05e",
        "name": "",
        "func": "msg.query = 'select * from em001 where type=para1';\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 380,
        "y": 180,
        "wires": [
            [
                "614a6e42.9a771"
            ]
        ]
    },
    {
        "id": "24212ff0.b802b",
        "type": "debug",
        "z": "5e1050a9.7d05e",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 880,
        "y": 180,
        "wires": []
    },
    {
        "id": "f0eb6285.91715",
        "type": "influxdb",
        "hostname": "127.0.0.1",
        "port": "8086",
        "protocol": "http",
        "database": "EMS",
        "name": "",
        "usetls": false,
        "tls": "",
        "influxdbVersion": "1.x",
        "url": "http://localhost:8086",
        "rejectUnauthorized": true
    }
]

I hope this is OK this time. I am new to node red and still use 1.3.x. Actually I started learning node red before release of version 2.x and then I did not feel the need to upgrade as I am finding 1.3.x good enough for my learning. I will surely try to upgrade as the time permits.

1 Like

Does it work with this function node?

[
    {
        "id": "2c72f17c.662ffe",
        "type": "function",
        "z": "7ca1b48862231788",
        "name": "",
        "func": "msg.query = \"select * from em001 where type = 'para1' \";\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 310,
        "y": 360,
        "wires": [
            [
                "614a6e42.9a771"
            ]
        ]
    }
]
1 Like

Yes, it works. Thanks a lot for your help. You really made my day.
Now, I am wondering why I did not think that way :wink: :smiley:

God bless you. Wishing you Merry Christmas and a very Happy New Year.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.