(Actually I am now thinking this is not the right node for this job, but.....)
I have a message payload (example) 123
I want to split it into 3 messages: 12 and 3.
I'm not up on node-red's asynchronous operations, but it may not be needed.
Oh, Specifications for the function:
3 digits. Numbers.
Must be 3 numbers long.
Leading 0 must be sent. (Kinda given if 3 digits)
A nominal delay between messages being sent out.
let digits = msg.payload.toString().split('');
let realDigits = digits.map(Number)
function sendOut(digit){
node.send({payload:digit})
}
realDigits.forEach(sendOut)
And then add delay node after function node and adjust the delay between messages as needed.
var y = 0;
var z = 0;
var x = msg.payload;
y = parseInt(x / 100);
msg.payload = y;
node.send(msg);
x = x - (y * 100);
msg.payload = x
node.send(msg);
msg.payload = "test";
return msg;
Yeah, the test isn't needed, but just to see progress.
So I was:
int(/100) -- send result
modify
int(/10) -- send result
modify
send last digit.