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.
- 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 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
That is not enough info to help you.
Where do you see this?
What was the value of msg.payload
BEFORE the function node?
What was does the full msg
object look like AFTER the function node?
// **msg.payload before the function node**
var name = msg.payload;
name = name[0]["TEMPERATURE"];
msg.payload =name;
msg.payload = msg.payload.toString();
msg.topic = null;
return msg;
I have attached a screenshot which you can see the output.
Thank you in advance.
That is your function code - not the value of msg.payload
Put a debug BEFORE the function node, show us the value of msg.payload
before it enters the function
AND a debug AFTER the function node so we can see the FULL msg
object (set debug node to show complete message)
Ok, one last time
Add debug nodes like this...
... and give them all names (like "Debug Split Func", "debug request func", "debug http response")
Show use what you get out of all three debug nodes.
This is after the function node:
<str val="undefined" />
then the incoming payload is not correct. Do as I asked in previous post (add 3 debugs)
very odd.
2 things...
- Copy all the code you have inside the "request_FromNiagra" function as it is right now & paste into a reply (remember
```
formatting) - Add
node.warn(["msg.payload", msg.payload, typeof msg.payload])
at the TOP of the "request_FromNiagra" function and try again
show use what you see in the debug sidebar.
// assign some variables
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.payload}" />`;
return msg;