# Writing Node Parameters Dynamically

**URL:** https://discourse.nodered.org/t/writing-node-parameters-dynamically/40301
**Category:** General
**Created:** [3 February 2021 11:41 UTC](https://discourse.nodered.org/t/writing-node-parameters-dynamically/40301 "2021-02-03T11:41:21Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![cverster](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cverster/32/35423_2.png) [@cverster](https://discourse.nodered.org/u/cverster)
#### Post date: [3 February 2021 11:41 UTC](https://discourse.nodered.org/t/writing-node-parameters-dynamically/40301/1 "2021-02-03T11:41:21Z")

</div>

Hi all. I'm trying to write multiple values to influx DB through a single node. What confuses me about the **node-red-contrib-influxdb** batch node is that I'm not sure where to specify the database I want to write to, so I'm trying a different method. Here is my example flow where I try to write multiple values to influx using a single output node:

```auto
[
    {
        "id": "e6665605.651228",
        "type": "inject",
        "z": "67579b26.28b6e4",
        "name": "1 minute inject",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 320,
        "y": 180,
        "wires": [
            [
                "90085c22.e39ae"
            ]
        ]
    },
    {
        "id": "90085c22.e39ae",
        "type": "MSSQL",
        "z": "67579b26.28b6e4",
        "mssqlCN": "ee093d52.6f53a",
        "name": "Read from myTable",
        "query": "select top 1 DATEDIFF(s, '1970-01-01 00:00:00', timestamp) as t_date, tag1, tag2, tag3 from [server].database.[dbo].[table]\nwhere not (tag1 is null OR tag2 is null OR tag3 is null)\norder by timestamp desc",
        "outField": "payload",
        "x": 580,
        "y": 180,
        "wires": [
            [
                "5bbe5a5c.451874"
            ]
        ]
    },
    {
        "id": "5bbe5a5c.451874",
        "type": "function",
        "z": "67579b26.28b6e4",
        "name": "Prepare InfluxDB Writes",
        "func": "time = (msg.payload[0].t_date-7200)*1000;\ntag1 = msg.payload[0].tag1;\ntag2 = msg.payload[0].tag2;\ntag3 = msg.payload[0].tag3;\n\nmsg.payload = [\n {\n measurement: \"my_tag1\",\n value: tag1\n },\n {\n measurement: \"my_tag2\",\n value: tag1\n },\n {\n measurement: \"my_tag3\",\n value: tag1\n },\n]\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 850,
        "y": 180,
        "wires": [
            [
                "53977f30.eea18"
            ]
        ]
    },
    {
        "id": "53977f30.eea18",
        "type": "split",
        "z": "67579b26.28b6e4",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "payload",
        "x": 1030,
        "y": 380,
        "wires": [
            [
                "c9f0a383.e9153",
                "5f23740.255ad8c"
            ]
        ]
    },
    {
        "id": "c9f0a383.e9153",
        "type": "debug",
        "z": "67579b26.28b6e4",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1290,
        "y": 440,
        "wires": []
    },
    {
        "id": "5f23740.255ad8c",
        "type": "influxdb out",
        "z": "67579b26.28b6e4",
        "influxdb": "",
        "name": "",
        "measurement": "",
        "precision": "",
        "retentionPolicy": "",
        "database": "mydatabase",
        "precisionV18FluxV20": "ms",
        "retentionPolicyV18Flux": "",
        "org": "organisation",
        "bucket": "bucket",
        "x": 1300,
        "y": 380,
        "wires": []
    },
    {
        "id": "ee093d52.6f53a",
        "type": "MSSQL-CN",
        "tdsVersion": "7_4",
        "name": "My Server",
        "server": "address",
        "port": "",
        "encyption": false,
        "database": "database",
        "useUTC": true,
        "connectTimeout": "15000",
        "requestTimeout": "15000",
        "cancelTimeout": "5000",
        "pool": "5"
    }
]

```

What I want to do, is to set the "measurement" parameter of the influx output node dynamically based on the value of "measurement" in my object that I'm splitting. So it should write all three of my tags to the influxDB database indvidually. Is that possible?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [3 February 2021 11:59 UTC](https://discourse.nodered.org/t/writing-node-parameters-dynamically/40301/2 "2021-02-03T11:59:21Z")

</div>

> [@cverster](#):
>
> I'm not sure where to specify the database

It is in the same place in the Batch nodes as for the Influx Out node, in the Server config

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/8/a8e59e637fd14c8796c425daabddc21500564acc.png)

> [@cverster](#):
>
> So it should write all three of my tags to the influxDB database individually.

In the normal Out node you can certainly set the Measurement property in the message. Is it not working? If not then show us the content of the messages you are sending (use a Debug node set to show Complete Message).

---

<div class="post-metadata">

### Author: ![cverster](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cverster/32/35423_2.png) [@cverster](https://discourse.nodered.org/u/cverster)
#### Post date: [3 February 2021 12:14 UTC](https://discourse.nodered.org/t/writing-node-parameters-dynamically/40301/3 "2021-02-03T12:14:54Z")

</div>

Ah, I'm using 1.8flux. When I try to write using 1.x I get Error: getaddrinfo EAI\_AGAIN http http:80. The normal output node does work, but I need to specify the measurement in the node itself as shown belwo:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e56d36c0cf4f659e759b9e5afdcabb97de1645e.png)

If I don't specify a measurement it gives me an error asking me to specify the measurement. When I try to write using the single output node, I have the following flowing to debug:

```auto
{"measurement":"my_tag1","value":123}
{"measurement":"my_tag2","value":456}
{"measurement":"my_tag3","value":789}

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [3 February 2021 13:37 UTC](https://discourse.nodered.org/t/writing-node-parameters-dynamically/40301/4 "2021-02-03T13:37:23Z")

</div>

Do you want to use Flux? If not then select 1.x type (which includes 1.8 not using Flux).

> [@cverster](#):
>
> `{"measurement":"my_tag1","value":123}`

Is that in msg.payload? I suggested setting the debug node to show Complete Message for a reason - because the measurement should be in `msg.measurement` not `msg.payload.measurement`

Do the three values represent the same thing but associated with something else (my\_tagn)? For example it might be bedroom temperature, office temperature, and temperatures for other rooms. If so then you should send them all to the same measurement (room\_temperatures for example) and use an influx Tag to identify the room. Then in the query you would use `where room = "theroom"` in the query to select the appropriate one.

---

<div class="post-metadata">

### Author: ![cverster](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cverster/32/35423_2.png) [@cverster](https://discourse.nodered.org/u/cverster)
#### Post date: [3 February 2021 14:26 UTC](https://discourse.nodered.org/t/writing-node-parameters-dynamically/40301/5 "2021-02-03T14:26:35Z")

</div>

Thanks, I understand not that I need to write to msg.measurement. Also, I'll change things up to make them all write to the same tag. I now write the following msg object to the influx node:

```auto
measurement = msg.payload.measurement
value = msg.payload.value
time = msg.payload.timestamp

msg = {
    measurement: measurement,
    fields: {
        value: value
    },
    timestamp: time
}

```

I check the object in a debug node and it looks right, like this (this is the entire msg object):

```auto
{"measurement":"my_tag1","fields":{"value":123},"timestamp":1612361772000,"_msgid":"8d4c3793.db22d8"}

```

Now, the influx output nodes give me no errors, but neither does it write the values to the desired measurement. Is there something wrong with my object structure? I've also tried this without the fields object..

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [3 February 2021 15:47 UTC](https://discourse.nodered.org/t/writing-node-parameters-dynamically/40301/6 "2021-02-03T15:47:00Z")

</div>

If you want to specify a timestamp use the batch node.  
However, if you don't need to specify a timestamp then you still haven't got it right.  
From the docs  
" If **msg.payload** is a string, number, or boolean, it will be written as a single value to the specified measurement (called _value_ )."

So to simple write a value to measurement the message should be  
`{measurement: "my_tag1", payload: 123}`

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [17 February 2021 15:47 UTC](https://discourse.nodered.org/t/writing-node-parameters-dynamically/40301/7 "2021-02-17T15:47:18Z")

</div>

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