Python Terminal (updates and FIFO)

Im writing an app to control pianobar on my my linux server using Blynk as the remote control. Pianobar plays pandora and it works great from the console (it is a console app). Im having trouble getting past two issues, one pretty easy i think and one more complex.

  1. When i turn up the volume using the step widget, i want it to write to the V10 terminal widget, “Volume Up”. And same for “Volume Down”. Its pin V4 in my script. But what i get is a single “Volume Up” no matter how many times i push it. However, the very first time i push “Volume Down”, all the messages for the “volume up” that were banked up, come out to the screen. If i push up 8 times, it will show 1, then when i push down, it will show the 7 UP and 1 down. I know im missing something easy, but i think i been staring at it too long and could use another pair of eyes.

  2. I want the output of the console program to be directed to a FIFO or anything where i could pull what comes from the console app to the terminal window. I don’t think this is ready for Blynk troubleshooting yet, but i figured if im asking for help, i might as well go full force. When i use the V5 / V6 button widgets, i want the results sent to the V10 terminal. All the stuff that is commented out of the script is the stuff i’ve tried that i felt was going somewhere. (i tried alot more than whats shown)

Here is my Code

import os
from threading import Thread
import sys
import errno
import BlynkLib

FIFO = '/root/.config/pianobar/ctl'
#FIFOP = '/root/.config/pianobar/ctlp'

except OSError as oe:
    if oe.errno != errno.EEXIST:
#    os.mkfifo(FIFOP)
#except OSError as oe:
#    if oe.errno != errno.EEXIST:
#        raise

BLYNK_AUTH = '<Auth>'
blynk = BlynkLib.Blynk(BLYNK_AUTH, server="", port=8080)
#blynk = BlynkLib.Blynk(BLYNK_AUTH)
playing = "0"

def v1_write_handler(value):
    global playing
    if value[0] == '1':
        print  '1';
#        fifop = open(FIFOP, "w")
#        fifop.write(
        os.system('/usr/bin/pianobar &')
#        os.system('/usr/bin/pianobar > FIFOP &')
#        output = subprocess.Popen(["/usr/bin/pianobar", "&"], stdout=subprocess.PIPE).communicate()[0]
        blynk.virtual_write(10, "Power On\n")
        blynk.virtual_write(2, "play")
        playing = "1"
        fifo = open(FIFO, "w")
    if value[0] == '0':
        if playing == "0":
        blynk.virtual_write(2, "stop")
        blynk.virtual_write(10, "Power Off\n")
        fifo = open(FIFO, "w")
#        fifop.close()
        playing = "0"
        print  '0'

def v2_write_handler(value):
    if playing == "1":
        if value[0] == 'play':
            print  'play'
            blynk.virtual_write(10, "Play\n")
            fifo = open(FIFO, "w")
        if value[0] == 'stop':
            print  'stop'
            blynk.virtual_write(10, "Pause\n")
            fifo = open(FIFO, "w")
        if value[0] == 'prev':
            print  'prev'
            blynk.virtual_write(10, "Previous (not implemented in Pianobar\n")
            fifo = open(FIFO, "w")
        if value[0] == 'next':
            print  'next'
            blynk.virtual_write(10, "Next\n")
            fifo = open(FIFO, "w")

#  New Volume, not  setup yet
def v3_write_handler(value):
    print value[0]

#  Old Volume, something broke when i messes
def v4_write_handler(value):
    if playing == "1":
        print value[0]
        if value[0] == '1':
            blynk.virtual_write(10, "Volume Up\n")
            blynk.sync_virtual(10)  #  Did not help but left in until i can fix it.
            fifo = open(FIFO, "w")
        if value[0] == '-1':
            blynk.virtual_write(10, "Volume Down\n")
            fifo = open(FIFO, "w")

def v5_write_handler(value):
    if playing == "1":
        if value[0] == '1':
            blynk.virtual_write(10, "Get Info on Current Song\n")
            fifo = open(FIFO, "w")

def v6_write_handler(value):
    if playing == "1":
        if value[0] == '1':
            blynk.virtual_write(10, "Get Info on Next Song\n")
            fifo = open(FIFO, "w")

def blynk_connected():
    print  'connected';

#def printtoterm():
#    fifopr = open(FIFOP, "r")
#    for line in fifopr:
#        blynk.virtual_write(10, line)
#        print "Received: " + line,
#    fifopr.close()

while True:
#    Thread(target = printtoterm).start()

Here is my Clone Project


I would have to sit down and play with the program to be sure… but as I see you have Send Step YES that should meen that each button press is actually sending a -1 or a 1 depending on back or forward button pressed, and the Step value you set. This is intentional and ment for simple “step” (AKA simple encoder) like programming.

To actually “step” through your range you want Send Step NO

Yes, the fact that the value shown on the widget never changes from range values to neg/pos steps (using whatever step value is set) adds to the confusion… and it has been an often repeated request that has simply gone unheeded :frowning:

Opps… now that I scan through your code, I see you intend to use the Step method… which basically means your widget range (-30 to 5) is meaningless, and must be counted and calculated in code.

I’ll play with it some more, but i was just reading what was sent with the step on. when it sends a (1), i up the volume and when it sends a (-1) i down the volume. i kinda wasnt too worried about the value of the volume at the moment, im hoping to move it to a slider at a later point. but i still appreciate the second set of eyes.