# Function output payload

**URL:** <https://discourse.nodered.org/t/function-output-payload/61098>\
**Category:** General\
**Created:** [11 April 2022 06:46 UTC](https://discourse.nodered.org/t/function-output-payload/61098 "2022-04-11T06:46:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonkers71](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jonkers71/32/59714_2.png) [@jonkers71](https://discourse.nodered.org/u/jonkers71)\
**Post date:** [11 April 2022 06:46 UTC](https://discourse.nodered.org/t/function-output-payload/61098/1 "2022-04-11T06:46:34Z")

</div>

Hello all.

This is probably really easy for somebody but I am struggling. I have read a bunch of stuff and never done any js stuff.

I am trying to use net-snmp in a function node. I need to eventually get snmp-v3 but for testing just v2.

I have it working so far and it returns the correct data in the debug window. But how do I get that same out put into the msg.payload?

Any help would be great. This is the code that I am running from the function node.

```auto
// NPM module exposed as variable, npm_module
var session = snmp.createSession ("192.168.10.250", "public");

var oids = ["1.3.6.1.2.1.1.1.0"];

session.get (oids, function (error, varbinds) {
    if (error) {
        console.error (error);
    } else {
        for (var i = 0; i < varbinds.length; i++) {
            if (snmp.isVarbindError (varbinds[i])) {
                console.error (snmp.varbindError (varbinds[i]));
            } else {
				console.log (varbinds[i].oid + " = " + varbinds[i].value);
            }
        }
    }
    session.close ();
});

return msg;

```

---

<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:** [11 April 2022 06:59 UTC](https://discourse.nodered.org/t/function-output-payload/61098/2 "2022-04-11T06:59:24Z")

</div>

Firstly, is there a reason you are not using [node-red-node-snmp](https://flows.nodered.org/node/node-red-node-snmp)?

Secondly, as you are running async code, you cannot `return msg` you need to use [node.send](https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously)

e.g....

```javascript
// NPM module exposed as variable, npm_module
const session = snmp.createSession ("192.168.10.250", "public");
const oids = ["1.3.6.1.2.1.1.1.0"];

session.get (oids, function (error, varbinds) {
    if (error) {
        node.error(error, msg);
    } else {
        for (let i = 0; i < varbinds.length; i++) {
            const e = snmp.varbindError(varbinds[i]);
            if (e) {
                node.error(e, msg);
            } else {
                msg.payload = varbinds[i].value;
                msg.topic = varbinds[i].oid;
                node.send(msg)
            }
        }
    }
    session.close ();
});

/// return msg; << delete this

```

---

<div class="post-metadata">

**Author:** ![jonkers71](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jonkers71/32/59714_2.png) [@jonkers71](https://discourse.nodered.org/u/jonkers71)\
**Post date:** [11 April 2022 07:09 UTC](https://discourse.nodered.org/t/function-output-payload/61098/3 "2022-04-11T07:09:04Z")

</div>

Thanks for the reply.

I wasnt using node-red-node-snmp because as far as I am aware I couldnt do snmpV3 which is where this will end up.

Am just trying to get it working before I move forward.

As i said I have been reading and getting it to this point and have no js experiance so it has been a bit of a learning curve.

I have shut the pc down now but Will give the changes ago tomorrow.

Thanks again.

---

<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:** [11 April 2022 07:15 UTC](https://discourse.nodered.org/t/function-output-payload/61098/4 "2022-04-11T07:15:42Z")

</div>

> [@jonkers71](#):
>
> I wasnt using node-red-node-snmp because as far as I am aware I couldnt do snmpV3

Ah. The node-red-node-snmp uses [net-snmp](https://www.npmjs.com/package/net-snmp) under the hood (which does support v3) however [its dependency](https://github.com/node-red/node-red-nodes/blob/8ca551d4bd3945619fa3159e3cc1b97d008e1ec9/io/snmp/package.json#L6) is on a really old version.

There is a [pull request](https://github.com/node-red/node-red-nodes/pull/705) to add V3 support but the PR author has not addressed the review comments (so the PR has stalled)

---

<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:** [26 April 2022 00:51 UTC](https://discourse.nodered.org/t/function-output-payload/61098/7 "2022-04-26T00:51:59Z")

</div>

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