Hello,
My OpenHAB 3.x is on Raspberry Pi with openhabian. When I run my local script it outputs temperature from sensor in °C as a number. But when I run same script (it is whitelisted) via exec binding I get this in logs:
File "/usr/local/bin/run-sht20-temp", line 6, in <module>
sht = SHT20(1, resolution=SHT20.TEMP_RES_14bit)
File "/usr/local/lib/python3.7/dist-packages/sht20/sht20.py", line 59, in __init__
self.bus = SMBus(port)
File "/usr/local/lib/python3.7/dist-packages/smbus2/smbus2.py", line 280, in __init__
self.open(bus)
File "/usr/local/lib/python3.7/dist-packages/smbus2/smbus2.py", line 310, in open
self.fd = os.open(filepath, os.O_RDWR)
PermissionError: [Errno 13] Permission denied: '/dev/i2c-1'
Traceback (most recent call last):
File "/usr/local/bin/run-sht20-temp", line 6, in <module>
sht = SHT20(1, resolution=SHT20.TEMP_RES_14bit)
File "/usr/local/lib/python3.7/dist-packages/sht20/sht20.py", line 59, in __init__
self.bus = SMBus(port)
File "/usr/local/lib/python3.7/dist-packages/smbus2/smbus2.py", line 280, in __init__
self.open(bus)
File "/usr/local/lib/python3.7/dist-packages/smbus2/smbus2.py", line 310, in open
self.fd = os.open(filepath, os.O_RDWR)
PermissionError: [Errno 13] Permission denied: '/dev/i2c-1'
It looks like problems with permissions. I have already tried to give the script chmod +x and also chmod u+r+x but did not help.
Also tried to put “sudo” everywhere into script.
I am newbie in Linux could you please give me some hints how to get that script running via exec binding?
Edit: My whitelisted script has name “get-data.sh” and contains:
#!/bin/bash
echo $(run-sht20-temp)
It takes data from "run-sht20-temp " which contains:
#!/usr/bin/python3
from sht20 import SHT20
from time import sleep
sht = SHT20(1, resolution=SHT20.TEMP_RES_14bit)
temp = sht.read_temp()
# or
data = sht.read_all()
temp = data[0]
print(temp)
I have only gave extra chmod permissions to my whitelisted script: “get-data.sh”.
Should I also give extra permissions to these python scripts which process sensor values?