Trying to optimise my flows a bit but am having problems i cant quite fathom.
i have 4 x function nodes i think i can replace with 1. Each is passed the same message containing sensor readings and has to reference a flow level variable to determine the record source.
(the preceding node overwrites the topic).
so in each function i am retrieving the flow level variable that indicates the sensor data source and using that to recreate a meaningful topic hierarchy, including the sensor type that function is devoted to, and resetting the message payload to the payload.sensor value of interest before passing on the new message.
the individual function devoted to temperatures :
var plant = flow.get('plant')||'PlantU';
var part1 = plant.slice(0,5);
var part2 = plant.slice(-1);
plant = part1 +'/' + part2;
msg.payload = msg.payload.temperature;
msg.topic = 'Notify/'+ plant +'/T';
return msg;
Works without errors and the other functions mirror what its doing too
After my initial post i thought i may as well move the final payload assignments to where i am declaring the new messages, after doing so the error stopped appearing in the debug window?
i had copied the declaration statement directly from a node red guide page.
But now no error??? alls well i guess..
I guess i must have left a stray ',' or invisible character in the text i have pasted a lot as i dont know any java.. ..
re the output, i am currently using 4 discrete output nodes and directing all 4 paths back to the same mqtt out node, with your suggestion i could reduce the flows to 1 and send out all 4 messages in an array? sequentially?, Ok i will give that a go.. thanks again for taking the time to look at this?
Have you tried to use "Change" and "Switch" instead of "Function" for such a manipulation? I'm pretty sure you can do most of those string managements by only using the "Change" node and increase the readability even more