Stop openhab, do not (!) ‘clear’ the gpio and start openhab again. Following errors on all defined GPIOs:
2015-09-28 08:04:43.457 [ERROR] [.o.b.gpio.internal.GPIOBinding] - Error occured while creating backend object for item Home_Doorbell, exception: Device or resource busy
In this case the GPIOs cannot be controlled via openHAB (although on your UI it does indicate that it switches and works properly)
Stop openhab, clear the GPIOs (echo > /sys/class/gpio/unexport) and start openhab again
No errors found / all working as expected
Openhab is running correctly and GPIOs (input and output) work fine. I switched ON the buzzer, after that I added a comment in the default.items file and saved it. Following happened:
2015-09-28 08:40:16.652 [INFO ] [org.openhab.model.script.test ] - Buzzer state change. State = ON
2015-09-28 08:40:51.555 [INFO ][c.internal.ModelRepositoryImpl] - Refreshing model ‘hag.items’
2015-09-28 08:40:51.615 [INFO ][org.openhab.model.script.test ] - Buzzer state change. State = Undefined
2015-09-28 08:40:53.940 [INFO ][org.openhab.model.script.test ] - Doorbell state change. State = Undefined
2015-09-28 08:40:54.665 [INFO ][org.openhab.model.script.test ] - Buzzer state change. State = OFF
2015-09-28 08:40:54.705 [INFO ][org.openhab.model.script.test ] - Doorbell state change. State = OPEN
NOTE: Changing the .rules does not result in incorrect states.
Thanks, four questions
1 :How does your .cfg file look like?
2:How does your autostart file look like, i guess there is where you have put your :
echo unexporting all
sh -c “echo 2 > unexport”
sh -c “echo 3 > unexport”
…
I unexported all GPIO, even though they might not have been used, is that an issue? The unexport is not run as sudo right? I have openhab installed in /home/pi/Openhab and i am logged in the user pi. Do i need to alter some file permission for the/sys/class/gpio in the reset script?
Do you use an autoreset script in your /etc/rs.local ? Because my pi goes down ones per day in average, so I need the autostart…(think i need to put a capasitor on the power line, because my pc power supply fails ones in a while for a few seconds.) I have my pi powered through the 5v gpio pin, do you power it with usb?
3: My final question is how do you kill openhab when its not run in osgi mode?
4: How does your rule file look like? I gues you have your contact item changing the state of the switch item? Did you use internal pullup on the contact item or did you put a 10kohm resistor between vcc and ground?
openhab.cfg - for GPIO test I did not touch the config
Unexporting the GPIOs - created simple script (at the moment I do manually run it) ./cleangpio.sh. Even when there is no need to unexport you can run these commands. You need to run it in sudo (otherwise gpio dir not accessible)
For basic gpio tests I just start / close / status “openhab” with /etc/init.d/openhab <start|stop|status>
.rules - for above tests I used the basic lines below. Yes, I used a pullup resistor for the doorbell (only 1k) - however also used an opto isolator (4N25) to separate the 2 circuits. For the buzzer (output) of course no resistor used. When you are interested I can send you the schematics.
rule “Bell detection”
when
Item Home_Doorbell received update
then
var String Timestamp = String::format( “%1$tH:%1$tM:%1$tS %1$tY-%1$tm-%1$td”, new Date() )
logInfo(“test”, "Doorbell state change. State = " + Home_Doorbell.state)
sendMail(“me@blabla.com”, “Doorbell state received: (” + Home_Doorbell.state + “)”, "Doorbell rang at " + Timestamp)
end
rule “Buzzer state”
when
Item Home_Buzzer received update
then
logInfo(“test”, "Buzzer state change. State = " + Home_Buzzer.state)
end
rule “HAG system start”
when
System started
then
var String Timestamp = String::format( “%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS”, new Date() )
sendMail(“me@blabla.com”, “HAG system started”, "The HAG system started on: " + Timestamp)
end
I will see if it still works next time it reboots…
I have a few question regarding
2 .rules - for above tests I used the basic lines below. Yes, I used a pullup resistor for the doorbell (only 1k) - however also used an opto isolator (4N25) to separate the 2 circuits. For the buzzer (output) of course no resistor used. When you are interested I can send you the schematics.
Can you post the schematic, why did you use 4n25? Is it needed? Did you connect the switch to ground or 3v?
And how did you tell your doorbell contact to set pin 20 high(home buzzer item) ?
I guess it should be something like this or:
rule "Bell detection"
when
Item Home_Doorbell received update
Home_Buzzer.state = + Home_Buzzer.state
then
end
Below doorbell schematic. Used opto coupler to isolate the doorbell circuit (12vdc) from my Raspberry. Could use transistor logic as well but I decided to physically separate them (the circuit basically detects the current when doorbell rings / inside the 4n25 a LED “activates” the transistor).
echo unexporting all
sudo sh -c 'echo "2" > /sys/class/gpio/unexport'
sudo sh -c 'echo "3" > /sys/class/gpio/unexport'
sudo sh -c 'echo "4" > /sys/class/gpio/unexport'
sudo sh -c 'echo "17" > /sys/class/gpio/unexport'
sudo sh -c 'echo "27" > /sys/class/gpio/unexport'
sudo sh -c 'echo "22" > /sys/class/gpio/unexport'
sudo sh -c 'echo "10" > /sys/class/gpio/unexport'
sudo sh -c 'echo "9" > /sys/class/gpio/unexport'
sudo sh -c 'echo "11" > /sys/class/gpio/unexport'
sudo sh -c 'echo "5" > /sys/class/gpio/unexport'
sudo sh -c 'echo "6" > /sys/class/gpio/unexport'
sudo sh -c 'echo "13" > /sys/class/gpio/unexport'
sudo sh -c 'echo "19" > /sys/class/gpio/unexport'
sudo sh -c 'echo "26" > /sys/class/gpio/unexport'
sudo sh -c 'echo "14" > /sys/class/gpio/unexport'
sudo sh -c 'echo "15" > /sys/class/gpio/unexport'
sudo sh -c 'echo "18" > /sys/class/gpio/unexport'
sudo sh -c 'echo "23" > /sys/class/gpio/unexport'
sudo sh -c 'echo "24" > /sys/class/gpio/unexport'
sudo sh -c 'echo "25" > /sys/class/gpio/unexport'
sudo sh -c 'echo "8" > /sys/class/gpio/unexport'
sudo sh -c 'echo "7" > /sys/class/gpio/unexport'
sudo sh -c 'echo "12" > /sys/class/gpio/unexport'
sudo sh -c 'echo "16" > /sys/class/gpio/unexport'
sudo sh -c 'echo "20" > /sys/class/gpio/unexport'
sudo sh -c 'echo "21" > /sys/class/gpio/unexport'
echo Done unexporting
this how the unexporting script needs to look like, note the differnces between " and ’
I don’t understand why but it works now, at least for time being…
And thanks joroen, i think I also will add the buzzer to my setup… My only problem now is that I have run out of GPIO’s, so I might have to add arduino or something else:)
2015-09-18 18:49:31.355 [ERROR] [m.r.internal.engine.RuleEngine] - Error during the execution of startup rule 'Initialize light states': Could not invoke method: org.openhab.model.script.actions.BusEvent.postUpdate(org.openhab.core.items.Item,java.lang.Number) on instance: null
2015-09-18 18:49:32.193 [ERROR] [m.r.internal.engine.RuleEngine] - Error during the execution of startup rule 'Initialize heating states': Could not invoke method: org.openhab.model.script.actions.BusEvent.postUpdate(org.openhab.core.items.Item,java.lang.Number) on instance: null
2015-09-18 18:49:32.966 [ERROR] [m.r.internal.engine.RuleEngine] - Error during the execution of startup rule 'Initialize contact states': Could not invoke method: org.openhab.model.script.actions.BusEvent.postUpdate(org.openhab.core.items.Item,java.lang.Number) on instance: null
this is what I see as user rights in gpio before i start openhab
pi@raspberrypi ~ $ ls -l /sys/class/gpio/
total 0
-rwxrwx--- 1 root gpio 4096 Oct 9 09:22 export
lrwxrwxrwx 1 root gpio 0 Jan 1 1970 gpiochip0 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpiochip0
-rwxrwx--- 1 root gpio 4096 Oct 9 09:23 unexport
2015-10-09 09:41:15.949 [INFO ] [runtime.busevents ] - Heating_FF_Bath state updated to Undefined
2015-10-09 09:41:16.015 [INFO ] [runtime.busevents ] - Light_Module2 state updated to Undefined
2015-10-09 09:41:16.037 [INFO ] [runtime.busevents ] - Light_Module1 state updated to Undefined
2015-10-09 09:41:16.063 [INFO ] [runtime.busevents ] - Light_Balcony state updated to OFF
2015-10-09 09:41:16.170 [INFO ] [runtime.busevents ] - Light_Module1 state updated to OFF
2015-10-09 09:41:16.674 [INFO ] [runtime.busevents ] - Light_Module2 state updated to OFF
so what am I doing wrong? I now start and stop openhab by using
sudo sh resetGpio.sh
sudo sh /home/pi/openhab/start.sh
There are a lot of tutorials out there with all sorts of instructions for how and where to put it. Most are out of date.
The preferred installation approach on Debian based Linux machines (Raspbian, Ubuntu, Mint, etc) is to use apt-get as described here. This will create the openhab user and group, set openhab to start as a service, let you upgrade b
oth openHAB and addons automatically, and put the various parts of openhab in standardized locations
Config: /etc/openhab
openHAB home: /usr/share/openhab
addons: /usr/share/openhab/addons
webapps (where Habmin goes, location of icons): /usr/share/openhab/webapps
Will reinstall it tonight and try it out again, I had it installed in /home/pi everything… Because that was what a probably outdated tutorial on instructables said…
Send me a link to that Instructables or post it here. I know @watou has contacted the author of at least one Instructable author about his outdated instructions but I don’t think this was the same one. At a minimum I can put a comment on it pointing to the more up to date instructions.
Couldn’t find the one with /home/pi right now, have it bookmarked on my personal laptop somwhere.
A final note, how do I change the state of a gpio in my rule, sendCommand(Module1, ON) does not do the the trick if its ON and i want to set it to off.
Reinstalling seems so far to work, thanks rlkoshak:) However how can I send the command to turn on my light from my switch, the log file shows that its detected state change but this sendCommand(Light_Kitchen_Item, ON) does not turn it on.
It should just be a matter of configuring the item correctly. Unfortunately I’ve not used GPIO from openHAB so I have no experience to draw upon to help.
Frame label="Debug" {
Group item=Lights icon="light"
Group item=Switches label="Contacts" icon="kitchen"
Group item=Heating label="Heating" icon="bath"
Group item=rgb label="RGB Switch"
}
and this is my rule file:
import org.openhab.core.library.type.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openab.core.types.command
import org.openhab.core.items.genericitem
import java.util.Date
import java.text.SimpleDateFormat
rule "Switch detection"
when
Item Contact_LivingRoom1 received update
then
var String Timestamp = String::format( "%1$tH:%1$tM:%1$tS %1$tY-%1$tm-%1$td", new Date() )
logInfo("test", "Contact_LivingRoom1 state change. State = " + Contact_LivingRoom1.state)
sendCommand("Light_Kitchen", "ON")
executeCommandLine("echo halla")
sendMail("skatun@gmail.com", "Contact_LivingRoom1 state received: (" + Contact_LivingRoom1.state + ")", "Contact switched at " + Timestamp)
end
rule "HAG system start"
when
System started
then
var String Timestamp = String::format( "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS", new Date() )
sendMail("skatun@gmail.com", "HAG system started", "The HAG system started on: " + Timestamp)
end