# Convert 20-byte string to 10-number array

**URL:** https://discourse.nodered.org/t/convert-20-byte-string-to-10-number-array/45886
**Category:** General
**Created:** [19 May 2021 01:11 UTC](https://discourse.nodered.org/t/convert-20-byte-string-to-10-number-array/45886 "2021-05-19T01:11:30Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![haltjc](https://avatars.discourse-cdn.com/v4/letter/h/858c86/32.png) [@haltjc](https://discourse.nodered.org/u/haltjc)
#### Post date: [19 May 2021 01:11 UTC](https://discourse.nodered.org/t/convert-20-byte-string-to-10-number-array/45886/1 "2021-05-19T01:11:31Z")

</div>

I am pulling a specific 20-byte set of data from the SNMP node. Every 2 bytes represent a different number. I need the output to be an array of 10 numbers, which will be sent to the InfluxDB node.

SNMP gives me an array[1], with the data I need in object 0 labeled:  
type: 0x4 value: "????????" and tstr: "OctetString"  
What I need is in value, so I split it and move the payload.value to payload.

I've tried multiple things from this point, and none have worked. Closest I get is the binary-node, setting the pattern to _b16 =\> label, b16 =\> label2, x128_. This gives me an object with { label: 65021, label2: 65021}. The resulting numbers should only be 3 digits, and not the same.

I also tried the buffer-parser node. This seems exactly what I want: the type, a label, set length, offset before the next one. However, I get a RangeError for attempting to write outside buffer bounds.

Any thoughts on what I'm doing wrong, or a better way to do it from the start? I did not think this was going to be the difficult part of my project! Thanks in advance.

---

<div class="post-metadata">

### Author: ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)
#### Post date: [19 May 2021 09:05 UTC](https://discourse.nodered.org/t/convert-20-byte-string-to-10-number-array/45886/2 "2021-05-19T09:05:53Z")

</div>

Can you give us a example flow with data?

---

<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: [19 May 2021 09:29 UTC](https://discourse.nodered.org/t/convert-20-byte-string-to-10-number-array/45886/3 "2021-05-19T09:29:51Z")

</div>

> [@haltjc](#):
>
> I am pulling a specific 20-byte set of data from the SNMP node. Every 2 bytes represent a different number. I need the output to be an array of 10 numbers

use buffer parser...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b4ce092460a9dbf0f6d53cc86c1f100676716de7.png)

Demo flow...

```auto
[{"id":"33b1b208.fa2e1e","type":"inject","z":"4b3f21a3.ba434","name":"fake SNMP 20 byte buffer","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[0,11,0,22,0,33,0,44,0,55,0,66,0,77,0,88,0,99,0,111]","payloadType":"bin","x":1990,"y":1860,"wires":[["c827dfeb.cb932","6bcc0ffc.5d21f"]]},{"id":"c827dfeb.cb932","type":"buffer-parser","z":"4b3f21a3.ba434","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item2","offset":2,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item3","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item4","offset":6,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item5","offset":8,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item6","offset":10,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item7","offset":12,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item8","offset":14,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item9","offset":16,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item10","offset":18,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":1950,"y":1920,"wires":[["e60792c2.2721d"]]},{"id":"e60792c2.2721d","type":"debug","z":"4b3f21a3.ba434","name":"after","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2190,"y":1920,"wires":[]},{"id":"6bcc0ffc.5d21f","type":"debug","z":"4b3f21a3.ba434","name":"before","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2190,"y":1860,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![haltjc](https://avatars.discourse-cdn.com/v4/letter/h/858c86/32.png) [@haltjc](https://discourse.nodered.org/u/haltjc)
#### Post date: [19 May 2021 19:26 UTC](https://discourse.nodered.org/t/convert-20-byte-string-to-10-number-array/45886/4 "2021-05-19T19:26:50Z")

</div>

Thanks for the quick responses. This is my first time exporting a flow, so I hope I got the formatting correct.

This flow shows the 4 results I described and am able to get. I must be missing a conversion somewhere to get rid of the "??????".

Using the buffer parser node from Steve-Mcl's example results in the same out of bounds error.

 ![Screen Shot 2021-05-19 at 12.24.05 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2c4ee09285b252c8601e53573d425af21bb8389b.png)

```auto
[{"id":"ff6977af.56c1f8","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"4322b239.2c8d1c","type":"snmp","z":"ff6977af.56c1f8","host":"192.168.1.100","community":"public","version":"2c","oids":"1.3.6.1.4.1.26565.1.1.6.6.0","timeout":5,"name":"","x":260,"y":180,"wires":[["62bc9db6.0dd7e4","d5a497a9.9d7eb8"]]},{"id":"62bc9db6.0dd7e4","type":"split","z":"ff6977af.56c1f8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":430,"y":240,"wires":[["26aad779.fdb598","44abee0b.12ddb"]]},{"id":"26aad779.fdb598","type":"change","z":"ff6977af.56c1f8","name":"","rules":[{"t":"move","p":"payload.value","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":300,"wires":[["e7ef94ed.d95c18","96327080.14dda"]]},{"id":"d5a497a9.9d7eb8","type":"debug","z":"ff6977af.56c1f8","name":"snmp payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":510,"y":180,"wires":[]},{"id":"44abee0b.12ddb","type":"debug","z":"ff6977af.56c1f8","name":"post-split payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":240,"wires":[]},{"id":"e7ef94ed.d95c18","type":"debug","z":"ff6977af.56c1f8","name":"post-move payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":300,"wires":[]},{"id":"a18cd3e2.0addf","type":"inject","z":"ff6977af.56c1f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":80,"y":100,"wires":[["4322b239.2c8d1c"]]},{"id":"96327080.14dda","type":"buffer-parser","z":"ff6977af.56c1f8","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item2","offset":2,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item3","offset":4,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item4","offset":6,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item5","offset":8,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item6","offset":10,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item7","offset":12,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item8","offset":14,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item9","offset":16,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"int16be","name":"item10","offset":18,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":890,"y":360,"wires":[["8157d9a5.a74dd8"]]},{"id":"8157d9a5.a74dd8","type":"debug","z":"ff6977af.56c1f8","name":"post-buffer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1100,"y":360,"wires":[]}]

```

---

<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: [18 July 2021 19:27 UTC](https://discourse.nodered.org/t/convert-20-byte-string-to-10-number-array/45886/5 "2021-07-18T19:27:00Z")

</div>

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