# Sending a buffer from momentary button action

**URL:** https://discourse.nodered.org/t/sending-a-buffer-from-momentary-button-action/35403
**Category:** Dashboard
**Created:** [5 November 2020 21:07 UTC](https://discourse.nodered.org/t/sending-a-buffer-from-momentary-button-action/35403 "2020-11-05T21:07:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![RudiWiedemann](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@RudiWiedemann](https://discourse.nodered.org/u/RudiWiedemann)
#### Post date: [5 November 2020 21:07 UTC](https://discourse.nodered.org/t/sending-a-buffer-from-momentary-button-action/35403/1 "2020-11-05T21:07:17Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [5 November 2020 22:00 UTC](https://discourse.nodered.org/t/sending-a-buffer-from-momentary-button-action/35403/2 "2020-11-05T22:00:31Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![RudiWiedemann](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@RudiWiedemann](https://discourse.nodered.org/u/RudiWiedemann)
#### Post date: [6 November 2020 20:01 UTC](https://discourse.nodered.org/t/sending-a-buffer-from-momentary-button-action/35403/3 "2020-11-06T20:01:23Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/1/b1eba885c10688f51a2bf7b69d6952f83aec70f5.jpeg)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [6 December 2020 20:01 UTC](https://discourse.nodered.org/t/sending-a-buffer-from-momentary-button-action/35403/4 "2020-12-06T20:01:26Z")

</div>

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