From b46a20f6f9b023d710ea9a83dc3d5b5cf7ba7734 Mon Sep 17 00:00:00 2001 From: Tilman Date: Wed, 11 Oct 2017 01:13:07 +0200 Subject: [PATCH] details --- code/piplayer3.py | 25 ++++++++++++++++++------- notes.md | 29 ++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/code/piplayer3.py b/code/piplayer3.py index 3f777be..ecd25ba 100644 --- a/code/piplayer3.py +++ b/code/piplayer3.py @@ -9,7 +9,7 @@ import os import requests import urllib -logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s - %(message)s') +logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s - %(message)s') logging.info('Initializing') # Configuration @@ -20,7 +20,7 @@ SOUND_SCAN_FAIL = "file:///home/pi/sounds/fail.mp3" SOUND_PLAYBACK_ERROR = "file:///home/pi/sounds/error.mp3" QR_SCANNER_TIMEOUT = 3 -MOPIDY_URL = 'http://127.0.0.1:6680/mopidy/rpc' +MOPIDY_RPC_URL = 'http://127.0.0.1:6680/mopidy/rpc' MUSIC_EXTENSIONS = ('.aac', '.ac3', '.aiff', '.amr', '.au', '.flac', '.m4a', '.mid', '.mka', '.mp3', '.ogg', '.ra', '.voc', '.wav', '.wma') # photo sensor on PIN 17 @@ -60,7 +60,7 @@ def call(method, params=None): else: json = '{"jsonrpc": "2.0", "id": 1, "method": "' + method + '" , "params": ' + params + '}' - response = requests.post(MOPIDY_URL, data=json) + response = requests.post(MOPIDY_RPC_URL, data=json) logging.debug(response.text) return response @@ -70,7 +70,7 @@ def add_uri(filename): def play_sound(filename): call('core.tracklist.clear') - logging.debug('Cleared tracklist, adding ' + filename) + logging.debug('Cleared tracklist, now playing ' + filename) add_uri(filename) call('core.playback.play') @@ -86,6 +86,7 @@ def list_files(dir): def btn1_callback(channel): + logging.debug("PREV") json = call('core.playback.get_time_position').json() position = json['result'] if (position < 4): @@ -94,6 +95,7 @@ def btn1_callback(channel): call('core.playback.seek', '{ "time_position": 0 }') def btn2_callback(channel): + logging.debug("PLAY/PAUSE") json = call('core.playback.get_time_position').json() state = json['result'] if (state == 'playing'): @@ -102,6 +104,7 @@ def btn2_callback(channel): call('core.playback.play') def btn3_callback(channel): + logging.debug("NEXT") call('core.playback.next') @@ -111,6 +114,10 @@ GPIO.add_event_detect(PIN_NEXT, GPIO.FALLING, callback=btn3_callback, bouncetime try: + # FIXME turn this into a proper service and wait for the network interface (and mopidy) + # https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/#systemd + time.sleep(20) + play_sound(SOUND_OK) while True: @@ -155,20 +162,24 @@ try: if (not os.path.isfile(full_path)): logging.debug("Not a file, recursively add all audio files in directory") filenames = list_files(full_path) + playback_started = False for filename in filenames: if filename.lower().endswith(MUSIC_EXTENSIONS): add_uri("file://" + urllib.parse.quote(filename)) + if (not playback_started): + call('core.playback.play') + playback_started = True + else: logging.debug("It's a file") add_uri("file://" + urllib.parse.quote(full_path)) + call('core.playback.play') else: logging.debug("URL, open directly") add_uri(qr_code) - - logging.debug("Start playback") - call('core.playback.play') + call('core.playback.play') except subprocess.CalledProcessError as e: logging.error("Error starting playback, mocp returned {}".format(e.returncode)) diff --git a/notes.md b/notes.md index 6b20906..96f1d48 100644 --- a/notes.md +++ b/notes.md @@ -5,7 +5,7 @@ https://www.raspberrypi.org/documentation/remote-access/ssh/ --> file "ssh" on boot partition -[basic setup] +[basic setup] -lirc -moc sudo apt-get install python-pip sudo apt-get install python3-pip @@ -86,7 +86,7 @@ client_secret = sudo apt-get install git -### moped web client https://github.com/martijnboland/moped +### moped web client https://github.com/martijnboland/moped (nach http://krausix.de/mopidy-raspberry-pi/) sudo mkdir /opt/webclient cd /opt/webclient sudo git clone https://github.com/martijnboland/moped.git @@ -113,12 +113,31 @@ client_secret = sudo mkdir /media/share sudo chmod 777 /media/share sudo nano /etc/rc.local + # make /tmp on RAM disk writable + chmod 777 /tmp + + # disable HDMI + /usr/bin/tvservice -o + # mount share - sudo mount -t cifs -o user=guest,password= //192.168.1.110/hidrive/Media/Audio /home/pi/share - #sudo mount -t cifs -o user=guest,password= //192.168.1.125/hidrive/Media/Audio /media/share + sudo mount -t cifs -o user=guest,password= //192.168.1.125/hidrive/Media/Audio /media/share + + # start piplayer + su pi -c 'python3 /home/pi/piplayer3.py >> /tmp/piplayer3.log 2>&1 &' sudo reboot +### fstab +proc /proc proc defaults 0 0 +/dev/mmcblk0p1 /boot vfat defaults,ro 0 2 +/dev/mmcblk0p2 / ext4 defaults,noatime,ro 0 1 +tmpfs /var/log tmpfs nodev,nosuid 0 0 +tmpfs /var/tmp tmpfs nodev,nosuid,mode=1777 0 0 +tmpfs /var/cache tmpfs nodev,nosuid,mode=1777 0 0 +tmpfs /tmp tmpfs nodev,nosuid,mode=1777 0 0 +tmpfs /home/pi/.config tmpfs nodev,nosuid,mode=1777,uid=pi 0 0 +tmpfs /var/lib/mopidy/.config tmpfs nodev,nosuid,mode=1777,uid=mopidy 0 0 + @@ -154,7 +173,7 @@ curl -X POST -H Content-Type:application/json -d '{"jsonrpc": "2.0", "id": 1, "m curl -X POST -H Content-Type:application/json -d '{"jsonrpc": "2.0", "id": 1, "method": "core.tracklist.add" , "params": {"uri": "file:///home/pi/sounds/scanning.mp3"}}' http://192.168.1.142:6680/mopidy/rpc curl -X POST -H Content-Type:application/json -d '{"jsonrpc": "2.0", "id": 1, "method": "core.tracklist.add" , "params": {"uri": "http://www.wdr.de/wdrlive/media/kiraka.m3u"}}' http://192.168.1.142:6680/mopidy/rpc curl -X POST -H Content-Type:application/json -d '{"jsonrpc": "2.0", "id": 1, "method": "core.tracklist.add" , "params": {"uri": "spotify:user:tliero:playlist:08pbBkT5Vd2xXhxrMCVbAH"}}' http://192.168.1.142:6680/mopidy/rpc - +curl -X POST -H Content-Type:application/json -d '{"jsonrpc": "2.0", "id": 1, "method": "core.tracklist.add" , "params": {"uri": "spotify:album:4GmD0wNIlc47j8XcCECuVH"}}' http://192.168.1.142:6680/mopidy/rpc