Hi, IT guy pretending to understand how to script this function and not getting it. Below function is working. The reason I did it this way was to simply get the right output to BLYNK app.
However there are some values here I would like to group and just show that component status. For example, instead of showing status of LED Green, LED red and LED Yellow individually, I want to display " LED status : [green] '. What is the best way to do this?
The function node is as below
let var1
let var2;
let var3;
let var4;
let var5;
let var6;
let var7;
let var8;
let var9;
let var10;
let var11;
let var12;
let var13;
let var14;
let msg1 = {payload: var1};
let msg2 = {payload: var2};
let msg3 = {payload: var3};
let msg4 = {payload: var4};
let msg5 = {payload: var5};
let msg6 = {payload: var6};
let msg7 = {payload: var7};
let msg8 = {payload: var8};
let msg9 = {payload: var9};
let msg10 = {payload: var10};
let msg11 = {payload: var11};
let msg12 = {payload: var12};
let msg13 = {payload: var13};
let msg14 = {payload: var14};
What determines " LED status : [green] " ? What values would msg.payload.LEDGreen, msg.payload.LEDRed and msg.payload.LEDYellow have to have to make that string?
OBSERVATION...
Why do you bother even splitting the object? All this code is fairly unnecessary - you can simply set the ui_text to the property of interest...
OBSERVATION2...
I know i said you dont need to split out each message but if you must, this might be a bit more manageable...
msg.payload.LEDGreen, red, yellow are all true or false values. The fun thing is that I realized in certain conditions both green and red can both be true. When I initially posted I was assuming only one would be true at a time. Having said that there are other payloads (not shown) with similar true or false value I would want the same logic for, just unsure how to do it (example, system is either in auto mode or manual mode, so which ever of those is TRUE I want to have that reflect as running status AUTO or MANUAL
why bother splitting the object? Because my skills and experience usually end at 'copy/paste/edit' someone else's code lol. This was the first way I did it that actually worked. thanks for the other example, will play around with that and see if that makes more sense to me.
As I mentioned briefly, end goal is to use BLYNK / to reflect the system current status in the most efficient way possible. Right now I have node-red (on a PI) polling the Siemens S7-1200 PLC every 30 seconds. This will be a remote location connected over cellular, and I may end up pushing the data up to a cloud repository of sorts over MQTT and then on to Blynk from there, haven't gotten that far to think about it too much yet. Past that, future phase would also be ability to push changes back down to the PLC remotely via Blynk or at that point a custom app, React Native possibly.
NOTE: with both of these solutions, I add to the payload a property named "machineMode". This can be used in your ui elements by accessing msg.payload.machineMode
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. Worth the 5 mins read (especially the bit about using the "copy" buttons that appear under your mouse when you hover over a debug output in the sidebar). Working with messages : Node-RED