0neblock / Arduino_SNMP

SNMP Agent built with Arduino
MIT License
77 stars 30 forks source link

Extended example #16

Closed shortbloke closed 2 years ago

shortbloke commented 3 years ago

Adding a more complete/complex example that implements a couple of MIB tables, stores SET values in local storage using LittleFS.

Would welcome feedback as to how tables could be better represented, whilst still keeping it fairly simple for others to follow.

sp4c3man commented 3 years ago

Hey shortbloke, thank you for your awesome example! I worked with it and everything is functional. But I have one problem - If the OIDs are greater than 127 the SNMP browser only finds the first OID with 127+. I'm not the best programmer and I've seen that the OIDs are saved as char. But why does frameflow show one OID with one value greater than 127, but only one?

Does your example work with 127+ OIDs on your PC? Maybe: char *oidentPhySensorType_1 = ".1.3.6.1.2.1.199.1.1.1.1.1";

I tried this in your example and he shows OIDs up to 127, but then other OIDs disappear and only one is shown.

Maybe you can help me :-) That would be great!

And I hope there is a way to gift you some beer for your awesome work!

shortbloke commented 3 years ago

@sp4c3man Glad you found the extended example useful. I don't seem to experience the problem you suggest, I updated my example code changing all the sensors from .99 to .199 and it worked just fine with iReasoning MIB browser walking the device: image

Can you provide some repro steps, and detail which tools you're using and I'll see how I can help.

WRT to support, this project isn't mine, I just contributed this example. Though if you want to support me, you can check out the link on my blog.

sp4c3man commented 3 years ago

Hey @shortbloke, I did not expect such super fast answer! Thanks! That are some good and bad news - the problem must be on my side.

I tried it again, only with your example data (no writing and loading files). Processor is an atmega1284 with Bobuino (arduino uno with atmega328 has way too small memory) and a wiznet w5500 ethernet adapter. My arduino version is 1.8.13, I installed the newest Ethernet.h, EthernetUdp.h and Arduino_SNMP.h and now I'm using two browsers: frameflow and ireasoning.

First note: if I press walk, he only shows sysDescr.0 and stops with a timeout. If I press "get next" it will go on to the first 199 OID and stops (with small OIDs I can "get next" to the last OID).

SNMP_Error

I could post my program, but it is a shortened version of your example - I think there is no copy paste error.

Maybe you have an idea - could be my last chance using greater OIDs.

Thank you!

shortbloke commented 3 years ago

@sp4c3man Ok so iReasoning 9.5 works when walking, as it uses get-request and get-next-request, where as iReasoning 13.0 uses getBulkRequest which doesn't work. The serial output shows "CORRUPT PACKET" in response to the GetBulk request, so I suspect this isn't supported.

I've tested on my ESP32 and using get and get next successfully gets .1.3.6.1.2.1.199.1.1.1.1.1 through to .1.3.6.1.2.1.199.1.1.1.8.1

The get-response for me is 96 bytes, as recorded with Wireshark. It's odd you can get .1.3.6.1.2.1.199.1.1.1.1.1 but not .1.3.6.1.2.1.199.1.1.1.2.1

Suggest you try capturing a Wireshark trace and also check the serial output, as the library might be throwing an error. With you're reduced memory footprint, I'm not sure what would be the max packet size you can handle.

sp4c3man commented 3 years ago

Hey again @shortbloke! Your solution approaches are very good! Something to learn for me :-)

Good to know, I think that's what frameflow does, when it is scanning the device address. Now I used wireshark and there happens something interesting when reaching the 128's.

There is no serial error message from my arduino, but there is this in wireshark:

SNMPerror

My PC is .35 and the device .50. I tried three times to get the next OID value and when I "get next" the ...128.1.1.1.1.2.1 then the response is some ...127.1.1.1.1.2.1 that's pretty weird. I can't imagine how that is possible.

Thank you!

shortbloke commented 3 years ago

@sp4c3man You mention there is an error in the Wireshark, the screenshot doesn't show it. Can you include a save of the Wireshark (.pcap) trace? Also does the serial output show the correct OIDs being requested? Actually, this might be a better conversation had via email rather than in this pull request. If you want to contact me you can reach me using: martin at martinrowan dot co dot uk (obviously with the necessary character substitution).

sp4c3man commented 3 years ago

@shortbloke Okay, I will write an e-mail to you with the data!

For everyone: I think this is a good example for checking the existing errors. When you have the same problem, please wait a few days, I will write a possible positive or a negative result to the end of this conversation!

0neblock commented 2 years ago

Hey @shortbloke, if you're able to update this for v2 of the library I can merge it in. Thanks!

shortbloke commented 2 years ago

@0neblock Updated to use new library methods. However, looks like I need to mock out the various dependencies, LITTLEFS, FS, ArduinoJson. Not entirely sure how to go about this and brief testing with cmake on master (with vscode, not using platform.io at this stage), the build fails, so I think I need more info on how to setup the correct dev environment to build and run the tests, so that I can then add the mocks.

0neblock commented 2 years ago

@0neblock Updated to use new library methods. However, looks like I need to mock out the various dependencies, LITTLEFS, FS, ArduinoJson. Not entirely sure how to go about this and brief testing with cmake on master (with vscode, not using platform.io at this stage), the build fails, so I think I need more info on how to setup the correct dev environment to build and run the tests, so that I can then add the mocks.

Thanks @shortbloke, I'll have a look. The "required" libs were mainly just to be able to use "Arduino.h", so I'll have to look into how to make it work with 3rd party libraries.

0neblock commented 2 years ago

@shortbloke I added the example build to the github tests mainly as a regression test for the built-in example. I'm happy to just merge this in now and if we want to put a regression test in for this we can later.