I have today installed a BMP180 pressure sensor and got it working correctly using the I2C bus on the RPi. I have created a very simple command script which will work as an SNMP "pass" command to return the pressure as an SNMP variable. I think I know how to do this as I have done the same for CPU temperature and room temperature using the DS18B20 "single-wire" probes.
However, I have come across a problem which I an unsure how to solve. It seems that access to the BMP180 device requires a script to be run as SU, so: sudo . However, when SNMP tries to run the script it fails, just as if the script were being run by a regular user. I've tried making the script owned by root, and making it run as if it were root (at least I think so, but my knowledge is very weak in that area), but that doesn't seem to be enough. I get:
IOError: [Errno 13] Permission denied
My script:
#!/bin/bash if [ "$1" = "-g" ] then echo .1.3.6.1.2.1.25.1.20 echo gauge python /home/pi/pressure.py fi exit 0
My Python code:
#!/usr/bin/python import Adafruit_BMP.BMP085 as BMP085 sensor = BMP085.BMP085(mode=BMP085.BMP085_ULTRAHIGHRES) pressure = sensor.read_pressure() + 2179 print '{0:0.0f}'.format(pressure)
Likely it's something obvious which my lack of experience is hiding from me!
sudo snmp-air-pressure -g # works correctly
snmp-air-pressure -g # fails with error 13