How to construct SNMP Varbinds with payload values

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.

Unfortunately your flows aren't currently importable.Please read the following post How to share code or flow json and then edit the above message.

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

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"]]}]

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"]]}]

So this is your function:

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

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.

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

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.

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.

Indeed. Already fixed

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

1 Like