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.
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
I've created a simple program in python3 with selenium to monitor a website. The program works as intended when I run it on my own computer, but as I need to keep it running 24/7, I've put it on a droplet from digital ocean. The program works when I am connected to via ssh, but from the log file I can tell that the program stops as soon as I close the connection. I'm guessing it has something that the problem is that the program is running on the same thread as the connection. My question is: How do I make sure the program runs in the background so it will keep running even after I close the coonection to the droplet?
Try using screen.
It allows you to run programs in separate windows so they run completely independent from each other, and also should keep your program running while not connected.
More info about screen: https://www.gnu.org/software/screen/
I have a python script that checks the temperature every 24 hours, is there a way to leave it running if I shut the computer down/log off.
Shutdown - no.
Logoff - potentially, yes.
If you want to the script to automatically start when you turn the computer back on, then you can add the script to your startup folder (Windows) or schedule the script (Windows tasks, cron job, systemd timer).
If you really want a temperature tracker that is permanently available, you can use a low-power solution like the Raspberry Pi rather than leaving your pc on.
The best way to accomplish this is to have your program run on some type of server that your computer can connect to. A server could be anything from a raspberry pi to an old disused computer or a web server or cloud server. You would have to build a program that can be accessed from your computer, and depending on the server and you would access it in a lot of different ways depending the way you build your program and your server.
Doing things this way means your script will always be able to check the temperature because it will be running on a system that stays on.
Scripts are unable to run while your computer is powered off. What operating system are you running? How are you collecting the temperature? It is hard to give much more help without this information.
One thing I might suggest is powering on the system remotely at a scheduled time, using another networked machine.
You can take a look at the following pages
http://www.wikihow.com/Automatically-Turn-on-a-Computer-at-a-Specified-Time
http://lifehacker.com/5831504/how-can-i-start-and-shut-down-my-computer-automatically-every-morning
Additionally once it turn on, you can perform a cronjob, for execute your python code by a console command >> python yourfile.py . What is the Windows version of cron?
I am making an image processing solution where the Raspberry Pi processes the image using a python script, and sends the result to an Arduino board. I want to keep this system always running, as Raspberry Pi has a Linux kernel, so is there any way to keep the python script on the pi always running?
It's not clear if the images will be stored on a folder or how your script will receive the images, but here are 2 options:
Setup a cron job to run your script every X seconds/minutes, process all images available and send them to the arduino board
Run your script in the background as a service, there are some cool instructions on the following link:
http://blog.scphillips.com/posts/2013/07/getting-a-python-script-to-run-in-the-background-as-a-service-on-boot/
If you keep terminal running forever, then you can simply use python's While condition
while True:
*do some thing*
and keep the program running as long as u need you can also use time module if you want it to sleep for few sec or mins
I use the technique described in this post:
Is it possible to run a Python script as a service in Windows? If possible, how?
to make a Windows service in Python. I starts OSC and waits for a message to start a video. The thing is, I can't make it start a video. At any stage. I used subprocess.call, I used os.startfile and I used win32api.WinExec. I put the command in a .bat file and started that. Nothing worked. Is it impossible?
I changed the script to start the video when the service starts, so this is not an OSC problem.