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

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


.

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

Thank you in advance.

BR,
Hiteshkumar Amipara

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

image

try all double or all single quotes for that line

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.

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

try it this way .. using template literals with backticks ( ` )

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

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.


With this

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

are you using ` a backtick or a ' single quote

your original was missing 2 single quotes

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

Why are you coding the request in a function node instead of using the 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.


Thank you in advance.

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.

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

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

(note those are backticks not single quotes)

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

what have you tried ?

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 ?

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


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

As said before by @UnborN ...

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.

// 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;

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 ```)

``` 
   code goes here 
```

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

See this post for more details - How to share code or flow json

// 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;

Try this...

// 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;

Thank you for your message.

Output is: undefined