Hello,
I am new to Node-Red, and I am facing a simple problem. Connection of my nodes is explained bellow. There is an inject node which is my matrix: "CREATE TABLE RANDOMNUM( TIMESTAMP INT PRIMARY KEY NOT NULL, VALUE INT NOT NULL, BOOL INT NOT NULL)". This node is connected to a "litedb" node and "litedb" is connected to a debug node. There is another inject node which is connected to the following function.
var randomNum = Math.round(Math.random()*100);
var largeBool = (randomNum > 50?1:0);
var newMsg = {
"topic": "INSERT INTO RANDOMNUM VALUES ( "+msg.payload+","+randomNum+","+largeBool+")"}
return newMsg;
This function is connected as well to the litedb node and what I want to do is to visualize the variable "newMsg" in a chart. I have tried different connections with chart but it none of them works.
By 'litedb' are you refering to sqlite??
When explaining a issue, it is helpful (and time saving for anyone going to give you some of their time) to provide the name of the exact node you are using like: The flow is using node-red-node-sqlite.
What is the debug node showing when you insert a value? (please change the debug node to show the 'complete msg object')
Then you need to do a SELECT against the database & then you need to format the returned rows of data to match the described format in the built-in help on the chart node.
NOTE: the SELECT should have a suitable WHERE / TOP / LIMIT clause to avoid sending more data to the chart than there are pixels (e.g. if you try to display 10000 points on a 400px chart - not only will it be pointless but it will make your browser crawl)
I was thinking about creating a new function which will have only selected values from the previous function, for example "randomNum" and "largeBool". I want these to values to be visualized in a chart but I don't know how to write the code for this. Its simple but I am confused.
I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.
There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.
Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.
The function code (with comments to help you understand)...
var randomNum = Math.round(Math.random() * 100);
var largeBool = (randomNum > 50 ? 1 : 0);
var newMsg = {
"topic": "INSERT INTO RANDOMNUM VALUES ( " + msg.payload + "," + randomNum + "," + largeBool + ")"
}
//create a msg with topic and payload set - for the number
var msg2 = {
topic: "number",
payload: randomNum
}
//create a msg with topic and payload set - for the bool
var msg3 = {
topic: "bool",
payload: largeBool
}
//return the 3 messages (array element 0 goes to output 1, element 1 goes to output 2 etc)
return [newMsg, msg2, msg3];