# SNMP Access problem

**URL:** <https://discourse.nodered.org/t/snmp-access-problem/45990>\
**Category:** General\
**Created:** [20 May 2021 16:15 UTC](https://discourse.nodered.org/t/snmp-access-problem/45990 "2021-05-20T16:15:37Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielmf](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@danielmf](https://discourse.nodered.org/u/danielmf)\
**Post date:** [20 May 2021 16:15 UTC](https://discourse.nodered.org/t/snmp-access-problem/45990/1 "2021-05-20T16:15:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [20 May 2021 16:26 UTC](https://discourse.nodered.org/t/snmp-access-problem/45990/2 "2021-05-20T16:26:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AsHex\_66](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ashex_66/32/31151_2.png) [@AsHex\_66](https://discourse.nodered.org/u/AsHex_66)\
**Post date:** [28 May 2021 07:28 UTC](https://discourse.nodered.org/t/snmp-access-problem/45990/3 "2021-05-28T07:28:27Z")

</div>

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

> <https://stackoverflow.com/questions/9643626/does-javascript-support-64-bit-integers>

---

<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:** [28 May 2021 07:50 UTC](https://discourse.nodered.org/t/snmp-access-problem/45990/4 "2021-05-28T07:50:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AsHex\_66](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ashex_66/32/31151_2.png) [@AsHex\_66](https://discourse.nodered.org/u/AsHex_66)\
**Post date:** [28 May 2021 08:16 UTC](https://discourse.nodered.org/t/snmp-access-problem/45990/5 "2021-05-28T08:16:47Z")

</div>

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 ☹

---

<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:** [28 May 2021 08:28 UTC](https://discourse.nodered.org/t/snmp-access-problem/45990/6 "2021-05-28T08:28:48Z")

</div>

BigInt supports \> 2^53-1

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

---

<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:** [28 May 2021 10:37 UTC](https://discourse.nodered.org/t/snmp-access-problem/45990/7 "2021-05-28T10:37:34Z")

</div>

> [@AsHex\_66](#):
>
> Can you give me a bit more details, and I might see if I can reproduce it on my side

Here is a flow ...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/8/e83dbd683d18e97980c2ca454b8adc43ff172353.png)

```auto
[{"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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ffd5d99dac05dd6a720aa02556f1bf438333d6e8.png)

```auto
{"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.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [28 May 2021 10:46 UTC](https://discourse.nodered.org/t/snmp-access-problem/45990/8 "2021-05-28T10:46:33Z")

</div>

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.

---

<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:** [1 June 2021 10:08 UTC](https://discourse.nodered.org/t/snmp-access-problem/45990/9 "2021-06-01T10:08:06Z")

</div>

Had another play & now get sensible values...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/1/c11d6d91e4f489ad69cb775bfc8074e4a7641198.png)

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...

```auto

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...

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![danielmf](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@danielmf](https://discourse.nodered.org/u/danielmf)\
**Post date:** [1 June 2021 16:28 UTC](https://discourse.nodered.org/t/snmp-access-problem/45990/10 "2021-06-01T16:28:10Z")

</div>

this solve my problem.

thanks

---

<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:** [15 June 2021 16:29 UTC](https://discourse.nodered.org/t/snmp-access-problem/45990/11 "2021-06-15T16:29:01Z")

</div>

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