SNMP GET Opaque data type results in hex values

I’m using the SNMP binding with OH2 and trying to get that battery value from my UPS connected through my Synology DiskStation.

I can read out OctetString and Integer values, but when it comes to Opaque, I get hex values back.

I’ve tried both Number and String, but only String actually return values…

String NAS_UPS_BATT "Battery on the UPS [%s %%]" { snmp="<[192.168.x.x:public:.1.3.6.1.4.1.6574.4.3.1.1.0:10]" }

Any ideas on this?

Thanks!
Thomas

I have exactly the same problem. Nodody else with that problem?

It’s been a while since this was posted, but since it showed up in my search, it might in others’ too.
The hex values are an encoded float, see https://stackoverflow.com/questions/35276556/snmpsharpnet-opaque-float. You can do the conversion via a JavaScript transform:

(function(input) {
    var bytes = input.split(":");
    if(bytes.length != 7 || bytes[0] != "9f" || bytes[1] != "78" || bytes[2] != "04") return input;
    var view = new DataView(new ArrayBuffer(4));
    for (i = 0; i < 4; i++) {
       var byteValue = parseInt("0x" + bytes[3 + i]);
       view.setInt8(i,byteValue);
    }
    return view.getFloat32(0);
})(input)

Save this as opaqueFloat.js in the transform folder. Then you can use it as follows:

Number UPS_BatteryLevel "UPS Battery Level [%d %%]" {snmp="<[nas:public:1.3.6.1.4.1.6574.4.3.1.1.0:10000:JS(opaqueFloat.js)]"}