Hi Pilluli,
Thanks so much for this plugin. AWESOME concept and it will help me a lot if I can get it working. I have literally tried everything now including all the suggestions in this thread.
What I am trying to do:
I have an 8 channel relay board linked to the GPIO pins on the Pi. I have written 3 python scripts: raspbmc_on.py to turn the switch on, raspbmc_off.py to turn it off and raspbmc_off_timer.py to turn the switch off after 10 minutes.
The code:
raspbmc_on.py
Code:
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
import random
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(3, GPIO.OUT)
GPIO.setup(5, GPIO.OUT)
GPIO.setup(7, GPIO.OUT)
color = random.randrange(1,5)
print color
if color == 1:
GPIO.output(7, False)
GPIO.output(3, False)
GPIO.output(5, False)
elif color == 2:
GPIO.output(7, False)
GPIO.output(3, True)
GPIO.output(5, False)
elif color == 3:
GPIO.output(7, False)
GPIO.output(3, False)
GPIO.output(5, True)
elif color == 4:
GPIO.output(7, True)
GPIO.output(3, False)
GPIO.output(5, False)
elif color == 5:
GPIO.output(7, False)
GPIO.output(3, True)
GPIO.output(5, False)
else:
GPIO.output(7, False)
GPIO.output(3, False)
GPIO.output(5, False)
raspbmc_off.py
Code:
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(3, GPIO.OUT)
GPIO.setup(5, GPIO.OUT)
GPIO.setup(7, GPIO.OUT)
color = "off"
if color == "red":
GPIO.output(3, False)
GPIO.output(5, True)
GPIO.output(7, True)
elif color == "green":
GPIO.output(5, False)
GPIO.output(3, True)
GPIO.output(7, True)
elif color == "blue":
GPIO.output(7, False)
GPIO.output(3, True)
GPIO.output(5, True)
elif color == "white":
GPIO.output(7, False)
GPIO.output(3, False)
GPIO.output(5, False)
elif color == "tq":
GPIO.output(7, False)
GPIO.output(3, True)
GPIO.output(5, False)
elif color == "purple":
GPIO.output(7, False)
GPIO.output(3, False)
GPIO.output(5, True)
elif color == "yellow":
GPIO.output(7, True)
GPIO.output(3, False)
GPIO.output(5, False)
else:
GPIO.output(7, True)
GPIO.output(3, True)
GPIO.output(5, True)
raspbmc_off_timer.py
Code:
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
import datetime
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(3, GPIO.OUT)
GPIO.setup(5, GPIO.OUT)
GPIO.setup(7, GPIO.OUT)
i = datetime.datetime.now()
scriptstartdatetime = ("%s" % i)
i = datetime.datetime.now()
currentdatetime = i
offdatetime = i + datetime.timedelta(minutes = 10)
while(currentdatetime < offdatetime):
time.sleep(1)
i = datetime.datetime.now()
currentdatetime = i
print (currentdatetime)
GPIO.output(7, True)
GPIO.output(3, True)
GPIO.output(5, True)
I tried executing the python scripts directly from your plugin and it did not work. I then proceeded to try and run the python scripts through command shell and it did not work either as you need to execute the scripts with SUDO. Yes I did make them executable with CHMOD.
I then proceeded to create 3 new sh scripts. exec_raspbmc_on.sh which executes raspbmc_on.py with SUDO, exec_raspbmc_off.sh and exec_raspbmc_off_timer.sh to do the same with their matching python scripts.
The code for the sh scripts:
exec_raspbmc_on.sh
Code:
#!/bin/bash
sudo /home/pi/raspbmc_on.py
exec_raspbmc_off.sh
Code:
#!/bin/bash
sudo /home/pi/raspbmc_off.py
exec_raspbmc_off_timer.sh
Code:
#!/bin/bash
sudo /home/pi/raspbmc_off_timer.py
After I did this I could execute the sh scripts through command line without SUDO which in turn executed their respective python scripts with SUDO and it worked perfectly. The switches turn on and off as expected.
The problem is that when I pointed your plugin to those sh scripts, once again it did not work.
I even tried updating the settings.xml file manually to point directly to the python scripts and I even tried setting the value to "SUDO /home/pi/raspbmc_on.py" and nothing.
I tried creating python scripts which is the same as the sh scripts which executes the on off python scripts with SUDO. Once again, executing these without sudo in terminal executes the on off scripts with sudo and everything works yet hooking them up with the plugin does not work.
I also checked the XBMC log and opened your code and I cannot find the log entries that you write to the xbmc log anywhere in my xbmc log? It looks like its not even trying to execute the scripts yet the addon is installed, enabled and configured?
I am relatively new to linux and this whole python raspberry pi adventure and I know the code is not optimal but I will optimize it once I can get it running. I am sure I am probably missing something obvious but for the life of me it has been a 3 day battle and I just cannot get it working.
Please Please PLEASE help me to get this running.
Thanks in advance.
J