cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
304
Views
0
Helpful
1
Replies

Python

zakjka
Level 1
Level 1

Hi, 

 

i hope you are doing well. i have one issue. 

I have IoT set up and when the motion detector is triggered, my Rpi automatically sends email to client (tablet), but every time i need to stop and run again the code. Is there any way to don't do it, so when I trigger the Motion Detector, the Rpi automatically sends email every time to Tablet (so i don't needs to stop and run the code every time). 

i would really appreciate your help
Thank you

1 Reply 1

Torbjørn
VIP
VIP

Welcome to the community @zakjka. This sounds like a fun project!

To be able to give you a good answer to this it would help a lot if you posted your code or some more details about why it needs to be restarted. Please do so if the rest of this question misses the mark.

It sounds like you have a script that waits for your motion sensor to trigger, then sends an email and exits/finishes. If this is the case the easiest solution is to put it all in a while loop with "true" as a conditional. By doing this the loop will start from the top each after each time your existing code executes. It would look something like this:

while true:
  # your code goes here

You might also want to handle the execution of this script as a service with systemd. By doing this you will be able to have your code run as a service/without an interactive user session each time your pi boots. You can find a guide for how to do this here: https://www.makeuseof.com/what-is-systemd-launch-programs-raspberry-pi/ 

I can also recommend this book for learning more about python: https://automatetheboringstuff.com/ 

Happy to help! Please mark as helpful/solution if applicable.
Get in touch: https://torbjorn.dev