I have connected an LCD to my Rapsberry Pi which is acting as a frame buffer device (booting and desktop visible when running Raspbian). To control the LCD I use Python and Pygame, which works perfectly.
But I would like to auto start this application.
The only way I could which resulted in the Python application taking control over the LCD is by using LXDE autostart. But the application then runs twice! My guess this is due to the fact that I also run vnc, so I have two desktops which both autostart the application.
Is there any way to resolve this?
Related
I made an app in Thonny that when I run it, shows a camera connected to RPI and shows the image in an interface. You can also use the keyboard to do some things in the interface, take photos, etc.
I always execute it using thonny (run button), but now, I am trying to autostart the program in python when Raspbian ends its starting (after a shutdown or reboot).
I tried to do it in 3 ways:
autostart
lxde-pi/autostart
crontab
But it doesn't work. It starts Raspbian, but nothing more. Any ideas or code to do it?
Thanks a lot.
This might be a bit late for #mash_10, but for anyone else who lands here my solution that auto fires a bash script on the home folder. To add new automatic startups I just add code to my personal bash script. This works on Buster rpi.
Details are in my answer here How to automatically launch python file once GUI has loaded on Raspbian Pixel
Is there Python programming to connect to the ssid of a router without using CMD?
I have programming working that runs cmd batch files or sends "netsh" commands to the cmd window.
CMD is an excellent debugging tool but I can't believe it was intended to be used seriously for using with own software programming as the cmd editor needs to open, be opened or flash every time a command is sent.
It might help to mention that the stick PC I'm using does not have a physical monitor attached but with a hardware adaption to the HDMI output and VNC software installed so the screen can be viewed on any other computer with a VNC viewer. Mouse and keyboard can also control the PC stick with VNC server running.
As the VNC server will not be active until the Windows 10 has installed itself; precautions such as disabling Automatic Repair at start up, Windows Updates paused or anything else in start up that would require what, will be unseen, requests for mouse clicks or keyboard presses.
It needs programming to connect to a portable router, passively poll the connection to see if the router is still connected and reconnect whenever possible. Without Using CMD.
I have had all this working for a while. It's proving reliable to connect and run but not comfortable to watch because the batch file which loops every 10 minutes uses
netsh wlan connect ssid=YOURSSID name=PROFILENAME interface="WIRELESS NETWORK CONNECTION"
and
'name="name_of_wifi" interface="type_of_network_interface" priority=1'
It keeps opening CMD window and the reconnection first closes the VNC server so on the VNC client the VNC viewer has to be started again.
I haven't used Python yet but before I do I want to know if there is programming and/or libraries available to connect to the ssid of a wifi router without CMD.
Any help on this will be appreciated.
What code can be used to close a program running on RPI3?
I am running a
smart magic mirror using my Raspberry Pi, and I want to then close it. How can I?
It depends how you are accessing the Pi. If you are running it headless (without a separate monitor) then you need to use ssh to log in from another computer (ssh username#ip-address in the terminal window). You can then use other methods such as process killing to force the program to stop running on the Pi.
Alternatively, if you have access to the where you started the program on your Pi (maybe a window, or a terminal window where the Pi is running your mirror program, then you could exit or use a common interrupt such as Ctrl+C.
I am creating a GUI interface that will be using a 7" touch display with a raspberry pi 3. I want the GUI to take the place of the desktop, I do not want it displayed in a window on the desktop. any thoughts on how to do that. I have read the raspberry pi documentation to edit the rc.local script to start the application at login, but I can not figure out how to set up the python GUI with out creating a window
Your pi boots up and displays a console - just text - by running a program (getty). Then you run another application called a graphical display manager which then runs a window manager. On a pi it is usually gnome but there are many others,.. this window manager is what displays your GUI window. What you want is obviously possible, it is just that it is non-trivial to do. What you are talking about is either kiosk-mode application still running 'on the desktop' as you say but which obscures the desktop completely and does not allow you to switch or de-focus or an even more complicated JeOS like Kodi/XBMC bare metal installation running without your current window manager. Your python would have to do the job of the display manager and the window manager and it would be very, very slow.
Use a really light window manager and go kiosk mode. Or you could go with text! There are libraries eg ncurses but I'm not sure how that would work with your touch screen display.
1.
Disable graphical interface i.e. stop the desktop manager from running.
On Raspbian you can use raspiconfig to do it.
2.
Set up autologin into bash
3.
Block startx from automatically running desktop manager
4.
Add your app to be started from .bash_rc when autologin is performed.
To setup autologin first create a script called autologin in /bin directory that does:
#! /bin/bash
/bin/login -f pi
Note: pi is an user on raspbian that won't ask for password when sudo-ing.
To use the created script edit /etc/inittab:
Scroll down to where terminals are assigned and change tty1's line to be:
1:2345:respawn:/sbin/getty -n -l /bin/autologin 38400 tty1
Take care that ids are matching old tty1 settings.
Then in the user's home directory (/home/pi) add (if it's not already there) a file named ".xinitrc" containing just:
#! /bin/bash
cat
This will prevent X server from invoking desktop manager when started.
Now add in /home/pi's .bashrc your app or better a script that will run your app (at the end):
export DISPLAY=:0
/home/pi/Desktop/appstart &
startx
And appstart is:
#! /bin/bash
# Wait a second for X server to start:
sleep 1
# Now X is running and we have to switch into video terminal using chvt (change virtual terminal) command
# Graphic terminal is on Raspbian tty7
sudo chvt 7
# Start the app:
python /home/pi/Desktop/myapp/myapp.py
After all this is set up what will hapen is the following:
1.
You run Raspberry Pi and it autologins into user pi
2.
When Bash logs in it executes /home/pi/.bashrc
3.
.bashrc sets $DISPLAY variable because there are no X displays yet, runs starting script as a background job and starts X server.
4.
X server won't enter desktop manager because /home/.xinitrc will stop it step short of it.
5.
Starting script sleeps for a second to ensure that X is running and able to send graphics to tty7, switches to tty7 so that user doesn't have to do it manually, and then runs your application which will show up.
If your app is not graphical you will see only one big nothing. :D
Problems here are that you definitely should create an user just for this stuff. If your app crashes or user switches to tty1 and terminates X there he/she is in bash, logged in.
Depends on what level of security you need. You can do a lot of things to prevent abuse. For example, use fcntl to change mode tty1 is in so that it cannot receive key input any longer.
Or use some other tricks, or rearange this procedure somewhat, or ensure that tty1 runs everything in jobs with nohup, then logs out etc, etc.
Here's a short description of what I have:
I have to raspberry pi's in a local net work. I one of them I have a .py script named watchdog.py that starts a stream and then uses a sshpass command to the other pi to display the video stream.It also has some signaling LEDs a some push buttons for control
the problem is:
If I open a terminal and run the watchdog.py script in the GUI everything runs as it should be. So I thought of running it as a service as boot and installed upstart and made it run as a service (successfully I think). The thing is. If I boot the pi and then press the button to start the streams,they wont play on the other Pi, the LEDs ligh up and all the buttons work. And even the CPU load behaves the same way, but i still don't video nor audio. I have thought of trying automatically open a terminal (LXterminal) widow and run the python scrip on that window. but I didn't want the streaming raspberry pi also booting into gui (tough I guess I would mind if that makes the whole thing work).This little thing i making the whole project useless.
What are you using to play the streams? Depending on how you boot up the second Raspberry it might not have started some daemons for audio/video playback?!
You should (if you're not already doing) write a log (import logging ;)) and write a logfile which you can track for errors.
answer moved from OP's question itself:
I found a way that seems to work so far. instead of running the python script as a service I tried running it as cron job at reboot, and it worked. now it all works straight from reboot and I have Audio and video.