Not wanting to confuse matters, but the => syntax in
object.result.map(x => parseInt(x,16))
will only work in node 4.x or later.
Otherwise...
object.result.map(function(x) { return parseInt(x,16);});
Nick
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
For more options, visit https://groups.google.com/d/optout.
var b = parseInt("00fa",16);
msg.payload = b;
return msg;var b = parseInt(msg.payload.result [3],16);
msg.payload = b;
return msg;(Object){"result": [ "ffcc", "00fa", "00be", "02bc", "01e0", "0190", "1543", "0064" ]}
var result = msg.payload.result.map(x => parseInt(x,16))
msg.payload = result;
return msg;(Array) [ 65484, 250, 190, 700, 480, 400, 5443, 100 ]You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/TarEdQ19d1U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.
var input = [ "ffcc", "00fa", "00be", "02bc", "01e1", "0190", "1543", "0064"];var output = [];
var buffer = new Buffer(input.map(b => [b.substr(0,2), b.substr(2,2)]).reduce((a,b) => a.concat(b)).map(x => parseInt(x, 16)));
for (var b = 0 ; b < buffer.length/2 ; b++) { var value = buffer.readInt16BE(b*2, 2) / 10; output.push(value.toFixed(0));}
console.log(output);
function returnval(x){
if (x > 6000){
x = Math.round((x - 65535) / 10);
}else{
x = Math.round(x/10);
}
return x;
}
var result = msg.payload.result.map(x => parseInt(x,16));
//result[0] return 65484 value for -5 PV on Temperature Controller
var dev_1 = returnval(result[0]);