# Regarding to send a message from Node red to Niagara 4 framework

**URL:** https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603
**Category:** General
**Created:** [18 February 2022 14:33 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603 "2022-02-18T14:33:15Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Hitesh1234](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@Hitesh1234](https://discourse.nodered.org/u/Hitesh1234)
#### Post date: [18 February 2022 14:33 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/1 "2022-02-18T14:33:15Z")

</div>

Hello,,,

I would like to tell you that I would like to send a message or post a message from Node-red to Niagara 4 framework via Obix communication. The message from Niagara 4 can be read into the Node-red but the message can't be written or posted from Node-red to Niagara 4. I got an error. Also, I attached a screenshot of an error. Please see the attachment

 ![node-redNiagara4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/e/9e83026788efe4c7fe9b76ee93880d8a8458b8f4.png)  
.

Could you please to help me out to solve this problem?

Thank you in advance.

BR,  
Hiteshkumar Amipara

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [18 February 2022 14:43 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/2 "2022-02-18T14:43:42Z")

</div>

possibly the problem is mixing single quotes with double quotes when you try to concatenate the string ?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9ccc4a174d9d8c3f66a3967d9f35f0aa1ec75793.png)

try all double or all single quotes for that line

---

<div class="post-metadata">

### Author: ![Hitesh1234](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@Hitesh1234](https://discourse.nodered.org/u/Hitesh1234)
#### Post date: [18 February 2022 14:49 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/3 "2022-02-18T14:49:09Z")

</div>

Thank you for your reply.

When I will try all double then I got an error: "Expecting quoted attribute value"

I have also attached a screenshot. please see it.

Thank you.

```auto
![noderedNiagara1|632x500](upload://vZ5mZTUlP5Mlhtx8gRCwx8FAysl.png)

```

---

<div class="post-metadata">

### Author: ![Hitesh1234](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@Hitesh1234](https://discourse.nodered.org/u/Hitesh1234)
#### Post date: [18 February 2022 14:51 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/4 "2022-02-18T14:51:06Z")

</div>

![noderedNiagara1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/0/e02b22b59b05119f5c308573c899089a21f7be15.png)

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [18 February 2022 14:59 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/5 "2022-02-18T14:59:22Z")

</div>

> [@Hitesh1234](#):
>
> Expecting quoted attribute value

try it this way .. using [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) with backticks ( ` )

```auto
msg.payload = `<str val="${msg.payload}"/>`  

```

---

<div class="post-metadata">

### Author: ![Hitesh1234](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@Hitesh1234](https://discourse.nodered.org/u/Hitesh1234)
#### Post date: [18 February 2022 15:24 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/6 "2022-02-18T15:24:06Z")

</div>

Thank you once again.

I would like to inform you that if I used what you said in the last message then the msg.payload is written as output. But I want to post the value of msg.payload not just msg.payload.

I am sharing a screenshot. Please see it.

In the screenshot, the value of msg.payload is "ABCD". but the output is written as a msg.payload istead of "ABCD"

Thank you so much.

 ![Niagara](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/e/befed4b23102a3874c97a826a18443e885e0c294.png)  
 ![NodeRed](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/8/984af6919284bbeac5e57f3e3f65a8dcf87d25d3.png)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [18 February 2022 15:30 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/7 "2022-02-18T15:30:08Z")

</div>

With this

```auto
msg.payload = `<str val="${msg.payload}"/>`

```

are you using ` a backtick or a ' single quote

your original was missing 2 single quotes

```auto
msg.payload = '<str val="'+msg.payload+'"/>'; 

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [18 February 2022 15:30 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/8 "2022-02-18T15:30:34Z")

</div>

Why are you coding the request in a function node instead of using the battle tested http request node?

---

<div class="post-metadata">

### Author: ![Hitesh1234](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@Hitesh1234](https://discourse.nodered.org/u/Hitesh1234)
#### Post date: [18 February 2022 15:40 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/9 "2022-02-18T15:40:24Z")

</div>

> [@Steve-Mcl](#):
>
> battle tested http request node

Hallo E1cid,

I did try what you mentioned in your message. It's not working.

I have attached a screenshot. Please see it.

 ![niagara](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/9/69115e3965faea1856ed14e7340302a0b3b217d3.png)  
 ![node-red](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5c7e93a2424561d2c4796bd7c14e7ecad447d270.png)

Thank you in advance.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [18 February 2022 15:43 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/11 "2022-02-18T15:43:52Z")

</div>

msg.payload is undefined  
add  
node.warn(msg.payload);  
just before the line to confirm msg.payload has not been defined  
p.s. when posting code it is best to post text, as images are hard to read and copy from.

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [18 February 2022 15:47 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/12 "2022-02-18T15:47:38Z")

</div>

by doing `msg = { "method" : "POST" ... }` doesnt that mean that you destroy whatever was in `msg.payload` and it becomes _undefined_ ?

at the **top** of your code save the value of `msg.payload` coming from the previous msg  
for Example

`let val = msg.payload`

so you can later use it with

```auto
msg.payload = `<str val="${val}"/>`

```

(note those are backticks not single quotes)

---

<div class="post-metadata">

### Author: ![Hitesh1234](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@Hitesh1234](https://discourse.nodered.org/u/Hitesh1234)
#### Post date: [18 February 2022 16:05 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/13 "2022-02-18T16:05:37Z")

</div>

sorry to say that...It's not working....

---

<div class="post-metadata">

### Author: ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)
#### Post date: [18 February 2022 16:16 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/14 "2022-02-18T16:16:27Z")

</div>

what have you tried ?

> [@E1cid](#):
>
> when posting code it is best to post text, as images are hard to read and copy from.

wire a **complete msg** Debug node and show us what comes out of that Function node.  
do you get a new error from the device ?

---

<div class="post-metadata">

### Author: ![Hitesh1234](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@Hitesh1234](https://discourse.nodered.org/u/Hitesh1234)
#### Post date: [21 February 2022 13:45 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/15 "2022-02-21T13:45:14Z")

</div>

Good morning...

I would like to tell you that I am trying to read and write data from MySQL into the Niagara 4 via Node-red with Obix driver. The data from the Niagara 4 has been read successfully into the MySQL server but the data from the MySQL has not been read successfully into the Niagara 4. Also, I am going to tell how the connection has been made between Niagara 4 with Node-Red as well as Node-red with MySQL.

1. connection between the Niagara 4 with Node-red via oBIX: For connection, I built a Node-red flow that can read the data from Niagara 4 into the Node-red. A built Node-red flow includes a function node, HTTP request, XML..

2)connection between the Node-red with MySQL: A mysql driver is used in Nore-red to access to a MySQL database.

Problem: A message, as a string value comes out of the function node, can't be written in Niagara 4.

I have also attached a screenshot of inputs and outputs.

Please see it..

Thank you in advance.

Best regards,  
Hiteshkumar Amipara

 ![node-red and Niagara 4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/b/eb921824f6de12911e32474240073b8e0dba020b.png)  
 ![node-red and niagara 4 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/e/4e3a5c24be20ccc4bd31cc1599fd707220340c98.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [21 February 2022 13:56 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/16 "2022-02-21T13:56:45Z")

</div>

You are trying to put an object into a string (line 33) thats why you get `val: "[object Object]"`

As said before by @UnborN ...

> [@UnborN](#):
>
> at the **top** of your code save the value of `msg.payload` coming from the previous msg

So add something like `var payload = msg.payload` at the top of your function then use `payload` instead of `msg` in line 33

* * *

TIP:  
Please post actual function code **not** screenshots of code since it is harder for us to test and provide you with fixes (without re-typing what you have already wrote)

TIP2:  
enable monaco editor to see the number of undeclared variables and potential errors you have.

---

<div class="post-metadata">

### Author: ![Hitesh1234](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@Hitesh1234](https://discourse.nodered.org/u/Hitesh1234)
#### Post date: [21 February 2022 13:58 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/17 "2022-02-21T13:58:57Z")

</div>

// Code of Function node  
username = "obixUser";  
password = "Wetec123456#@";  
ipAddress = "172.30.34.212";  
httpsPort = 443;

authHash = Buffer.from(username+":"+password).toString("base64");

//ordSlot = "/Drivers/SysmikScaIoNetwork/AI4\_2/points/Ai3/out/value";  
ordSlot = "/Supply$20Fan/NewValue";  
//ordSlot = "/Supply$20Fan/p";  
// create the message for the get request  
operation = "/set";  
msg={  
"method": "POST",  
"url": "https://"+ipAddress+":"+httpsPort+"/obix/config"+ordSlot+operation,  
"headers":{  
"Authorization": "Basic" + authHash,  
"Accept":"_/_"  
}

};

//ignore cert expired error

msg.rejectUnauthorized = false;

msg.payload = `<str val ="${msg}"/>`;

return msg;

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [21 February 2022 13:59 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/18 "2022-02-21T13:59:21Z")

</div>

TIP3:

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

### Author: ![Hitesh1234](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@Hitesh1234](https://discourse.nodered.org/u/Hitesh1234)
#### Post date: [21 February 2022 14:01 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/19 "2022-02-21T14:01:01Z")

</div>

```auto
// code of Function node
username = "obixUser";
password = "Wetec123456#@";
ipAddress = "172.30.34.212";
httpsPort = 443;

//create a base64 digest

authHash = Buffer.from(username+":"+password).toString("base64");

//ordSlot = "/Drivers/SysmikScaIoNetwork/AI4_2/points/Ai3/out/value";
ordSlot = "/Supply$20Fan/NewValue";
//ordSlot = "/Supply$20Fan/p";
// create the message for the get request
operation = "/set";
msg={
    "method": "POST",
    "url": "https://"+ipAddress+":"+httpsPort+"/obix/config"+ordSlot+operation,
    "headers":{
        "Authorization": "Basic" + authHash,
        "Accept":"*/*"
    }
    
};

//ignore cert expired error

msg.rejectUnauthorized = false;

//msg.payload = '<str val ="'+msg.payload+'"/>';

msg.payload = `<str val ="${msg}"/>`;

return msg;

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [21 February 2022 14:04 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/20 "2022-02-21T14:04:04Z")

</div>

Try this...

```auto
// Code of Function node

const incomingPayload = msg.payload; //save msg.payload before you destroy the msg object below
const username = "obixUser";
const password = "Wetec123456#@";
const ipAddress = "172.30.34.212";
const httpsPort = 443;
const authHash = Buffer.from(username + ":" + password).toString("base64");
const ordSlot = "/Supply$20Fan/NewValue";
const operation = "/set";

// create the message for the get request
msg = {
    "method": "POST",
    "url": "https://" + ipAddress + ":" + httpsPort + "/obix/config" + ordSlot + operation,
    "headers": {
        "Authorization": "Basic" + authHash,
        "Accept": "/"
    }

};

//ignore cert expired error
msg.rejectUnauthorized = false;

msg.payload = `<str val="${incomingPayload}" />`; //Use the saved value of msg.payload

return msg;

```

---

<div class="post-metadata">

### Author: ![Hitesh1234](https://avatars.discourse-cdn.com/v4/letter/h/77aa72/32.png) [@Hitesh1234](https://discourse.nodered.org/u/Hitesh1234)
#### Post date: [21 February 2022 14:08 UTC](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603/21 "2022-02-21T14:08:04Z")

</div>

Thank you for your message.

Output is: **undefined**

[Next page](https://discourse.nodered.org/t/regarding-to-send-a-message-from-node-red-to-niagara-4-framework/58603.md?page=2)
