Sending a buffer from momentary button action

I'm trying to send 2 different sequences of bytes using a momentary button widget in Node Red. I want to send a buffer (NOT an array) of raw bytes [145,48,64] when a button (with configurable color) is pressed, and then a different buffer [129,48,64] of raw bytes when that button (with different color) is released. I'm not a JS or HTML programmer. Just a hacker with some Node Red experience. Here is the code I'm using as a modified Template Node from someone else:

var bon = Buffer.from([145,48,64]);
var boff = Buffer.from([129,48,64]);
this.scope.on = {payload: bon};
this.scope.off = {payload: boff};
</script>
<md-button
   ng-touchstart="send(on)"
   ng-mousedown="send(on)"
   ng-touchend="send(off)"
   ng-mouseup="send(off)">
       C4
</md-button>

Ideally the code could be buried in a single Node (like the Template Node) with the buffer values embedded in that node since I'm trying to create a control panel with lots of these buttons and don't want a clogged up Node Red IDE.

I'd appreciate any help. Thanks in advance.

Hi

Buffer is a nodejs thing - not available in the browser.

You could simply send an array then using a function node at server side (in node-red) convert the array into a Buffer...

Function node

msg.payload = Buffer.from(msg.payload);
return msg;

Stephen:

That worked great! I was just able to “bufferize” the array generated by the Template.

Now, using the existing code as a basis, can you help me define the text color and background color? Right now the default is white text on red background.

image002.jpg

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