20001471
Posts: 2
Joined: Tue Feb 04, 2020 6:06 pm

button -> bash command

Tue Feb 04, 2020 6:28 pm

Hi everybody, I'm new and actually I don't know anything about python, infact I'm having troubles.
My goal is to have a little switch that when closed runs a bash command (vlc stream over http) and when open stops that command.

Code: Select all

import RPi.GPIO as GPIO
import time
import os



def start():
    print('start')
    os.system("/home/pi/scripts/mp3stream")

def stop():
    print('stop')
    os.system("/home/pi/scripts/stopstream")

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

while True:
    if GPIO.input(16) == GPIO.HIGH:
        while GPIO.input(16) == GPIO.HIGH:
            time.sleep(0.1)
        start()
    elif GPIO.input(16) == GPIO.LOW:
        while GPIO.input(16) == GPIO.LOW:
            time.sleep(0.1)
        stop()
the command in stopstream is

Code: Select all

pkill vlc
The problem is that it doesn't run stopstream (neither prints stop), I suppose because the vlc command doesn't have an end(?)

I'm more than happy to hear any advice, thanks for your time

DirkS
Posts: 10363
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: button -> bash command

Tue Feb 04, 2020 7:57 pm

Have you connect a button to the correct pin https://pinout.xyz/pinout/pin36_gpio16

20001471
Posts: 2
Joined: Tue Feb 04, 2020 6:06 pm

Re: button -> bash command

Tue Feb 04, 2020 8:28 pm

DirkS wrote:
Tue Feb 04, 2020 7:57 pm
Have you connect a button to the correct pin https://pinout.xyz/pinout/pin36_gpio16
Yeah, start function works

Return to “Python”