Peppy player

You can find all places for 'pi' using 'grep -r "/home/pi" .' in the Peppy folder. All of them except the one which you found are in the configuration files. So I think you can continue using your user.

I still don't see the reason why file logging doesn't work after reboot. One possible reason could be that player was started by different user. But I don't see that from your scripts. Another guess - the player was started by sudo and as a result different libraries were in use. Also the order of libraries loading after reboot could be different (not sure why). That could load some library which initialized logging in a specific way. The problem is there is no way to write errors to the log file until you initialized it, chicken & egg problem. Maybe just write error caught during initialization to the regular file instead of log file.
 
I wanted to rule out that X or that xinitrc is a problem.
I'm pretty sure it did work before it did install X.

I removed xinitrc and changed my .profile to:
Code:
python3 /home/haegarthehorrible/opt/Peppy/peppy.py
If i do that i get only this and Peppy does not start:
attachment.php


Maybe that Network error was there the whole time and i did not see it because it was hidden behind the Peppy GUI?

That logging code does not create a /tmp/error.txt file.
Damn, without logging its almost impossible to figure out whats going on.
 

Attachments

  • Untitled-1.jpg
    Untitled-1.jpg
    412.1 KB · Views: 267
Do you still run X? Without X you don't have a graphical context in the SSH terminal. You can use the player only in the Headless mode in this case with Web UI. Another way is to use 'openvt' but this way we go to the beginning of this story :)
 
Last edited:
As i wrote, i'm trying to get rid of X.
There must be a way to make a HDMI touchscreen working.
That USB cable i guess is what normally would be the mouse (HID device?)

Code:
export PATH=$HOME/opt/python-3.7.8/bin:$PATH
su haegarthehorrible -c 'cd /home/haegarthehorrible/opt/Peppy'
openvt -s -- python3 peppy.py
This in my .profile does start Peppy but tells me there is no pygame.
So i guess its using the default Python and not python-3.7.8 where all the packages are installed.
 
Last edited:
You sometimes go backwards :p

pygame is not the problem. If i use my Peppy and X auto start stuff then it works. So pygame is there.

I'm again trying to do it the right way and look for a systemd solution.
And this time i did search for 'python systemd openvt'.
And you know what came up: Somebody who did it for Peppy:
Python-pygame Skript lauft als Systemd-Service mit user 'pi' - Allgemeines - Deutsches Raspberry Pi Forum

What i don't understand is why the 'tty2' thing and why the 'start-peppy-player.sh'

It must be possible without that sh file.

Is there a reason you are using rc-local?
Its deprecated since a long time and most distributions don't have it anymore.
Code:
systemctl start peppy.service
systemctl stop peppy.service
would be a lot nicer and cleaner.

1. What is the correct substitute for rc.local in systemd instead of re-creating rc.local - Unix & Linux Stack Exchange
2. What is the correct substitute for rc.local in systemd instead of re-creating rc.local - Unix & Linux Stack Exchange
 
Last edited:
As far as I remember the virtual terminal tty2 is owned by root. In order to grant access to it you need to add udev rule. You can actually create account on that forum and ask your questions there. It's very responsive and helpful forum. I usually post my text in German and English. Here is the Peppy thread there:
Peppy WebRadio - Musikboxen, Webradios, Musikplayer - Deutsches Raspberry Pi Forum

I use rc.local just because it was working 5 years ago and it's still working now on Raspberry OS. I usually don't change working code. But if you will come up with a working systemd configuration I can probably borrow it from you ;)
 
I wonder what the right forum is to ask this.
I did ask python-forum.io one week ago and did not get an answer.
If i search at forums.debian.net there is not much on that topic.
There seems to be no pygame forum...

This does start Peppy on the connected screen:
Code:
[Unit]
Description=Peppy Service
Wants=network-online.target
After=network-online.target

[Service]
Restart=no
User=haegarthehorrible
Environment="PATH=/home/haegarthehorrible/opt/python-3.7.8/bin:$PATH"
WorkingDirectory=/home/haegarthehorrible/opt/Peppy
ExecStart=sudo /home/haegarthehorrible/opt/Peppy/peppy.py
ExecStop=/bin/kill -INT $MAINPID
OOMScoreAdjust=-100
TimeoutStopSec=10s
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty2

[Install]
WantedBy=multi-user.target
but it tells me "no module named pygame".

So
Code:
Environment="PATH=/home/haegarthehorrible/opt/python-3.7.8/bin:$PATH"
is not enough to tell it to use that 3.7.8 where the packages are installed.
 
This also seems to work but still does not find the modules:
Code:
[Unit]
Description=Peppy Service
Wants=network-online.target
After=network-online.target

[Service]
Restart=no
User=haegarthehorrible
Environment="PATH=/home/haegarthehorrible/opt/python-3.7.8/bin:$PATH"
WorkingDirectory=/home/haegarthehorrible/opt/Peppy
ExecStart=/bin/openvt -c 1 -s /home/haegarthehorrible/opt/Peppy/peppy.py
OOMScoreAdjust=-100
TimeoutStopSec=10s

[Install]
WantedBy=multi-user.target
I found this: How to set environment variable in systemd service? - Server Fault

So i did:
Code:
~$ sudo systemctl edit peppy.service

[Service]
Environment="PATH=/home/haegarthehorrible/opt/python-3.7.8/bin:$PATH"
But it does not help.
 
Without sudo i get:
Code:
dummy.service: Failed at step EXEC spawning /home/haegarthehorrible/opt/Peppy/peppy.py: Exec format error
even if the owner is right
Code:
~$ ls -all /dev/tty1
crw--w---- 1 haegarthehorrible tty 4, 1 Jul 11 18:48 /dev/tty1
The funny thing is that on my screen i see "no module named pygame"
That means its executed?

I Google since hours and found 1 Million people trying to run Python with systemd. But nothing really works.

Remember:
My python is in '/home/haegarthehorrible/opt/python-3.7.8' and all the pip stuff is installed by the user 'haegarthehorrible'

1 ############

Code:
[Unit]
Description=Peppy Service
Wants=network-online.target
After=network-online.target
RequiresMountsFor=/home/haegarthehorrible

[Service]
Restart=no
User=haegarthehorrible
Environment="PATH=/home/haegarthehorrible/opt/python-3.7.8/bin"
WorkingDirectory=/home/haegarthehorrible/opt/Peppy
ExecStart=/home/haegarthehorrible/opt/Peppy/peppy.py
ExecStop=/bin/kill -INT $MAINPID
OOMScoreAdjust=-100
TimeoutStopSec=10s
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty1

[Install]
WantedBy=multi-user.target
Error:
dummy.service: Failed at step EXEC spawning /home/haegarthehorrible/opt/Peppy/peppy.py: Exec format error

On screen:
no module named pygame

/dev/tty1:
crw--w---- 1 haegarthehorrible tty 4, 1 Jul 11 18:48 /dev/tty1

Note:
I tried it also with "TTYPath=/dev/tty2"

2 ############

Code:
[Unit]
Description=Peppy Service
Wants=network-online.target
After=network-online.target
RequiresMountsFor=/home/haegarthehorrible

[Service]
Restart=no
User=haegarthehorrible
Environment="PATH=/home/haegarthehorrible/opt/python-3.7.8/bin"
WorkingDirectory=/home/haegarthehorrible/opt/Peppy
ExecStart=/bin/openvt -c 2 -s -f /home/haegarthehorrible/opt/Peppy/peppy.py
OOMScoreAdjust=-100
TimeoutStopSec=10s
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty2

[Install]
WantedBy=multi-user.target
On screen:
no module named pygame

/dev/tty2:
crw--w---- 1 haegarthehorrible tty 4, 2 Jul 11 19:03 /dev/tty2

3 ############

Code:
[Unit]
Description=Peppy Service
Wants=network-online.target
After=network-online.target
RequiresMountsFor=/home/haegarthehorrible

[Service]
Restart=no
User=haegarthehorrible
Environment="PATH=/home/haegarthehorrible/opt/python-3.7.8/bin"
WorkingDirectory=/home/haegarthehorrible/opt/Peppy
ExecStart=/bin/openvt -c 1 -s /home/haegarthehorrible/opt/Peppy/peppy.py
ExecStop=/bin/kill -INT $MAINPID
OOMScoreAdjust=-100
TimeoutStopSec=10s

[Install]
WantedBy=multi-user.target
On screen:
no module named pygame

dev/tty1:
crw--w---- 1 haegarthehorrible tty 4, 1 Jul 11 19:36 /dev/tty1

4 ############

Code:
[Unit]
Description=Peppy Service
Wants=network-online.target
After=network-online.target
RequiresMountsFor=/home/haegarthehorrible

[Service]
Restart=no
User=haegarthehorrible
Environment="PATH=/home/haegarthehorrible/opt/python-3.7.8/bin"
WorkingDirectory=/home/haegarthehorrible/opt/Peppy
ExecStart=/home/haegarthehorrible/opt/python-3.7.8/bin /home/haegarthehorrible/opt/Peppy/peppy.py
ExecStop=/bin/kill -INT $MAINPID
OOMScoreAdjust=-100
TimeoutStopSec=10s
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty1

[Install]
WantedBy=multi-user.target
Error:
dummy.service: Failed at step EXEC spawning /home/haegarthehorrible/opt/python-3.7.8/bin: Permission denied

On screen:
no module named pygame

dev/tty1:
crw--w---- 1 haegarthehorrible tty 4, 1 Jul 11 19:36 /dev/tty1

##############

I guess i tried millions of other ways.
I also tried:
Code:
sudo chmod 644 /lib/systemd/system/dummy.service
sudo chmod +x /home/haegarthehorrible/opt/Peppy/peppy.py
Then i did read about SELinux - but that is not installed in Debian 10

There is also this prefixe "+" for path i tried:
systemd.service

A small excerpt of stuff i did read:
display.init() fails when run under systemd * Issue #342 * pygame/pygame * GitHub
How To Setup Autorun a Python Script Using Systemd - TecAdmin
Run a python app (or script) as a systemd service
linux - Running Python script via systemd fails to load module - Stack Overflow
https://unix.stackexchange.com/questions/462075/systemd-service-not-recognizing-python-library
https://bbs.archlinux.org/viewtopic.php?id=213292
https://serverfault.com/questions/413397/how-to-set-environment-variable-in-systemd-service
https://stackoverflow.com/questions/37211115/how-to-enable-a-virtualenv-in-a-systemd-service-unit
https://unix.stackexchange.com/ques...ript-using-systemd-no-module-named-oandapyv20
https://serverfault.com/questions/821575/systemd-run-a-python-script-at-startup-virtualenv
https://serverfault.com/questions/973002/only-certain-environment-variables-are-set-in-systemd
https://askubuntu.com/questions/676...rvice-run-via-specific-user-and-start-on-boot
 
My setup: Reaspberry Pi 3B+, 3.5" SPI touchscreen connected to GPIO.
I connected to Pi over SSH (Putty) as 'pi' user.

I was able to run the following command from the folder /home/pi without 'sudo':
Code:
openvt -s -- python3 peppy.py
It starts the player and UI shows up in the touchscreen.

Then I created the following simple systemd service configuration file:
Code:
[Unit]
Description=Peppy Service
Wants=network-online.target
After=network-online.target

[Service]
Restart=no
User=pi
WorkingDirectory=/home/pi/Peppy
ExecStart=openvt -s -- python3 peppy.py

[Install]
WantedBy=multi-user.target
The service failed to to start with message:
Code:
 peppy.service - Peppy Service
   Loaded: loaded (/etc/systemd/system/peppy.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sun 2020-07-12 01:24:51 BST; 55s ago
  Process: 601 ExecStart=/bin/openvt -s -- python3 peppy.py (code=exited, status=0/SUCCESS)
 Main PID: 601 (code=exited, status=0/SUCCESS)

Jul 12 01:24:51 raspberrypi systemd[1]: Started Peppy Service.
Jul 12 01:24:51 raspberrypi systemd[1]: peppy.service: Succeeded.
Hmm, probably that's the reason why I'm still using rc.local :)
 
I have something that now starts Peppy up to the point where it says:
"pygame.error: unable to open mouse"

Is there a way to disable this "looking for mouse" thing (for testing)?
I did read something about
Code:
os.environ['SDL_NOMOUSE'] = '1'
os.putenv('SDL_NOMOUSE', '1')
But where do i need to place that in the code?

The description of my screen says:
When works with Raspberry Pi, supports Raspbian/Ubuntu/Kali/Retropie/WIN10 IOT, driver free
When work as a computer monitor, supports Windows 10/8.1/8/7, single touch, and driver free

I guess they talk about Desktop/GUI/X systems.
But since it is just a HID mouse and there is no driver needed it must work with the standard mouse driver the systems have.
Is there such a driver for that framebuffer stuff? Or is it just impossible to use a mouse there?

I did read this now:
There is big a difference between starting something stand-alone inside X and starting a stand-alone graphical application outside X (i.e., on the framebuffer). I believe pygame, which depends on SDL, used to support a mode for the latter but no longer does, so you might as well ignore anything that involves using it without an X server.
I've heard using the framebuffer only for Pygame produces comparatively terrible performance.
You said you don't use X. So you use framebuffer and not SDL - right?

SORRY if i bug. I'm just trying to understand how it works to figure out what the best way is to run Peppy.
 
Last edited:
Hi MrGlasspoole,

Did you try to start player with 'sudo' when you see that mouse error?

If you need you can set SDL_NOMOUSE environment variable in .../Peppy/util/config.py in this function:
Peppy/config.py at 87daa889969de9b0215731785318e903b136219e * project-owner/Peppy * GitHub
In the same function you can see how it handles the mouse.

Yes, I don't use X but I use framebuffer as you can see here:
Peppy/config.py at 87daa889969de9b0215731785318e903b136219e * project-owner/Peppy * GitHub
Pygame is a Python binding for SDL. SDL can use framebuffer.

Maybe if it works for you with X just use it (?) I hope that eventually you will find the oprimal combination/configuration.

Best regards
 
Yes sudo.
systemd runs as root and i also did:
Code:
ExecStart=sudo /bin/sh -c "export SDL_NOMOUSE=1 && /bin/openvt -s /home/haegarthehorrible/opt/Peppy/peppy.py"
But even doing this:
Code:
        if self.config[USAGE][USE_MOUSE]:
            if os.path.exists("/dev/input/touchscreen"):
                os.environ['SDL_NOMOUSE'] = '1'
            else:
                os.environ['SDL_NOMOUSE'] = '1'
            os.environ['SDL_NOMOUSE'] = '1'
it changes nothing and is still looking for the mouse. Weird - I don't get it

The first reason for trying get rid of X was to rule out that it maybe has to do with that empty log file.
Then my thoughts where that X is wasting resources if it is not needed for Peppy.

What happens if i use X and Peppy is using framebuffer.
Isn't that some kind of going from one to the other and back?
Like you convert a digital audio signal to analog and back to digital :)