-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autostart, Clickwheel, Spotify Credentials... How I made the screen work #22
Comments
I appreciate several of your tweaks, including the need to compile click.c and to use git to clone the dupontgu repository before installing requirements.txt, both of which were necessary. Since I don't have the cute miniTV yet, I have been running spotifypod.py from the command line, either via ssh with the -Y option or from the Pi ZeroW. However, if I don't comment out the spotify_manager.refresh_data() and refresh_devices() lines, I can't get it to work. In fact, the Pi boots up into openbox but the spotifypod.py doesn't run (or rather I suspect it fails because of lack of authorization). On the Pi I have to click the mouse to bring up the openbox menu, then choose terminal, then run the python program. The autorun script probably fails because of the environment setting (as best I have been able to tell). Here's my errors when I allow refresh_data():
What is working is Spotify generally, as I can connect the Pi to my Bluetooth headphones, use Spotify on my phone to play through the Pi device (which it sees as raspotify), and the menus do come up albeit with the wrong key codes for both my Mac keyboard via ssh and my official Pi keyboard on the Pi. Have you made any more progress? |
I solved my spotifypod.py problem by installing the Midori browser on the Pi (not mentioned in any of the posts I read). Run it first on a Pi 4 to get the .cache file or it will crawl. Just got a breakout board for the click wheel today so I will try the click interface. If that works, the only remaining issue will be getting spotifypod.py to run automatically on boot--I think I have all the settings right, but I will recheck again. And of course I have to locate the cute display which is out of stock everywhere. |
@doctorleach omg thank you so much for posting that, I had no idea what might have caused that error and also prevented the whole UI from loading... |
Bitte sehr! |
So i think mine is now trying to run. But my screen says "unable to open display" on two lines and then just shows a command prompt. aNY IDEAS? |
I see you started another thread about this topic, and assume you have read all the comments there. I'm not sure what is causing your problem, so it would help if you could describe your system. What display are you running on the Pi Zero? Are you using a minidisplay or are you just hooked up to a monitor? Or are you ssh'ing into the Pi? There is light at the end of the tunnel as I have all the parts working now, including the click wheel. I just bought a smaller NTSC/PAL display from Adafruit because the 2" one is out of stock and not likely to be back in stock for several months. It's slightly too small for the iPod window but it works. You might also want to look at http://rsflightronics.com/spotifypod, which contains a lot of specific tips. Here's my setup, which works but isn't yet inside the iPod case: |
I’m running on the pi with the 2”tv screen from adafruit. I did use the tips. It has been booting to a black screen for a couple weeks. I was looking at the area where you type in your Spotify ID and secret I have been adding those within the ‘’ commas. But I started to think that that may be incorrect so I deleted the commas and that when it started booting to the double error and the command prompt. |
Here are my lines from /etc/X11/openbox/environment: export SPOTIPY_CLIENT_ID='abcdefg etc' [note: there is no magic to the port 8002; I just tried several and that was the one I happened to be using when I got my .cache file to work. It needs to be consistent with what you entered in your Spotify administration account as the Redirect URI] These lines are also in /etc/xdg/openbox/environment for some reason that I either don't know or can't remember. I also added them to the .bash_profile file in the /home/pi directory and for extra good measure to /root/.bash_profile, but I just looked at the latter file and it has the wrong URI from a previous attempt so it must not be used; ignore it. By the way, the lines need to be preceded by # in the .bash_profile file, as in: I could start removing these from each place one at a time to see which ones are really necessary. It took lots of fiddling to get everything to work, as you have discovered. It seems to me that the spotifypod.py script on your Pi must not be executing or it must be failing. I've partially kept track of my various attempts to get things working but what really did it for me was installing the Midori browser (or any other one). That got me over the Spotify credentials problems I was having because I had no .cache file in the same directory as the spotifypod.py script, and then tweaking the line in the openbox autostart file to read: sudo -H -u pi --preserve-env=SPOTIPY_REDIRECT_URI,SPOTIPY_CLIENT_ID,SPOTIPY_CLIENT_SECRET python3 spotifypod.py & seemed to do the trick. |
I've done all of that now. The display error is gone but its booting to a black backlit screen again. Not sure what else to try. |
Having a # before a line just makes it a comment. I have my environmental variables only in the one file specified in the README and it works (but only when starting from the Pi ofc). What you could try (and what I did too): I would recommend to disable VNC in the raspi-config again to avoid unnecessary slowdowns when booting. You can always enable the VNC server for one session (so until you shutdown/restart) by typing |
I'm red-faced about my # observations; I should have known that it makes a comment but sometimes when trying to solve a problem I try all sorts of permutations, often without thinking them through. But this demonstrates that my including the Spotipy environment variables in .bash_profile for the user pi is not necessary. So I guess it only needs to be in the file "environment" in the openbox configuration directory in /etc/xdg/openbox/ (I see that /etc/X11/openbox just is a pointer so the environment file only exists in one place, namely /etc/xdg/openbox/environment). Another suggestion for zburhop is to make sure that the .cache file is present in the same directory as spotifypod.py (presumably the frontend subdirectory). If the spotify_manager.refresh_data() line is not commented out in view_model.py (and maybe the refresh_devices() line would accomplish the same goal), the .cache file gets updated. I suspect it's updated each time these are called, but in any event you could check the date on the .cache file and it should be reasonably close to the current datetime. If it's hours or days older, that probably indicates that the refresh commands are not being executed or not succeeding. Since you boot to a black screen, it is likely that X11 is starting, but yet another thing to check is that the .bash_profile file for the pi user reads:
As of today, the only parts of the project that aren't working well for me are (1) on the Playlists screen, only several of them appear and you can't scroll down to any more than the first few; some bug in the python code? and (2) the screen stays on the whole time, which sucks up a lot of power. I'm using the smaller version of the Adafruit NTSC/PAL screen. The system call os.system('xset -display :0 dpms force off') in spotifypod.py doesn't seem to work, at least not if I try it from the command line, because I get an error message "server does not have extension for dpms option" |
Yeah I do that kinda stuff too from time to time when trying to fix something and then realize afterwards that it didn't make sense at all so no worries :D The For me it was also important to have no other player playing from Spotify while refreshing data as otherwise an error will occurr. About your playlist bug - try out the changes I made in my pull request #24, maybe that fixes the Playlist problems you are experiencing (it did fix mine!). |
@HerrEurobeat -- Well you are right, your pull request #24 fixes the Playlist problem, so the boss should accept your pull request. Und vielen Dank, mein sehr geehrter Herr (are you German? that's how we were taught in German class in the 1960s). Now I'm down to one problem (assuming I don't break something when I stuff everything in the case), namely getting the display to respond to dpms. I may try your VNC suggestion just to see if I can figure out what happening. I'm also wiping the cobwebs off my trusty 3D printer to try to make the plastic holding pieces from https://www.thingiverse.com/thing:4789155 |
Great to hear that my PR fixes that problem for you too. Yes I'm German und kein Problem :D |
Why go through the trouble with VNC.(just curious) I’m using ssh terminal to talk to the pi already from a windows machine. I never bothered with making this work on a Mac or pc. I just setup the pi with WiFi and ssh from day one and have been trying to work the problem via ssh. Double check what everyone said again tomorrow. Out of curiosity is there a change that someone can make an image file of their working unit sometime. I feel like that would be the easiest way to go as more people inevitably try to build this. An image missing your Spotify credentials obviously lol..... also one bit of confusion for me is how to do the uri address on Spotify. I was just writing http://localhost or whatever at first. |
The idea of using VNC was just to have the exact same environment and "desktop" that you will see on your display. |
I've been struggling to get the GUI to render. The .xsession-errors file shows: I'm assuming this means the openbox autostart can launch because the account isn't being authorized. I've tried various configurations and URIs to try to get my authorization approved. Does anyone have insight into have to resolve this and/or have a link to an easier guide to API authentication process? |
two things to check:
sudo -H -u pi --preserve-env=SPOTIPY_REDIRECT_URI,SPOTIPY_CLIENT_ID,SPOTIPY_CLIENT_SECRET python3 spotifypod.py &
|
Hi guys! I appreciate all ya'lls support on this project. I am so close (at least I hope so, lol) So right now I'm at step 9 and above with OpenBox! Below Ill provide a link to pics of my xinitric, autostart, and openbox path windows. So far when I try to boot my PI and and open my VNC Viewer it will bring me to my login page where I login and I'm brought to a blank screen. 10 seconds later and I'm brought back to the login window. I will add that I was confused in the openbox path window and step 12 with syncing my data. I added the 3 "export" commands above the "set system-wide.." and the spotify refresh commands below the "#to set your keyboard.." command. I assume that's where these commands go? I'm not entirely sure TBH. In step 13 I was confused with "Uncomment and fill the following line:" Well, anywho, I have screenshots of my Openbox windows here: https://drive.google.com/drive/folders/1BQi4NvxVJ_ebSz0gXRTMAb7094VctoYF?usp=sharing Forgive me, as I am not used to openbox.. lol Thank you!! |
I've made some adjustments since my last post and found that there was a problem with the location of one of the files openbox was trying to read. However, I'm still receiving a blank screen with a cursor when I reboot the pi, and the .xsession-errors look like the root of the issue is that my Spoify credentials aren't being authorized. I've followed all the steps to the best of my knowledge and have tried using If someone could provide more details on the authorization process for the client credentials, I would appreciate it. I'm pretty sure that's the only thing preventing the software from running at this point. |
@annalynm I just noticed your post. So what happens is that the spotifypod.py script is being executed [by the way, this can't be if you removed the sudo -H -u pi line in the autostart file, unless you reinstated the previous version without the --preserve-env flag; and make sure sudo is sudo and not Sudo as it appears in your comment; but I would still recommend the --preserve-env flag]. That script in turn calls view_model.py which in turn calls spotify_manager.py to execute the refresh_data() function. This calls into the spotipy library to get authorization via the oauth2.py script. Here you run into a wall. Why is this? I'm not sure, but I assume you have a browser installed on the Pi Zero (like Midori?). I've found this can be the most difficult step and the two times I've done the installation I had to fiddle with it quite a bit (as for example changing the port number on the redirect URI--but you have to change it everywhere including on the admin.spotify.com dashboard) and then the damn thing just worked. Sometimes I think pasting this URL into the browser is what helped create the .cache file in the frontend subdirectory, but I'm not sure; in any event, if you don't have such a .cache file then you haven't been authorized by Spotify yet: (replace XXX with client_id and make sure the redirect URI exactly matches the one in your Spotify project setup on spotify.com, although in this browser address box using URL escape codes like %3A for : and %2F for / ) My redirect URI is http://127.0.0.1:8005, but I've tried a few. It seems to work better if you use a port number, but the actual numbers are arbitrary. |
Tried to follow your link to screen shots but google drive says it's in your trash, so I can't see them. Uncomment means to delete the # character as the start of a line; with the character there the line is ignored / treated as a comment. |
Another suggestion is to create a file called testit.py with the following 3 lines: import spotify_manager and then run it from the command line: python3 testit.py This will only work if you got a .cache file, I think. But if you're good to go you should see output to the screen as it downloads playlists, artists, etc. |
@doctorleach I get a GtK-WARNING **: cannot open display I assume I'm suppose to use the midori browser to paste the authorization URL into, per your previous post. What am I missing about midori? My .xsession-errors are showing I've also made sure that my I used the This is my first time working with a Raspberrypi, so much of this learning experience is process of elimination (and a lot of what I'm trying to eliminate is my own user error). |
Whoops sorry! Here’s the new link: https://drive.google.com/drive/folders/1mtY5qQvxN93nGYmGw7KHVlXaBoLvyQJi |
@annalynm I'm following your saga as I'm in the same situation right now. Did you figure out anything on your authentication issue? I'm at the point where I don't know why the credentials aren't taking. |
@theswz I had to temporarily table this project as the peak of the semester hit, so I haven't made much progress since my last post. The most recent Spotify credential error I received said that the program couldn't the browser to verify the URI. I connected a mouse to the pi and when it boots to the blank screen with a mouse icon I was able to right click to access a drop down menu and run the midori browser from there. I made a bit of progress trying to get the Spotify credentials to authorize there, but I was struggling because I had to keep alternating between having the keyboard and the mouse plugged in and the pi would reboot if I switched them too many times. (I bought a usb splitter, but I haven't had time to work on the project since then). The same drop down menu I was running the midori browser from also has a terminal option listed. I've read elsewhere in these forums that some people had more success getting the Spotipy program to run in there. If you figure it out, please share the secret! I'm hoping to pick the project back up in the next week or so. |
So, I've spent more nights than I should have working on this, my first Raspberry Pi project.
Here are the things I've done following the README file and trying to make it work for myself...
For the ones that don't know, you can code everything from your PC/Mac terminal and you can copy/paste the codes. I didn't know for the first days.
Details on what works and what doesn't at the end of this...
So:
Install Raspberry Pi OS Lite to your Pi and then configure your WiFi on first boot
Install Updates
sudo apt-get update
sudo apt-get upgrade
Install Dependencies
sudo apt install python-setuptools python3-setuptools
sudo apt install python3-pip
sudo curl-sL https://dtcooper.github.io/raspotify/install.sh | sh
sudo apt install install xorg
sudo apt-get install python3-tk
sudo apt-get install redis-server
sudo apt-get install openbox
sudo apt-get install lightdm
sudo apt-get install x11-xserver-utils
Install Dependencies
pip3 install -r requirements.txt
This command didn't work. So I ran the following:
sudo apt-get install git
git clone https://github.com/dupontgu/retro-ipod-spotify-client
After this:
cd /home/pi/retro-ipod-spotify-client/frontend/
To finally run this...
pip3 install -r requirements.txt
Install pi-btaudio
git clone https://github.com/bablokb/pi-btaudio.git
cd pi-btaudio
sudo tools/install
All worked fine. For bluetooth pairing and instructions, go to https://github.com/bablokb/pi-btaudio
wget https://github.com/joan2937/pigpio/archive/master.zip
unzip master.zip
cd pigpio-master
make
sudo make install
I don't know if it works because I haven't been able to use the Clickwheel. Still don't know it it's a hardware or software issue...
Setup Spotify API
Create a Spotify Developer Account, then create an app where you will get your Client ID, Client Secret, and create a Redirect URI.
I recommend watching this video and try to make something like the link on README. I think it hasn't worked 100% right for me though...
Disable Screen Blanking
sudo raspi-config
Display Option > Screen Blanking > OFF / Disable
Disable Cursor and Screen Savers
Add or Create and Add this:
sudo nano /root/.bash_profile
Then:
'#!/bin/bash'
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx -- -nocursor
# Disable any form of screen saver / screen blanking / power management
xset s off
xset s noblank
Configure xinitrc
sudo nano /etc/X11/xinit/xinitrc
Inside, make sure the following is there:
#!/bin/sh
# /etc/X11/xinit/xinitrc
# global xinitrc file, used by all X sessions started by xinit (startx)
# invoke global X session script
#. /etc/X11/Xsession'
exec openbox-session #-> This is the one that launches Openbox ;)`Run "spotifypod.py" with Autostart
sudo nano /etc/xdg/openbox/autostart
and add the following command to launch spotifypod.py:
I made some changes and didn't use the /fork/ folder as in README
cd /home/pi/retro-ipod-spotify-client/frontend/
sudo -H -u pi python3 spotifypod.py &
sudo /home/pi/retro-ipod-spotify-client/clickwheel/click &
There is no
click
so in order to get that:cd /home/pi/retro-spotify-client/clickwheel
gcc -Wall -pthread -o click click.c -lpigpio -lrt
It returns some warnings but everything is fine. I guess...
Spotify Credentials
'sudo nano /etc/xdg/openbox/environment'
Add you credentials:
export SPOTIPY_CLIENT_ID='your_SPOTIPY_CLIENT_ID'
export SPOTIPY_CLIENT_SECRET='your_SPOTIPY_CLIENT_SECRET'
export SPOTIPY_REDIRECT_URI='your_SPOTIPY_REDIRECT_URI'
Syncronize Spotify Data
Synchronizing Spotify data! Last but not least, if you want to make sure all your playlists artists, etc are synchronized every time you turn on your Spotypod, you can simply modify the script
view_model.py
with the following at line 16:
#spotify_manager.refresh_devices()
spotify_manager.refresh_data()
instead of calling
refresh_device
, you can executerefresh_data
. This will sync all your data and then will executerefresh.devices
. This will make the boot up way slower! but it will synchronize every single time you switch on :). If you don't run at least oncerefresh_data()
no playlist, artist or anything related with your account will be displayed!I had errors with this part so I left it as it was...
sudo nano /etc/default/raspotify
Uncomment and fill the following line:
OPTIONS="--username <USERNAME> --password <PASSWORD>"
And maybe you want also to consider the following:
# The displayed device type in Spotify clients.
# Can be "unknown", "computer", "tablet", "smartphone", "speaker", "tv",
# "avr" (Audio/Video Receiver), "stb" (Set-Top Box), and "audiodongle".
DEVICE_TYPE="smartphone"
All good. I also changed the Device Name
sudo nano /boot/config.txt
uncomment (erase #):
sdtv_mode=2
comment add (#)
hdmi_force_hotplug=1
then add:
hdmi_ignore_hotplug=1
After this if it throws error for displaying
spotifypod.py
try the following command:export DISPLAY=:0.0
So that's what I've got.
The app doesn't autostart. When I start it I get the frontend screen that shows NOW PLAYING when I play a song on my phone. I still haven't been able to work with the clickwheel, it is running with no errors apparently, but it doesn't work with my clickwheel at least so I haven't tried the app on itself.
I connected the Pi to my bluetooth speaker and from my phone I used the Pi as a Remote Device and I got Spotify audio out of it. Is it able to choose it's own songs and play them, I still don't know.
I hope this works for someone and if anybody has any info on how to solve the rest of this, please share hahaha.
Cheers and thanks @dupontgu for this fun project.
The text was updated successfully, but these errors were encountered: