igord93
Posts: 2
Joined: Thu Mar 29, 2018 7:11 pm

Problems running python and C trough SNMP

Thu Mar 29, 2018 7:48 pm

Hello everyone,

This is my first post here, so I apologize if I say something wrong.

I am using a Raspberry Pi 3 to build a temperature, humidity and smoke sensors that communicate over SNMP.

I made all the codes for the readings from the sensors, the temperature and humidity being in python and the smoke in C.

They all run normally trough the system, but when I call them over the SNMP, which have this code:

Code: Select all

agentAddress udp:161
rocommunity public
extend .1.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743 python /usr/local/bin/temp.py
This is what it returns:

Code: Select all

snmpwalk -v2c -c public localhost .1.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.1.0 = INTEGER: 1
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.2.1.2.6.112.121.116.104.111.110 = STRING: "/usr/local/bin/temp.py"
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.2.1.3.6.112.121.116.104.111.110 = ""
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.2.1.4.6.112.121.116.104.111.110 = ""
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.2.1.5.6.112.121.116.104.111.110 = INTEGER: 5
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.2.1.6.6.112.121.116.104.111.110 = INTEGER: 1
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.2.1.7.6.112.121.116.104.111.110 = INTEGER: 1
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.2.1.20.6.112.121.116.104.111.110 = INTEGER: 4
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.2.1.21.6.112.121.116.104.111.110 = INTEGER: 1
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.3.1.1.6.112.121.116.104.111.110 = STRING: "Traceback (most recent call last):"
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.3.1.2.6.112.121.116.104.111.110 = STRING: "Traceback (most recent call last):
  File \"/usr/local/bin/temp.py\", line 6, in <module>
    humidity, temperature = Adafruit_DHT.read_retry(22, 4)
  File \"build/bdist.linux-armv7l/egg/Adafruit_DHT/common.py\", line 94, in read_retry
  File \"build/bdist.linux-armv7l/egg/Adafruit_DHT/common.py\", line 81, in read
  File \"build/bdist.linux-armv7l/egg/Adafruit_DHT/Raspberry_Pi_2.py\", line 34, in read
RuntimeError: Error accessing GPIO."
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.3.1.3.6.112.121.116.104.111.110 = INTEGER: 7
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.3.1.4.6.112.121.116.104.111.110 = INTEGER: 1
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.4.1.2.6.112.121.116.104.111.110.1 = STRING: "Traceback (most recent call last):"
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.4.1.2.6.112.121.116.104.111.110.2 = STRING: "  File \"/usr/local/bin/temp.py\", line 6, in <module>"
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.4.1.2.6.112.121.116.104.111.110.3 = STRING: "    humidity, temperature = Adafruit_DHT.read_retry(22, 4)"
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.4.1.2.6.112.121.116.104.111.110.4 = STRING: "  File \"build/bdist.linux-armv7l/egg/Adafruit_DHT/common.py\", line 94, in read_retry"
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.4.1.2.6.112.121.116.104.111.110.5 = STRING: "  File \"build/bdist.linux-armv7l/egg/Adafruit_DHT/common.py\", line 81, in read"
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.4.1.2.6.112.121.116.104.111.110.6 = STRING: "  File \"build/bdist.linux-armv7l/egg/Adafruit_DHT/Raspberry_Pi_2.py\", line 34, in read"
iso.3.6.1.4.1.5528.100.4.1.1.1.8.1095346743.4.1.2.6.112.121.116.104.111.110.7 = STRING: "RuntimeError: Error accessing GPIO."
I don't know if I am missing a permission at some point. But if the system can run the code, why snmpd cannot?

Thank you very much for the help!

User avatar
topguy
Posts: 6073
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Problems running python and C trough SNMP

Fri Mar 30, 2018 9:33 pm

Code: Select all

RuntimeError: Error accessing GPIO."
Which user does "snmpd" run as ?

Code: Select all

ps -ef | grep snmpd
If that user does not have access to GPIO then you have to add that user to the group that give you access to the GPIO.

asandford
Posts: 1998
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Problems running python and C trough SNMP

Sat Mar 31, 2018 12:31 am

This isn't what SNMP is designed for, it's a management protocol, not an IoT tool. Whilst you can prpbably bend it to do what you want, why not use one of the numerous products such as MQTT which implement the functionality you require? I expect you'd find far more tutorials on the web for them than using SNMP.

gmc
Posts: 123
Joined: Fri Mar 09, 2012 11:31 am
Location: Cheshire, UK
Contact: Website

Re: Problems running python and C trough SNMP

Sat Mar 31, 2018 8:39 am

I would also suggest using MQTT. I just implemented this with my weather project in c. Works a treat.

https://www.eclipse.org/paho/clients/c/

igord93
Posts: 2
Joined: Thu Mar 29, 2018 7:11 pm

Re: Problems running python and C trough SNMP

Tue Apr 03, 2018 5:22 pm

Hey guys!

Thanks for the feedback, after some time I figured it out what that error was, was in the SNMP permission, after doing this command after stopping SNMP, it started working:

Code: Select all

sudo snmpd -Lf err log.txt
But now I am trying to modify the SNMP configuration file, to initiate with that line, and its not working.

I am trying to modify the SNMPDOPTS on the init.d directory but its not working out when I restart.

Where does the SNMP get the parameters to mount the this file?

Thanks you!

Return to “Beginners”