RafaPolit / moode-spotify-connect-web

moOde OS - spotify-web-connect install instructions and required files.
MIT License
15 stars 4 forks source link

'Illegal instruction' output when tying to run the spotify-connect.sh #9

Open schnellecom opened 6 years ago

schnellecom commented 6 years ago

I have the Rpi zero w and when I try to run the spotify connect.sh it gives this output:

pi@moode:~/spotify $ ./spotify-connect.sh Loading Spotify library... Last.fm: incomplete credentials, not launched Device has no native mute min_volume_range: 0 Using libspotify_embedded version: release-esdk-1.20.0-v1.20.0-g594175d4 Illegal instruction

I have tried changing the name of the device in main.py because I got that error and tried changing the master in the spotify-connect.sh.

Also I noticed that the spotify-connect-web.service is constantly restarting.

I am using a generic USB sound card which outputs sound with the command provided in the instructions. I also tried two different ones so I don't think(hope) that is the issue

Thanks already for the help Best Regards Lukas

RafaPolit commented 6 years ago

This one is probably beyond me. If the illegal instruction is on the libspotify_embedded, then we are toast. We depend on that file working.

Did you make any changes at all to main.py? Was the original build successful?

Maybe it's worth rebuilding making sure everything outputs the 'expected' results (specially the build).

What OS are you running?

schnellecom commented 6 years ago

First yes I changed the main.py in the beginning adding this what you described here: http://moodeaudio.org/forum/showthread.php?tid=14&pid=1507#pid1507

Yes the original build was successful and the sound command did output sounds.

I have the 2018-03-13-raspbian-stretch-lite build with moode Release: 4.1 2018-04-02

How do I do a complete rebuild/ uninstall so I can reinstall?

Already thanks for the support. If you need any additional logs or info just tell me

RafaPolit commented 6 years ago

First of all, that change is only needed if you the error: "No module named wsgi".

If not, please do not modify the file and try to see what happens. Is there a chance that, when editing the main.py file you corrupted the file by omitting a space or something else?

So, first question:

Please post the output of:

$ cd /home/pi/spotify/spotify-connect-web
$ cat main.py
schnellecom commented 6 years ago

I changed it only after I received the "No module named wsgi" error. I also just tried to reverse the changes and removed the 'py' and I got the error again.

Here is my main.py: (w/o the change to pywsgi)

!/usr/bin/env python

First run the command avahi-publish-service TestConnect _spotify-connect._tcp 4000 VERSION=1.0 CPath=/login/_zeroconf

TODO: Add error checking

TODO: Show when request fails on webpage

import os import sys import argparse import re from flask import Flask, request, abort, jsonify, render_template, redirect, flash, url_for from flask_bootstrap import Bootstrap from flask_cors import CORS from gevent.wsgi import WSGIServer from gevent import spawn_later, sleep from connect_ffi import ffi, lib from connect import Connect from utils import get_zeroconf_vars, get_metadata, get_image_url

web_arg_parser = argparse.ArgumentParser(add_help=False)

Not a tuple, evaluates the same as "" + ""

cors_help = ( "enable CORS support for this host (for the web api). " "Must be in the format ://:. " "Port can be excluded if its 80 (http) or 443 (https). " "Can be specified multiple times" )

def validate_cors_host(host): host_regex = re.compile(r'^(http|https)://[a-zA-Z0-9][a-zA-Z0-9-.]+(:[0-9]{1,5})?$') result = re.match(host_regex, host) if result is None: raise argparse.ArgumentTypeError('%s is not in the format ://:. Protocol must be http or https$ return host

web_arg_parser.add_argument('--cors', help=cors_help, action='append', type=validate_cors_host) args = web_arg_parser.parse_known_args()[0]

app = Flask(name, root_path=sys.path[0]) Bootstrap(app)

Add CORS headers to API requests for specified hosts

CORS(app, resources={r"/api/*": {"origins": args.cors}})

Serve bootstrap files locally instead of from a CDN

app.config['BOOTSTRAP_SERVE_LOCAL'] = True app.secret_key = os.urandom(24)

Used by the error callback to determine login status

invalid_login = False

@ffi.callback('void(SpError error, void *userdata)') def web_error_callback(error, userdata): global invalid_login if error == lib.kSpErrorLoginBadCredentials: invalid_login = True

connect_app = Connect(web_error_callback, web_arg_parser)

if os.environ.get('DEBUG') or connect_app.args.debug: app.debug = True

Routes

Home page

@app.route('/') def index(): return render_template('index.html')

API routes

Playback routes

@app.route('/api/playback/play') def playback_play(): lib.SpPlaybackPlay() return '', 204

@app.route('/api/playback/pause') def playback_pause(): lib.SpPlaybackPause() return '', 204

@app.route('/api/playback/prev') def playback_prev(): lib.SpPlaybackSkipToPrev() return '', 204

@app.route('/api/playback/next') def playback_next(): lib.SpPlaybackSkipToNext() return '', 204

[...]

The whole main.py is here in case you need it completely: https://drive.google.com/file/d/1IIAqTbSsNks_SSfChYEnS9MX1PEm6hE_/view?usp=sharing

RafaPolit commented 6 years ago

It looks good, maybe there was something wrong with the editing?

By the way, what are you using to edit the file? Maybe it is changing some encoding or something else? Who is the owner:group of the main.py file?

schnellecom commented 6 years ago

I use nano but I'll try it with another editor.

Here is the output of ls -l:

pi@moode:~/spotify/spotify-connect-web $ ls -l total 364 -rw-r--r-- 1 pi pi 594 May 28 19:21 connect_ffi.py -rw-r--r-- 1 pi pi 767 May 28 23:01 connect_ffi.pyc -rw-r--r-- 1 pi pi 6055 May 28 19:21 connect.py -rw-r--r-- 1 pi pi 6283 May 28 23:01 connect.pyc -rw-r--r-- 1 pi pi 9211 May 28 19:21 console_callbacks.py -rw-r--r-- 1 pi pi 10648 May 28 23:01 console_callbacks.pyc -rw-r--r-- 1 pi pi 601 May 28 19:21 Dockerfile -rw-r--r-- 1 pi pi 197 May 28 19:21 lastfm_credentials.json.dist -rw-r--r-- 1 pi pi 4211 May 28 19:21 lastfm.py -rw-r--r-- 1 pi pi 4001 May 28 23:01 lastfm.pyc -rwxr-xr-x 1 pi pi 224000 May 28 19:22 libspotify_embedded_shared.so -rw-r--r-- 1 pi pi 1074 May 28 19:21 LICENSE -rw-r--r-- 1 pi pi 8512 May 29 23:05 main.py -rw-r--r-- 1 pi pi 396 May 28 19:21 Makefile.docker drwxr-xr-x 3 pi pi 4096 May 28 23:01 pycache -rw-r--r-- 1 pi pi 7544 May 28 19:21 README.md -rw-r--r-- 1 pi pi 135 May 28 19:21 requirements.txt -rwxr-xr-x 1 pi pi 181 May 28 19:21 run-with-docker -rw-r--r-- 1 pi pi 321 May 28 19:21 spotify_appkey.key -rw-r--r-- 1 pi pi 5529 May 28 19:21 spotify.h -rw-r--r-- 1 pi pi 8161 May 28 19:21 spotify.processed.h drwxr-xr-x 4 pi pi 4096 May 28 19:21 static drwxr-xr-x 2 pi pi 4096 May 28 19:21 templates -rw-r--r-- 1 pi pi 1830 May 28 19:21 utils.py -rw-r--r-- 1 pi pi 2421 May 28 23:01 utils.pyc

BTW maybe a clean install is the solution. Is there a way to remove spotify without removing moode? (moode install takes several hours)

RafaPolit commented 6 years ago

Oh, yes, absolutely. All you need is to just remove the spotify directory in home/pi, and the two services you created.

So, basically,

$ sudo rm -R /home/pi/spotify
$ sudo systemctl disable avahi-spotify-connect-multiuser.service
$ sudo systemctl stop avahi-spotify-connect-multiuser.service
$ sudo rm /lib/systemd/system/avahi-spotify-connect-multiuser.service
$ sudo systemctl disable spotify-connect-web.service
$ sudo systemctl stop spotify-connect-web.service
$ sudo rm /lib/systemd/system/spotify-connect-web.service

If you want to completely remove all you did, probably delete the asound.conf file as well:

$ sudo rm /etc/asound.conf

That's it. (I'm assuming you did not follow the UI Alpha procedures, if not, reverse those changes as well).

schnellecom commented 6 years ago

So I tried to reinstall it and this error appeared. I will try to reinstall the whole system soon but if it can help here is the error:

Collecting cffi>=0.9.2 (from -r requirements.txt (line 1)) Collecting Flask==0.11.1 (from -r requirements.txt (line 2)) Using cached https://files.pythonhosted.org/packages/63/2b/01f5ed23a78391f6e3e73075973da0ecb467c831376a0b09c0ec5afd7977/Flask-0.11.1-py2.py3-none-any.whl Collecting Flask-Bootstrap<4.0,>=3.3.2.1 (from -r requirements.txt (line 3)) Collecting Flask-Cors==2.1.2 (from -r requirements.txt (line 4)) Collecting pycparser>=2.10 (from -r requirements.txt (line 5)) Using cached https://www.piwheels.org/simple/pycparser/pycparser-2.18-py2.py3-none-any.whl Collecting pyalsaaudio>=0.8 (from -r requirements.txt (line 6)) Collecting gevent>=1.0.1 (from -r requirements.txt (line 7)) Downloading https://files.pythonhosted.org/packages/a4/5b/12d4fb2e48634b34537ae250e958de426811f876fbacb2a2041f2af147d8/gevent-1.3.2.post0.tar.gz (4.6MB) 100% |████████████████████████████████| 4.6MB 16kB/s Ignoring cffi: markers 'sys_platform == "win32" and platform_python_implementation == "CPython"' don't match your environment Collecting pylast>=1.6.0 (from -r requirements.txt (line 8)) Using cached https://files.pythonhosted.org/packages/df/c6/d20fb3c70c96ca0cbc631cc7105dee0321377ddaaf5542f5c57e06ae31be/pylast-2.2.0-py2.py3-none-any.whl Collecting itsdangerous>=0.21 (from Flask==0.11.1->-r requirements.txt (line 2)) Collecting click>=2.0 (from Flask==0.11.1->-r requirements.txt (line 2)) Using cached https://files.pythonhosted.org/packages/34/c1/8806f99713ddb993c5366c362b2f908f18269f8d792aff1abfd700775a77/click-6.7-py2.py3-none-any.whl Collecting Werkzeug>=0.7 (from Flask==0.11.1->-r requirements.txt (line 2)) Using cached https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl Collecting Jinja2>=2.4 (from Flask==0.11.1->-r requirements.txt (line 2)) Using cached https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl Collecting dominate (from Flask-Bootstrap<4.0,>=3.3.2.1->-r requirements.txt (line 3)) Collecting visitor (from Flask-Bootstrap<4.0,>=3.3.2.1->-r requirements.txt (line 3)) Collecting Six (from Flask-Cors==2.1.2->-r requirements.txt (line 4)) Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl Collecting greenlet>=0.4.13; platform_python_implementation == "CPython" (from gevent>=1.0.1->-r requirements.txt (line 7)) Collecting MarkupSafe>=0.23 (from Jinja2>=2.4->Flask==0.11.1->-r requirements.txt (line 2)) Building wheels for collected packages: gevent Running setup.py bdist_wheel for gevent ... |done Stored in directory: /home/pi/.cache/pip/wheels/f8/29/8d/8eb87430b763151b14c80954f5a7d5186a528479881d302057 Successfully built gevent Installing collected packages: pycparser, cffi, itsdangerous, click, Werkzeug, MarkupSafe, Jinja2, Flask, dominate, visitor, Flask-Bootstrap, Six, Flask-Cors, pyalsaaudio, greenlet, gevent, pylast Successfully installed Flask-0.11.1 Flask-Bootstrap-3.3.7.1 Flask-Cors-2.1.2 Jinja2-2.10 MarkupSafe-1.0 Six-1.11.0 Werkzeug-0.14.1 cffi-1.11.5 click-6.7 dominate-2.3.1 gevent-1.3.2.post0 greenlet-0.4.13 itsdangerous-0.24 pyalsaaudio-0.8.4 pycparser-2.18 pylast-2.2.0 visitor-0.1.3 Segmentation fault

RafaPolit commented 6 years ago

Could you have a corrupted microSD card? I had one that was an off-market fake (sold to me as the real thing) that did these kind of unpredictable and random errors.

I do think you are beyond the full moOde rebuild at this point, but I would suggest replacing the card. Obviously not what you wanted to hear, but may as well save you time in the long run.

Hope you get things sorted out! Best regards, Rafa.

schnellecom commented 6 years ago

Yes it is possible that the card is corrupt it is a few years old. I will try a fresh install on a newer card soon and report if anything changed.

Already thanks for all the support and the great work here

schnellecom commented 6 years ago

So I installed moode and spotify connect again and I cannot get the spotify-connect-web.service to run. Here is what the status is outputting:

pi@moode:~/spotify $ sudo systemctl status spotify-connect-web.service ● spotify-connect-web.service Loaded: loaded (/lib/systemd/system/spotify-connect-web.service; disabled; vendor preset: enabled) Active: activating (auto-restart) (Result: exit-code) since Sun 2018-06-03 06:10:40 EDT; 2s ago Process: 32539 ExecStart=/home/pi/spotify/spotify-connect.sh (code=exited, status=203/EXEC) Main PID: 32539 (code=exited, status=203/EXEC)

Jun 03 06:10:40 moode systemd[1]: spotify-connect-web.service: Failed with result 'exit-code'.

I already tried to change the number of the mixer in spotify-connect.sh but that did not change anything even after restarting the service

RafaPolit commented 6 years ago

Disable and stop the service and run the script directly and post the output of Spotify-connect.sh, just like before. It's the only way of knowing which is the error.

schnellecom commented 6 years ago

Here is the output of spotify-connect.sh:

pi@moode:~/spotify $ sudo ./spotify-connect.sh ./spotify-connect.sh: 1: ./spotify-connect.sh: /sh: not found Traceback (most recent call last): File "main.py", line 9, in from flask import Flask, request, abort, jsonify, render_template, redirect, flash, url_for ImportError: No module named flask

Tried to fix that with "pip install flask" but that did not fix it

RafaPolit commented 6 years ago

Did you run the instructions to install depedndencies? It's weird to have another module missing. Maybe the spotify-connect script is missing info on the variables that point to the python libs? Can you cat the results of the spotify-connect.sh file?

schnellecom commented 6 years ago

I did run the commands to run the dependencies and when I ran the commands again it said that it is already installed. Here is the output of the dependencies and cat of the spotify-connect.sh:

pi@moode:~/spotify $ sudo apt-get install avahi-utils Reading package lists... Done Building dependency tree Reading state information... Done avahi-utils is already the newest version (0.6.32-2). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

pi@moode:~/spotify $ sudo apt-get install python-dev libffi-dev libasound2-dev Reading package lists... Done Building dependency tree Reading state information... Done libffi-dev is already the newest version (3.2.1-6). python-dev is already the newest version (2.7.13-2). libasound2-dev is already the newest version (1.1.3-5+rpi3). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

pi@moode:~/spotify $ cat spotify-connect.sh

!/bin/sh

cd / cd home/pi/spotify/spotify-connect-web LD_LIBRARY_PATH=/home/pi/spotify/spotify-connect-web python main.py --playback_device softvol -m Master --mixer_device_index 0 --bitrate 320 --name "moOde Connect" --key /home/pi/spotify/spotify-connect-web/spotify_appkey.key cd /

RafaPolit commented 6 years ago

Ok. i meant the pip requirements? $ cd /home/pi/spotify/spotify-connect-web/ $ pip install -r requirements.txt

schnellecom commented 6 years ago

That fixed that part of the problem. I just ran the command again and got this error: pi@moode:~/spotify $ ./spotify-connect.sh Traceback (most recent call last): File "main.py", line 12, in from gevent.wsgi import WSGIServer ImportError: No module named wsgi

Since you discussed the solution to it in another post I applied the solution by changing the main.py as described. After that I got the illegal instruction again:

pi@moode:~/spotify $ ./spotify-connect.sh Loading Spotify library... Last.fm: incomplete credentials, not launched Device has no native mute min_volume_range: 0 Using libspotify_embedded version: release-esdk-1.20.0-v1.20.0-g594175d4 Illegal instruction

So it is probably not the SD card as this one is only a few month old and barely used.

schnellecom commented 6 years ago

Also I checked and when I change the main.py back (remove the py in front of the wsgi) I get the "no module called wsgi again)

Biniou commented 4 years ago

Me on raspberrypi B , a fix this with a pre-built chroot version of spotify connect. https://github.com/Fornoth/spotify-connect-web

asound.conf are copy in chroot folder.

In my fork, I'm writing a lite readme for raspberry pi B (ARM7 version)

gibman commented 4 years ago

I'm also getting the "illegal instruction" here on my installation. moode audio reports the following: Pi-1B+ ARM6

yes, its an older model :)

I guess the binaries are not compiled for this CPU architecture ??

Biniou commented 4 years ago

chroot version should work.

'look at this readme for comand lines https://github.com/Biniou/moode-spotify-connect-web

I only change the code in this readme for install a chroot version, the text arround is maybe wrong