# How to construct SNMP Varbinds with payload values

**URL:** <https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413>\
**Category:** General\
**Created:** [1 November 2019 13:43 UTC](https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413 "2019-11-01T13:43:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![heyhogan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/heyhogan/32/13897_2.png) [@heyhogan](https://discourse.nodered.org/u/heyhogan)\
**Post date:** [1 November 2019 13:43 UTC](https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413/1 "2019-11-01T13:43:11Z")

</div>

I am using the SNMP SET node and want to craft a Varbinds with items from msg.payload. When I build a valid msg.varbinds via a function node and pass it in, I get "Unexpected end of JSON input". The same data pasted directly into the SNMP SET node works.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [1 November 2019 17:19 UTC](https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413/4 "2019-11-01T17:19:24Z")

</div>

Unfortunately your flows aren't currently importable.Please read the following post [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506) and then edit the above message.

---

<div class="post-metadata">

**Author:** ![heyhogan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/heyhogan/32/13897_2.png) [@heyhogan](https://discourse.nodered.org/u/heyhogan)\
**Post date:** [3 November 2019 04:08 UTC](https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413/5 "2019-11-03T04:08:45Z")

</div>

Thanks for the feedback. I will re-post correctly!

---

<div class="post-metadata">

**Author:** ![heyhogan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/heyhogan/32/13897_2.png) [@heyhogan](https://discourse.nodered.org/u/heyhogan)\
**Post date:** [3 November 2019 04:13 UTC](https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413/6 "2019-11-03T04:13:04Z")

</div>

Here is the working code...

`[{"id":"af0deb90.cddf8","type":"function","z":"decf9f47.ca3f3","name":"Create varibind","func":"var inputValue = msg.payload;\nmsg.varbinds = [{\"oid\":\"1.3.6.1.4.1.19536.10.1.5.1.1.2.1.6\",\"type\":\"OctetString\",\"value\": \"\"+msg.payload+\"\"}]\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":2240,"wires":[["4bb28274.c69094","2e302916.8e4ad6"]]}]`

---

<div class="post-metadata">

**Author:** ![heyhogan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/heyhogan/32/13897_2.png) [@heyhogan](https://discourse.nodered.org/u/heyhogan)\
**Post date:** [3 November 2019 04:14 UTC](https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413/7 "2019-11-03T04:14:44Z")

</div>

And here is the code that is similar, but giving errors:

`[{"id":"e6b1fc81.b6fce8","type":"function","z":"decf9f47.ca3f3","name":"Link OID and Outlet Number","func":"var inputValue = msg.payload;\nvar outlet = msg.payload.OutletNumber;\nvar name = msg.payload.Name;\nvar oid = \"1.3.6.1.4.1.19536.10.1.5.1.1.2.1.\";\nvar fulloid = oid + outlet;\nmsg.varbinds = [{\"oid\":\"\"+fulloid+\"\",\"type\":\"OctetString\",\"value\":\"\"+name+\"\"}]\nreturn msg;","outputs":1,"noerr":0,"x":240,"y":1980,"wires":[["c0153bcf.f2ca8","5917575.87ebf28","a43b8875.03654"]]}]`

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [3 November 2019 10:05 UTC](https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413/8 "2019-11-03T10:05:37Z")

</div>

So this is your function:

```auto
var inputValue = msg.payload;
var outlet = msg.payload.OutletNumber;
var name = msg.payload.Name;
var oid = "1.3.6.1.4.1.19536.10.1.5.1.1.2.1.";
var fulloid = oid + outlet;
msg.varbinds = [{"oid":""+fulloid+"","type":"OctetString","value":""+name+""}]
return msg;

```

Since `name` cimes from `msg.payload.Name` what is in `msg.payload.Name`? Try adding a debug node to the node that feeds your function node so you can see it's contents

---

<div class="post-metadata">

**Author:** ![heyhogan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/heyhogan/32/13897_2.png) [@heyhogan](https://discourse.nodered.org/u/heyhogan)\
**Post date:** [6 November 2019 04:43 UTC](https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413/9 "2019-11-06T04:43:04Z")

</div>

I did have a debug node, and what was driving me crazy was that it had the right info in it. I did find the error. At some point I must have entered the SNMP SET node and started to type in something in the Varbinds field, but then deleted it, or so I thought. I left a few blank spaces so the windows looked empty, but was not empty. When I deleted the node and copied a new one in, it worked just fine.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 November 2019 06:58 UTC](https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413/10 "2019-11-06T06:58:59Z")

</div>

It might be good to submit an issue on the node. A field with just spaces should generally be treated as empty.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 November 2019 08:01 UTC](https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413/11 "2019-11-06T08:01:43Z")

</div>

No. In general spaces are treated as spaces. The user may wish to send spaces. In this specific case they may not, so yes could be fixed.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 November 2019 10:41 UTC](https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413/12 "2019-11-06T10:41:57Z")

</div>

Perhaps my use of the word 'general' was too general. I suppose what I meant was that fields where an entry consisting of just spaces would not be expected, and where an empty field has some significance (such as allowing a value to be passed in a message attribute), should ideally be treated as if they are empty. It is not what one could call a bug, it is just a matter of being nice to the user.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 November 2019 10:49 UTC](https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413/13 "2019-11-06T10:49:50Z")

</div>

Indeed. Already fixed

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 November 2019 10:57 UTC](https://discourse.nodered.org/t/how-to-construct-snmp-varbinds-with-payload-values/17413/14 "2019-11-06T10:57:46Z")

</div>

Having made that comment I am now going to have to check all my nodes to see I have coped with that condition. ☹
