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