I try to read ADC values from SPI on raspberry PI 2 with OpenHAB.
I have the following item. This item should execute a python script, which should have one input parameter and one return value. The return value should set the moisture value from the item Moisture_Tomatoes. the input parameter is to select the SPI channel from the python script :
Number Moisture_Tomatoes “M: [%d]” (Moisture) {exec="[/usr/bin/python /opt/openhab/configurations/scripts/mcp3008_read_channel.py 0:60000:REGEX((.*?))]"}
and here is the script. Depending on the SPI channel it should return the ADC value:
#!/usr/bin/python
import spidev
import sys
So the item does not update after 60 seconds. Its zero all the time.
Is there a problem with the python script (return value) or is the execution command wrong?
If i execute the python script with a terminal (insteed of sys.exit(data) i print the values) it works fine.
If i execute the following command in terminal i don’t have any feedback:
"/usr/bin/python /opt/openhab/configurations/scripts/mcp3008_read_channel.py 0"
But when i change the “sys.exit(data)” with “print data” i have a feedback (the ADC value is printed on terminal), but nothing happen, if i execute the script with openHAB.
Is it wrong with print? Do i have to make a rule, which change the state of the Moisture value?
Hi Marc,
ok. Print is ok then, i.e. use print. You do see only the value, correct?
Next thing is the following:
In sitemaps file create a text item:
"Text item=Moisture_Tomatoes"
If you look in your UI, do you see anything now?
Cheers
Björn
PS: Check also your access permissions of your file.
Yes, i already have the item Moistur_Tomatoes in my sitemap and its shown in the UI. In the rules i initialize the value at start up with zero, and the value does not change.
rule "Init Items"
when
System started
then
// Update moisture values
Moisture_Tomatoes.postUpdate(0)
end
Ah yes, i changed the permission to 0755. Thats was wrong. but it is still zero.
I also include the persistence in addons dir (org.openhab.persistence.exec-1.8.1.jar) Do i have to activate the exec persistence in the config file?
Hi Marc,
Normally you should not need a rule.
The text item should change every 60000ms acc. to your exec item.
Is your output eventually a string?
Cheers
Björn
I tried your suggestion, but without success. The Item is still not changing.
If i perform the python script in the terminal, it gives my 100 back.
I implemented exactly like u said. but i m not sure about the permissions.
I set the permission to 0777 recursivly to the directory configurations and all the childs.
The group and owner is pi[1000]. Is it better to set it to root[0]?
Does the binding need root access to the system?
No my preferences in openhab are : USER_AND_GROUP=openhab:openhab
does i require root?
Does the user that runs the openHAB server (usually the user openhab) have permission to access the hardware that your script uses, the same permissions you have at the command prompt? Also, are there environment variables set in your environment that would be needed by the different user under which the openHAB server is running?
Hi Marc,
I agree with watou, thus I proposed to write only “print 100” in you python file.
Further suggestion:
Move your python script to the openhab directory and execute it there.
Cheers
Björn