# Send value from api to bacnet

**URL:** <https://discourse.nodered.org/t/send-value-from-api-to-bacnet/94112>\
**Category:** General\
**Tags:** function-node\
**Created:** [22 December 2024 21:52 UTC](https://discourse.nodered.org/t/send-value-from-api-to-bacnet/94112 "2024-12-22T21:52:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rippen85](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rippen85/32/97474_2.png) [@Rippen85](https://discourse.nodered.org/u/Rippen85)\
**Post date:** [22 December 2024 21:52 UTC](https://discourse.nodered.org/t/send-value-from-api-to-bacnet/94112/1 "2024-12-22T21:52:40Z")

</div>

I collect 24 points from Nordpool, then I want to send them to my bacnet unit. but it only takes the last value? How do I do between "chart data" and "write".

```auto
[
    {
        "id": "3cb529667ade3110",
        "type": "inject",
        "z": "3c0393f03dbda828",
        "name": "",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 100,
        "y": 240,
        "wires": [
            [
                "a1a79db0436d00ca"
            ]
        ]
    },
    {
        "id": "a1a79db0436d00ca",
        "type": "nordpool-api-plus",
        "z": "3c0393f03dbda828",
        "name": "",
        "area": "SE3",
        "currency": "SEK",
        "x": 300,
        "y": 240,
        "wires": [
            [
                "71c72db195b68260"
            ]
        ]
    },
    {
        "id": "71c72db195b68260",
        "type": "function",
        "z": "3c0393f03dbda828",
        "name": "chart data",
        "func": "var msg1 = {}\nfor (var i = 0; i<msg.payload.length;i++){\n msg1 = {\n topic:msg.payload[i].currency, \n payload:msg.payload[i].price, \n timestamp:msg.payload[i].timestamp,\n }\n node.send(msg1)\n}",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 500,
        "y": 240,
        "wires": [
            [
                "31826f5c856251e0",
                "85e1388914e4c5d9"
            ]
        ]
    },
    {
        "id": "8495e9b47b3be0f1",
        "type": "Bacnet-Gateway",
        "z": "3c0393f03dbda828",
        "name": "",
        "local_device_address": "192.168.68.151",
        "apduTimeout": 6000,
        "roundDecimal": 2,
        "local_device_port": 47808,
        "apduSize": "5",
        "maxSegments": "0x50",
        "retries": "5",
        "broadCastAddr": "255.255.255.255",
        "toLogIam": true,
        "discover_polling_schedule": "60",
        "discover_polling_schedule_value": "1",
        "discover_polling_schedule_options": "Minutes",
        "deviceId": "817001",
        "logErrorToConsole": false,
        "serverEnabled": false,
        "device_read_schedule": "60",
        "device_read_schedule_value": "1",
        "device_read_schedule_options": "Minutes",
        "deviceRangeRegisters": [],
        "portRangeRegisters": [],
        "cacheFileEnabled": false,
        "sanitise_device_schedule": "undefined",
        "sanitise_device_schedule_value": "",
        "x": 1180,
        "y": 80,
        "wires": [
            [
                "889e729a38804583"
            ]
        ]
    },
    {
        "id": "729a0561a8de8969",
        "type": "Bitpool-Inject",
        "z": "3c0393f03dbda828",
        "name": "Discover",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "doPoll": false,
        "doDiscover": true,
        "json": false,
        "mqtt": false,
        "pointJson": false,
        "object_property_simplePayload": false,
        "object_property_simpleWithStatus": false,
        "object_property_fullObject": false,
        "useDeviceName": false,
        "x": 1000,
        "y": 80,
        "wires": [
            [
                "8495e9b47b3be0f1"
            ]
        ]
    },
    {
        "id": "1926046efc180209",
        "type": "Bitpool-Inject",
        "z": "3c0393f03dbda828",
        "name": "Poll",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "doPoll": true,
        "doDiscover": false,
        "x": 750,
        "y": 120,
        "wires": [
            [
                "d11de816c82f7cbb"
            ]
        ]
    },
    {
        "id": "889e729a38804583",
        "type": "debug",
        "z": "3c0393f03dbda828",
        "name": "debug 4",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1360,
        "y": 80,
        "wires": []
    },
    {
        "id": "d11de816c82f7cbb",
        "type": "Bacnet-Write",
        "z": "3c0393f03dbda828",
        "name": "",
        "applicationTag": "4",
        "priority": "16",
        "pointsToWrite": [
            {
                "meta": {
                    "objectId": {
                        "type": 2,
                        "instance": 1
                    },
                    "device": {
                        "address": "192.168.68.149",
                        "isMstp": false,
                        "deviceId": 3057254,
                        "vendorId": 10,
                        "deviceName": "AS-P_3057254 3057254"
                    }
                },
                "description": "",
                "objectName": "Time_00",
                "displayName": "Time_00",
                "objectType": 2,
                "presentValue": 311.5,
                "hasPriorityArray": true,
                "units": "no-units",
                "error": "none",
                "timestamp": 1734900612850,
                "status": "online",
                "deviceId": 3057254,
                "deviceAddress": "192.168.68.149",
                "key": "1-0-Time_00_AV_1"
            },
            {
                "meta": {
                    "objectId": {
                        "type": 2,
                        "instance": 2
                    },
                    "device": {
                        "address": "192.168.68.149",
                        "isMstp": false,
                        "deviceId": 3057254,
                        "vendorId": 10,
                        "deviceName": "AS-P_3057254 3057254"
                    }
                },
                "description": "",
                "objectName": "Time_01",
                "displayName": "Time_01",
                "objectType": 2,
                "presentValue": 10,
                "hasPriorityArray": true,
                "units": "no-units",
                "error": "none",
                "timestamp": 1734900612851,
                "status": "online",
                "deviceId": 3057254,
                "deviceAddress": "192.168.68.149",
                "key": "1-0-Time_01_AV_2"
            },
            {
                "meta": {
                    "objectId": {
                        "type": 2,
                        "instance": 3
                    },
                    "device": {
                        "address": "192.168.68.149",
                        "isMstp": false,
                        "deviceId": 3057254,
                        "vendorId": 10,
                        "deviceName": "AS-P_3057254 3057254"
                    }
                },
                "description": "",
                "objectName": "Time_03",
                "displayName": "Time_03",
                "objectType": 2,
                "presentValue": 252,
                "hasPriorityArray": true,
                "units": "no-units",
                "error": "none",
                "timestamp": 1734900612851,
                "status": "online",
                "deviceId": 3057254,
                "deviceAddress": "192.168.68.149",
                "key": "1-0-Time_03_AV_3"
            },
            {
                "meta": {
                    "objectId": {
                        "type": 2,
                        "instance": 4
                    },
                    "device": {
                        "address": "192.168.68.149",
                        "isMstp": false,
                        "deviceId": 3057254,
                        "vendorId": 10,
                        "deviceName": "AS-P_3057254 3057254"
                    }
                },
                "description": "",
                "objectName": "Time_04",
                "displayName": "Time_04",
                "objectType": 2,
                "presentValue": 25,
                "hasPriorityArray": true,
                "units": "no-units",
                "error": "none",
                "timestamp": 1734900612852,
                "status": "online",
                "deviceId": 3057254,
                "deviceAddress": "192.168.68.149",
                "key": "1-0-Time_04_AV_4"
            },
            {
                "meta": {
                    "objectId": {
                        "type": 2,
                        "instance": 5
                    },
                    "device": {
                        "address": "192.168.68.149",
                        "isMstp": false,
                        "deviceId": 3057254,
                        "vendorId": 10,
                        "deviceName": "AS-P_3057254 3057254"
                    }
                },
                "description": "",
                "objectName": "Time_05",
                "displayName": "Time_05",
                "objectType": 2,
                "presentValue": 8,
                "hasPriorityArray": true,
                "units": "no-units",
                "error": "none",
                "timestamp": 1734900612852,
                "status": "online",
                "deviceId": 3057254,
                "deviceAddress": "192.168.68.149",
                "key": "1-0-Time_05_AV_5"
            },
            {
                "meta": {
                    "objectId": {
                        "type": 2,
                        "instance": 6
                    }
                },
                "description": "",
                "objectName": "Time_02",
                "displayName": "Time_02",
                "objectType": 2,
                "presentValue": 0,
                "hasPriorityArray": true,
                "units": "no-units",
                "deviceId": 3057254,
                "deviceAddress": "192.168.68.149",
                "key": "1-0-Time_02_AV_6"
            }
        ],
        "writeDevices": [
            {
                "key": 1,
                "label": "AS-P_3057254 3057254",
                "data": "AS-P_3057254 3057254",
                "icon": "pi pi-server",
                "children": [
                    {
                        "key": "1-0-Time_00_AV_1",
                        "label": "Time_00",
                        "data": "Time_00",
                        "pointName": "Time_00_AV_1",
                        "icon": "pi writePointIcon",
                        "children": [
                            {
                                "label": "Name: Time_00",
                                "data": "Time_00",
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Object Type: 2",
                                "data": 2,
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Object Instance: 1",
                                "data": 1,
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Units: no-units",
                                "data": "no-units",
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Present Value: 311.5",
                                "data": 311.5,
                                "icon": "pi pi-cog",
                                "children": null
                            }
                        ],
                        "type": "point",
                        "parentDevice": "AS-P_3057254 3057254",
                        "parentDeviceId": 3057254,
                        "showAdded": true,
                        "bacnetType": 2,
                        "bacnetInstance": 1
                    },
                    {
                        "key": "1-0-Time_01_AV_2",
                        "label": "Time_01",
                        "data": "Time_01",
                        "pointName": "Time_01_AV_2",
                        "icon": "pi writePointIcon",
                        "children": [
                            {
                                "label": "Name: Time_01",
                                "data": "Time_01",
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Object Type: 2",
                                "data": 2,
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Object Instance: 2",
                                "data": 2,
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Units: no-units",
                                "data": "no-units",
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Present Value: 10",
                                "data": 10,
                                "icon": "pi pi-cog",
                                "children": null
                            }
                        ],
                        "type": "point",
                        "parentDevice": "AS-P_3057254 3057254",
                        "parentDeviceId": 3057254,
                        "showAdded": true,
                        "bacnetType": 2,
                        "bacnetInstance": 2
                    },
                    {
                        "key": "1-0-Time_03_AV_3",
                        "label": "Time_03",
                        "data": "Time_03",
                        "pointName": "Time_03_AV_3",
                        "icon": "pi writePointIcon",
                        "children": [
                            {
                                "label": "Name: Time_03",
                                "data": "Time_03",
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Object Type: 2",
                                "data": 2,
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Object Instance: 3",
                                "data": 3,
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Units: no-units",
                                "data": "no-units",
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Present Value: 252",
                                "data": 252,
                                "icon": "pi pi-cog",
                                "children": null
                            }
                        ],
                        "type": "point",
                        "parentDevice": "AS-P_3057254 3057254",
                        "parentDeviceId": 3057254,
                        "showAdded": true,
                        "bacnetType": 2,
                        "bacnetInstance": 3
                    },
                    {
                        "key": "1-0-Time_04_AV_4",
                        "label": "Time_04",
                        "data": "Time_04",
                        "pointName": "Time_04_AV_4",
                        "icon": "pi writePointIcon",
                        "children": [
                            {
                                "label": "Name: Time_04",
                                "data": "Time_04",
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Object Type: 2",
                                "data": 2,
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Object Instance: 4",
                                "data": 4,
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Units: no-units",
                                "data": "no-units",
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Present Value: 25",
                                "data": 25,
                                "icon": "pi pi-cog",
                                "children": null
                            }
                        ],
                        "type": "point",
                        "parentDevice": "AS-P_3057254 3057254",
                        "parentDeviceId": 3057254,
                        "showAdded": true,
                        "bacnetType": 2,
                        "bacnetInstance": 4
                    },
                    {
                        "key": "1-0-Time_05_AV_5",
                        "label": "Time_05",
                        "data": "Time_05",
                        "pointName": "Time_05_AV_5",
                        "icon": "pi writePointIcon",
                        "children": [
                            {
                                "label": "Name: Time_05",
                                "data": "Time_05",
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Object Type: 2",
                                "data": 2,
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Object Instance: 5",
                                "data": 5,
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Units: no-units",
                                "data": "no-units",
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Present Value: 8",
                                "data": 8,
                                "icon": "pi pi-cog",
                                "children": null
                            }
                        ],
                        "type": "point",
                        "parentDevice": "AS-P_3057254 3057254",
                        "parentDeviceId": 3057254,
                        "showAdded": true,
                        "bacnetType": 2,
                        "bacnetInstance": 5
                    },
                    {
                        "key": "1-0-Time_02_AV_6",
                        "label": "Time_02",
                        "data": "Time_02",
                        "pointName": "Time_02_AV_6",
                        "icon": "pi writePointIcon",
                        "children": [
                            {
                                "label": "Name: Time_02",
                                "data": "Time_02",
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Object Type: 2",
                                "data": 2,
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Object Instance: 6",
                                "data": 6,
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Units: no-units",
                                "data": "no-units",
                                "icon": "pi pi-cog",
                                "children": null
                            },
                            {
                                "label": "Present Value: 0",
                                "data": 0,
                                "icon": "pi pi-cog",
                                "children": null
                            }
                        ],
                        "type": "point",
                        "parentDevice": "AS-P_3057254 3057254",
                        "parentDeviceId": 3057254,
                        "showAdded": true,
                        "bacnetType": 2,
                        "bacnetInstance": 6
                    }
                ],
                "type": "device",
                "lastSeen": 1734900585739,
                "showAdded": false,
                "ipAddr": "192.168.68.149",
                "deviceId": 3057254,
                "isMstpDevice": false,
                "initialName": "AS-P_3057254 3057254"
            }
        ],
        "hiddenDeployToggle": false,
        "prevHiddenToggleState": false,
        "x": 1010,
        "y": 160,
        "wires": [
            [
                "8495e9b47b3be0f1"
            ]
        ]
    },
    {
        "id": "31826f5c856251e0",
        "type": "debug",
        "z": "3c0393f03dbda828",
        "name": "debug 5",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 500,
        "y": 180,
        "wires": []
    },
    {
        "id": "85e1388914e4c5d9",
        "type": "switch",
        "z": "3c0393f03dbda828",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "index",
                "v": "",
                "vt": "num",
                "v2": "",
                "v2t": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 770,
        "y": 300,
        "wires": [
            [
                "d11de816c82f7cbb"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [23 December 2024 09:38 UTC](https://discourse.nodered.org/t/send-value-from-api-to-bacnet/94112/2 "2024-12-23T09:38:35Z")

</div>

Hi There,

You have a switch node that has an index between rule with no values:

> [@Rippen85](#):
>
> ```auto
> {
> "id": "85e1388914e4c5d9",
> "type": "switch",
> "z": "3c0393f03dbda828",
> "name": "",
> "property": "payload",
> "propertyType": "msg",
> "rules": [
> {
> "t": "index",
> "v": "",
> "vt": "num",
> "v2": "",
> "v2t": "num"
> }
> ],
> "checkall": "true",
> "repair": false,
> "outputs": 1,
> "x": 770,
> "y": 300,
> "wires": [
> [
> "d11de816c82f7cbb"
> ]
> ]
> }
> 
> ```

 ![Screenshot 2024-12-23 at 10.35.12](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/b/bbc03016be969140f2a26b299fac2a7be7510eed.png)

Seems a little strange to me, what is it meant to do?

---

<div class="post-metadata">

**Author:** ![Rippen85](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rippen85/32/97474_2.png) [@Rippen85](https://discourse.nodered.org/u/Rippen85)\
**Post date:** [23 December 2024 10:42 UTC](https://discourse.nodered.org/t/send-value-from-api-to-bacnet/94112/3 "2024-12-23T10:42:38Z")

</div>

> [@Rippen85](#):
>
> I collect 24 points from Nordpool

I only gett the last value from API (551.77)

 ![Skärmbild 2024-12-23 114149](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/efbf61e3803ee5e29611559da48ef9ae14105bec.jpeg)

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [23 December 2024 10:53 UTC](https://discourse.nodered.org/t/send-value-from-api-to-bacnet/94112/4 "2024-12-23T10:53:35Z")

</div>

> [@Rippen85](#):
>
> I only gett the last value from API (551.77)

I don't know that's why I asked:

> [@gregorius](#):
>
> Seems a little strange to me, what is it meant to do?

I still don't know.

> [@Rippen85](#):
>
> ![Skärmbild 2024-12-23 114149](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/efbf61e3803ee5e29611559da48ef9ae14105bec.jpeg)
> 
> Skärmbild 2024-12-23 1141491937×579 176 KB

Oh, I see from your new screenshot, you've removed the switch node _and_ you are still just getting a single value.

Is the payload that is going into the function node really an array?

```auto
var msg1 = {}
for (var i = 0; i<msg.payload.length;i++){
    msg1 = {
        topic:msg.payload[i].currency, 
        payload:msg.payload[i].price, 
        timestamp:msg.payload[i].timestamp,
    }
    node.send(msg1)
}

```

that's what the function node is doing and the code assumes that payload is an array if not, it's probably just sending a single value (since payload.length is one). I have no idea what the `nordpool-api-plus` node returns but check the payload that comes from it.

Btw using forEach might be simpler:

```auto
msg.payload.forEach( val => {
    msg1 = {
        topic:val.currency, 
        payload:val.price, 
        timestamp:val.timestamp,
    }
    node.send(msg1)
})

```

forEach will fail if msg.payload isn't an array.

---

<div class="post-metadata">

**Author:** ![Rippen85](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rippen85/32/97474_2.png) [@Rippen85](https://discourse.nodered.org/u/Rippen85)\
**Post date:** [26 December 2024 11:59 UTC](https://discourse.nodered.org/t/send-value-from-api-to-bacnet/94112/5 "2024-12-26T11:59:10Z")

</div>

![Skärmbild 2024-12-26 130202](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/1/f1d28873938da25ab3cbe856d79ae424442d4ad9.png)

Solution  
msg.payload = msg.payload[0].price  
return msg  
msg.payload = msg.payload[1].price  
return msg  
msg.payload = msg.payload[2].price  
return msg  
M.M

---

<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:** [26 March 2025 11:59 UTC](https://discourse.nodered.org/t/send-value-from-api-to-bacnet/94112/6 "2025-03-26T11:59:33Z")

</div>

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