SNMP Access problem

I'm using SNMP Node and when I try to send the query to the snmp object the response it's a counter64 (buffer)

Host-> IP
Community-> Public
SNMP version -> 2c
OID=1.3.6.1.2.1.31.1.1.1.10.1

I can't transform this buffer to valid number.

Can you help me?

I'm using node-red 1.3.5

Thanks

I hope someone comes up with an answer to this because I've never found an answer that worked with the SNMP from my Ubiquity router and AP's. In my case, it looked like the output, although supposedly a 64bit buffer, it didn't output 64bits if it didn't need to and you ended up with an odd number of bits.

Not sure this is related but JavaScript does not support 64 bit integers or reals. I am battling a similar issue with Modbus.

That was asked 2012.

JavaScript now has a BigInt type.

The issue I've seen is when the SNMP call returns a value with type of counter64, the value has less than 8 bytes.

1 Like

Steve,

What SNMP version are you using V1 or V2 (I am still working on V3, work got in the way) Can you give me a bit more details, and I might see if I can reproduce it on my side.

Regarding the BigInt, thanks, I am am aware, Real is as far as I am aware still limited to 52 bits precision, rest is an approximation. Might be wrong as it has been several months since I looked at this. Covid restrictions and chaos in the way :frowning:

1 Like

BigInt supports > 2^53-1

I am not in a position to provide a demo of the issue right now - will post something later.

Here is a flow ...
image

[{"id":"f6decc13.2c32a","type":"inject","z":"4b3f21a3.ba434","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":600,"y":2140,"wires":[["6522738f.23f59c"]]},{"id":"6522738f.23f59c","type":"snmp","z":"4b3f21a3.ba434","host":"192.168.1.35","community":"public","version":"2c","oids":"1.3.6.1.2.1.31.1.1.1.10.1","timeout":5,"name":"","x":770,"y":2140,"wires":[["2f3fccff.2f3c54"]]},{"id":"2f3fccff.2f3c54","type":"debug","z":"4b3f21a3.ba434","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":960,"y":2140,"wires":[]}]

that produces this...

image

{"oid":"1.3.6.1.2.1.31.1.1.1.10.1","type":70,"value":[79,57,56,189],"tstr":"Counter64"}

As you can see, 4 bytes is not enough to make a 64bit value.

1 Like

I think that I was getting even weirder results from some of the counters on my Ubiquity router - I seem to remember having odd numbers of bytes. I did have a couple of stabs at trying to piece things together as a bigint but my bit-banging foo seems to have rusted up.

1 Like

Had another play & now get sensible values...

In simple terms, put the buffer bytes returned from SNMP (for a Counter64) to the far end of an 8 byte buffer then read readBigInt64BE does the job.

function...


for(let i = 0; i < msg.payload.length; i++) {
    const item = msg.payload[i];
    if(item.tstr !== "Counter64") continue;
    let buf2 = item.value
    let bufStart = 8 - buf2.length; 
    let buf1 = Buffer.alloc(bufStart);
    buf = Buffer.concat([buf1, buf2]);
    item.bufferValue = item.value
    item.value =  Number(buf.readBigInt64BE());
}

return msg;

Demo flow...

[{"id":"f6decc13.2c32a","type":"inject","z":"4b3f21a3.ba434","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":615,"y":2160,"wires":[["6522738f.23f59c","c1382789.698da8"]],"l":false},{"id":"6522738f.23f59c","type":"snmp","z":"4b3f21a3.ba434","host":"192.168.1.35","community":"xxx","version":"2c","oids":"1.3.6.1.2.1.31.1.1.1.10.1","timeout":5,"name":"","x":750,"y":2140,"wires":[["9079b6c6.c072d8"]]},{"id":"9079b6c6.c072d8","type":"function","z":"4b3f21a3.ba434","name":"","func":"\nfor(let i = 0; i < msg.payload.length; i++) {\n    if(msg.payload[i].tstr !== \"Counter64\") continue;\n    const item = msg.payload[i];\n    let buf2 = item.value\n    let bufStart = 8 - buf2.length; \n    let buf1 = Buffer.alloc(bufStart);\n    buf = Buffer.concat([buf1, buf2]);\n    item.bufferValue = item.value\n    item.value =  Number(buf.readBigInt64BE());\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":929,"y":2160,"wires":[["ef8ba2a3.61a59"]]},{"id":"c1382789.698da8","type":"snmp","z":"4b3f21a3.ba434","host":"192.168.1.35","community":"xxx","version":"2c","oids":"1.3.6.1.2.1.31.1.1.1.11.1","timeout":5,"name":"","x":750,"y":2180,"wires":[["9079b6c6.c072d8"]]},{"id":"ef8ba2a3.61a59","type":"debug","z":"4b3f21a3.ba434","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":2200,"wires":[]}]
2 Likes

this solve my problem.

thanks

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