SNMP 2.x issue

Unsure if this is the method to reporting this, but I have started testing SNMP 2 and come across an issues setting the thing as a switch value. While the onvalue works great, the offvalue is failing as the full OID is a dynamic one and just disappears, the parent OID of .1.3.6.1.2.1.3.1.1.3.800.1 reports all of the IPs from the ARP table.

Type switch : phone_thing1                [ oid=".1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.5", mode="READ", datatype="IPADDRESS", onvalue="192.168.1.5", offvalue="nosuchinstance" ] 
Type switch : phone_thing2                [ oid=".1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.5", mode="READ", datatype="IPADDRESS", onvalue="192.168.1.5", offvalue="Null" ] 

My openhab log file was flooded with the following when I left my house, as my phone left and the IP was cleared from the ARP table.

2019-08-14 11:36:29.031 [WARN ] [ding.snmp.internal.SnmpTargetHandler] - Error: request 192.168.1.1/161:1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.5 returned '1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.5 = noSuchInstance'
2019-08-14 11:37:29.030 [WARN ] [ding.snmp.internal.SnmpTargetHandler] - Error: request 192.168.1.1/161:1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.5 returned '1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.5 = noSuchInstance'
2019-08-14 11:38:29.031 [WARN ] [ding.snmp.internal.SnmpTargetHandler] - Error: request 192.168.1.1/161:1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.5 returned '1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.5 = noSuchInstance'
2019-08-14 11:39:29.032 [WARN ] [ding.snmp.internal.SnmpTargetHandler] - Error: request 192.168.1.1/161:1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.5 returned '1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.5 = noSuchInstance'
2019-08-14 11:40:29.032 [WARN ] [ding.snmp.internal.SnmpTargetHandler] - Error: request 192.168.1.1/161:1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.5 returned '1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.5 = noSuchInstance'

With SNMP v1.x I was able to create a map file as the result was Null and I mapped it to OFF; I donā€™t see a difference or know of a value I can map to the offvalue to have the switch work properly.

Open to thoughts or suggestions if anyone has any.

Are you referring to SNMP v1 vs SNMP v2 or different versions of the binding?

SNMP itself is v2c on the network switch.

SNMP binding is v2.x.

I think you should only have 1 thing. What is your Thing configuration for phone_thing1 and phone_thing2?

Here are the docs with an example.

I do only have 1 thing defined, I listed both as different configurations I have tried so far to account for the OID not existing when the phone leaves the network. I used the OH doco to create what I have so far, when a phone is on the network it works as expected.

With the 1.x version of the SNMP binding requesting the OID .1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.5 will return the IP address from the ARP table of the switch, when the ARP entry expires (as the phone has left) the OID is actually removed and a query will fail. With the way OH handled it was by returning a Null value, the new way is behaving differently and I am looking to find a way to have the ā€˜offvalueā€™ value change to OFF. I only discovered this problem as I was updating a topic I wrote on using SNMP as another method to determine phone presence.

Below is an example of how the parent OID of the ARP table looks like.

$ snmpwalk -v2c -c public 192.168.1.1 1.3.6.1.2.1.3.1.1.3.800.1
1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.29 = IpAddress: 192.168.1.29
1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.45 = IpAddress: 192.168.1.45
1.3.6.1.2.1.3.1.1.3.800.1.192.168.1.231 = IpAddress: h192.168.1.231

Letā€™s start at the beginning.
What are you trying to accomplish with this? What is your end goal?

https://community.openhab.org/t/leveraging-snmp-to-detect-your-mobile-device

That is what I am trying to do with the new binding, as arping is not an option when OH and phones are in two different subnets.

So while the detection of the phone works as the OID exists, it is when the phone leaves that the binding doesnā€™t know what to do. It spams the log file and doesnā€™t change the value of the item.

From the CODEOWNER file found here it appears @J-N-K is author, perhaps heā€™ll pop in and let us know how it should work

1 Like

I would call that a bad design but anyway, I could set the channel-value to UNDEF if no response is received. You can map that to whatever you want then.

3 Likes

It was probably set that way to avoid keeping static entries in the MIB tables for ping sweeps/arp scans as by default the ARP table clears entries 4 hours by default.

Providing a UNDEF would probably resolve the issue, if the OID is not found; but I am receiving a response from the switch of ā€˜noSuchInstanceā€™. So Iā€™m unsure if this is something that is easy to change on the channel?

Also was unsure if a ā€˜onValueā€™ is specified, if you have to also define the ā€˜offValueā€™? Was going to also try applying a map statement on the phone2 item line to see if that could change the outcome of the switch state.

Please try this version bundle:update <number> https://janessa.me/esh/org.openhab.binding.snmp-undef.jar. Exceptions (like the one above) now set the channel to UNDEF.

Youā€™ll find a new configuration option (ā€œadvancedā€ in PaperUI) ignoreException. If you set true here, your log will not be flooded.

1 Like

Awesome @J-N-K!!! Iā€™ll comment out config files and set things up through PaperUI and test things out tonight as I donā€™t have a phone on the WiFi currently.

For doco purposes, if this replicates what I have working with the 1.x version of the binding; how can I add the ignoreException to config file?

2.X bindings do not use a config file like the 1.X ones do.

While that may be true for some bindings, the doco actually has a Thing file example along with a Item file example. :wink:

OK
Some bindings require manual Thing configuration. Others, such as zwave, automatically discover Things as the preferred method.

Just add it as an option to the channel configuration ignoreException="true"

1 Like

So testing has taken place, the On-Value works; turned off my wireless and waited 3 mins and the log spamming does occur, and the value in /rest/items/phone2 has a state of UNDEF.
I added UNDEF to the Off-Value and had the following log:

2019-08-15 21:36:55.909 [WARN ] [ding.snmp.internal.SnmpTargetHandler] - illegal value configuration for channel snmp:target:switch:phone2_thing

Also tried another round of testing with the config files setup, and the ignoreException=ā€œtrueā€ does flip to on in PaperUI on the channel. I checked in /rest/things/snmp:target:switch and it has the following value:

"ignoreException":true

Checking /rest/things/snmp:target:switch2 reports the following:

"ignoreException":"true"

Item state doesnā€™t change from UNDEF when I have a thing file in use; would a debug log be helpful for anything?

1 Like

I have updated the bundle above. Documentation is here: https://github.com/J-N-K/openhab2-addons/tree/snmp-undef/bundles/org.openhab.binding.snmp

1 Like

Awesome as always @J-N-K!!! Iā€™ll wipe out the PaperUI and config files when I get home tonight and do another round of testing and report back results.

Did it work as expected?

1 Like