Help this noob with this extremely simple JS function

tl;dr: The only thing I actually need to know is how to separate 3 values from a string (they are separated by a enter) and also convert them into number (since they are numbers in string form) from the output of the join node inside of the function node

Hi, I want to make a simple program that detects wherever a program has frozen by checking wherever the values of this program are the same in 3 different times, currently, 20 seconds later and 40 seconds later, basically if value is the same in these 3 timezones then the program has become frozen and will be closed and reopened on the raspberry pi by a console command

This is how it looks, everything I said works up until the function part: It's pretty simple, a repeating inyection (manually for now since it doesn't work), reading the data from the program from emoncms since the data from that program gets sent to emoncms, getting 3 outputs numbers from diferent times, using the delay node to sync them up...

But after that the problems begin, here is the output from the Join node which is correct but the problem is that when it got joined the data got converted from number to string imagen

This is the omega noob part, because not only are they 3 values, they also are strings mixed in one msg.payload I can't for the life of me figure out how to separate them and also how to then convert them to number again, this is how this completely broken and unfinished JS thing is:

const triple = msg.payload

const words = triple.split(" ");

var valor1 = (words[0]);
var valor2 = (words[1]);
var valor3 = (words[2]);

var valor1n = Number("valor1")
var valor2n = Number("valor2")
var valor3n = Number("valor3")

msg.payload = ((valor1n + valor2n + valor3n)- valor3n * 3);

return msg;

After that probably omegasimple issue is done then I can finish the program which is as simple as ((value1 + value2 + value3) - (value3 * 3)) to check if the values are the same or not (if the result is 0 then all the values are the same and the program is detected as frozen so a command will sent to raspberry pi to close that frozen program.


What settings did you use for that Join node and you ended up with a string ?

From the looks of that flow i would recommend setting a unique Topic in each of those Change nodes and set your Join node to create an Object


If the above is not useful the regarding the splitting of the string try

const words = triple.split("\r"); \\ split on return

Thanks for your help, these are the setting on the join node:

Hi, it's good to see another emoncms user here!
Could I suggest a simpler solution;

The filter node blocks the flow unless the incoming payload value changes, and unless the trigger node gets an input every 30 seconds, then it produces an output to restart your server (or whatever).
So, if the input was constantly 342, the filter node would block the flow, and after 30 seconds of getting no input the trigger node would then send an output.
(you can set the trigger node to whatever time limit that you want , 10s, 20s, 40s...)

[{"id":"58ac22c943a9bc27","type":"inject","z":"8ec88bd9c36c3f6b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":195,"y":1015,"wires":[["dffb70a4d4b36361"]]},{"id":"dffb70a4d4b36361","type":"http request","z":"8ec88bd9c36c3f6b","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"","persist":false,"authType":"","senderr":false,"x":365,"y":1015,"wires":[["f272ae434f9d1f29"]]},{"id":"a2af9dd0eb54df12","type":"trigger","z":"8ec88bd9c36c3f6b","name":"","op1":"","op2":"Restart","op1type":"nul","op2type":"str","duration":"30","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":665,"y":1015,"wires":[["4a06dbd72efb5b59"]]},{"id":"4a06dbd72efb5b59","type":"debug","z":"8ec88bd9c36c3f6b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":1015,"wires":[]},{"id":"f272ae434f9d1f29","type":"rbe","z":"8ec88bd9c36c3f6b","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":false,"property":"payload","topi":"topic","x":520,"y":1015,"wires":[["a2af9dd0eb54df12"]]}]

Thank you very much sir, it works perfectly for what I needed.

I also have a program I made to detect if too much time has passed since the last time emoncms has recived a input update and if it's too high it sends a signal (in my case it resets the raspberry pi) but it doesn't work for my needs anymore, anyways here it is:

just do a http request of a feed's timevalue.json and feed id, in my case being ""

then with a change node set msg.payload into msg.payload.time

then the actual function:

var LastUpdate = msg.payload
var miliseconds =
var seconds = miliseconds/1000;
// After LastUpdate + put how many seconds
// of difference between last emoncms input update and actual time
msg.payload = (seconds > (LastUpdate + 180));

if (msg.payload === true) {return msg;}

the thing is that the program that was sending input data to emoncms gets semifrozen and the data sent flatlines (doesn't change and keeps sending the same value to emoncms) instead of updating but meanwhile the data doesn't update properly because the program is semifrozen, it still sends it to emoncms so every 10 seconds the same data and this is no good for the program I had, this is a example of the data flatlines:

With this new program nodered can detect when the data "flatlines" and reset the program with a linux command sent to the raspberry pi

Thanks both @UnborN and @Paul-Reed for the help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.