kappaloot
Posts: 11
Joined: Wed Aug 01, 2012 9:52 pm

Starting a program when button is pressed

Wed Feb 18, 2015 11:53 am

Hello, i want my raspberry to run deluged when i press a button.
This is my code:

Code: Select all

import RPi.GPIO as GPIO
import time
from subprocess import call

GPIO.setmode(GPIO.BCM)
GPIO.setup(16,GPIO.IN,pull_up_down=GPIO.PUD_UP)

flag = False
while True:
		input = GPIO.input(16)
		if(input == False):
			if(flag == False):
				print "calling deluged"
				call(["deluged"])
				flag = True
				time.sleep(0.2)
			else:
				print "killing deluged"
				call(["pkill","deluged"])
				flag = False
				time.sleep(0.2)
		
The button works, when i press it the print functions are called, but it doesn't start deluged.
What am i doing wrong?

Thank you ;)


Edit: i'm trying to start deluged with a script

Code: Select all

 
#!/bin/bash

deluged
and calling it with call(["/home/pi/myscript.sh"],shell = True)

but it doesn't work

kappaloot
Posts: 11
Joined: Wed Aug 01, 2012 9:52 pm

Re: Starting a program when button is pressed

Wed Feb 18, 2015 4:49 pm

ok i solved.
Used a shell script

Code: Select all

sudo -u pi "/usr/bin/deluged"
deluged started regularly but as root and didn't use the settings i wanted and i couldn't "see" it

Return to “Python”