Posts: 7
Joined: Thu Oct 27, 2016 10:18 am

SNMP Script

Fri Dec 02, 2016 12:33 pm

I need help with using SNMP with RaspberryPi.
I'm trying to read the status of an incoming GPIO.
Following your instructions, I created two files and changed the snmpd.conf file
When I do the tests the python script works correctly.
The bash script also works correctly and returns the state of the digital input, but when I put the pass in the snmd.conf file, it only returns 0, even though I change the status physically the read is 0, in the other scripts it returns 0 and 1 more In snmpget only 0.
Following are scripts below.

/home/pi > gpio_23.py

import RPi.GPIO as gpio
import time


# Com pull-up interno
gpio.setup(23, gpio.IN, pull_up_down = gpio.PUD_UP)

print (gpio.input(23))


/usr/local/bin > input23

if [ "$1" = "-g" ]
echo .
echo gauge
python /home/pi/gpio_23.py
exit 0

# "Pass-through" MIB extension command
#pass . /bin/sh PREFIX/local/passtest
#pass . /usr/bin/perl PREFIX/local/passtest.pl

pass . /bin/sh /usr/local/bin/snmp-cpu-temp
pass . /bin/sh /usr/local/bin/input23

# Note that this requires one of the two 'passtest' scripts to be installed fir$
# before the appropriate line is uncommented.
# These scripts can be found in the 'local' directory of the source distributio$
# and are not installed automatically.


root@raspberrypi:/home/pi# snmpget -v 2c localhost -c public .
iso. = Gauge32: 0

root@raspberrypi:/home/pi# python gpio_23.py

root@raspberrypi:/usr/local/bin# ./input23 -g

Thank you in advance

José Luiz Vieira.

Return to “Advanced users”