RPICT and Node-Red hosted on Raspberrypi: Difference between revisions

From lechacal
Jump to navigation Jump to search
No edit summary
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 3: Line 3:
Make sure any program using the ttyAMA0 serial is off (emonhub, python programs etc).
Make sure any program using the ttyAMA0 serial is off (emonhub, python programs etc).


We assume a fresh install of Raspbian in this document.
We assume a fresh install of Raspberry Pi OS in this document.


Make sure you have followed the steps to setup the serial port first.
Make sure the steps to setup the serial port have been completed first.<br>
[[Howto setup Raspbian for serial read]]
[[Howto setup Raspbian for serial read]]


Line 22: Line 22:
Open a browser and go the indicated address. http://192.168.1.206:1880 for us here.
Open a browser and go the indicated address. http://192.168.1.206:1880 for us here.


How to setup Node-Red depends on what the user wants to achieve. We will show a simple example here how to split the data from the serial string.
How to setup Node-Red depends on what the user wants to achieve. We will show a simple example here to split the data from the serial string.


Start to build a flow with a ''Serial Input'' a ''Function'' block and ''Debug'' output.
Start to build a flow with a ''Serial Input'' a ''Function'' block and ''Debug'' output.


[[File:Rpictnodered_002.png]]
[[File:Rpictnodered_002.png]]
[[File:Rpictnodered_001.png]]
 
[[File:Rpictnodered_003.png]]
Now setup the serial port as shown below:
 
[[File:Rpictnodered_001.png| 300px]]
 
Then enter the java script in the function. Make 3 outputs are selected. Modify the script to your needs. We will just provide NodeID the First Real Power and Vrms from a RPICT7V1.
 
[[File:Rpictnodered_003.png| 300px]]
 
The code is here below for copy paste.
 
var output = msg.payload.split(" ");
var NodeID = parseInt(output[0]);
var RP1    = parseFloat(output[1]);
var Vrms  = parseFloat(output[15]);
var msg1 = {payload : NodeID};
var msg2 = {payload : RP1};
var msg3 = {payload : Vrms};
return [msg1, msg2, msg3];
 
The right pane debug will show the split values.
 
[[File:Rpictnodered_004.png| 300px]]

Latest revision as of 10:14, 31 October 2020


Make sure any program using the ttyAMA0 serial is off (emonhub, python programs etc).

We assume a fresh install of Raspberry Pi OS in this document.

Make sure the steps to setup the serial port have been completed first.
Howto setup Raspbian for serial read

Install Node-Red as follow

sudo apt-get install nodered

Start Node Red

node-red-start

You will see a similar message to this below at the top

Once Node-RED has started, point a browser at http://192.168.1.206:1880

Open a browser and go the indicated address. http://192.168.1.206:1880 for us here.

How to setup Node-Red depends on what the user wants to achieve. We will show a simple example here to split the data from the serial string.

Start to build a flow with a Serial Input a Function block and Debug output.

Now setup the serial port as shown below:

Then enter the java script in the function. Make 3 outputs are selected. Modify the script to your needs. We will just provide NodeID the First Real Power and Vrms from a RPICT7V1.

The code is here below for copy paste.

var output = msg.payload.split(" ");

var NodeID = parseInt(output[0]);
var RP1    = parseFloat(output[1]);
var Vrms   = parseFloat(output[15]);

var msg1 = {payload : NodeID};
var msg2 = {payload : RP1};
var msg3 = {payload : Vrms};

return [msg1, msg2, msg3];

The right pane debug will show the split values.