1

I'd like to know how to preform an action every hour in python. My Raspberry Pi should send me information about the temp and so on every hour. Is this possible?

I am new to python and linux, so a detailed explanation would be nice.

user
  • 5,370
  • 8
  • 47
  • 75
David Gölzhäuser
  • 3,525
  • 8
  • 50
  • 98
  • Write a python script and add it to your [crontab](http://blog.davidsingleton.org/raspberry-pi-webcam-a-gentle-intro-to-crontab/). – Katriel May 14 '13 at 12:55
  • http://stackoverflow.com/questions/373335/suggestions-for-a-cron-like-scheduler-in-python – Corey Goldberg May 14 '13 at 14:30

4 Answers4

3

write a python code for having those readings from sensors in to text or csv files and send them to you or to dropbox account

and then put a cron job in linux to run that python script every hour

type in your command line

sudo su

then type

crontab -e

In opened file enter:

/ 0 * * * * /home/pi/yourscript.py

where /home/pi/yourscript.py is your fullpath to python script and it will execute this "yourscript.py" every 60 min.

To send your code to you - you have to choose some way- 1) you can send it to your inbox 2) to dropbox account 3) to sql data base In any case you have to write script for that.

Inderpal Singh
  • 270
  • 2
  • 8
  • 24
2

you can check out the sched module (in the Python standard library).

personally, I'd keep it simpler, and just run your script every hour using a system scheduler like cron.

a basic crontab entry to run hourly (on the hour) might look like this:

0 * * * * /home/foo/myscript.py > /dev/null 2>&1

if you really want to write a scheduler in Python, see some of the answers given here: How do I get a Cron like scheduler in Python?

Community
  • 1
  • 1
Corey Goldberg
  • 59,062
  • 28
  • 129
  • 143
0

The easiest way would be to set up a cron job to call a python script every hour.

Martin
  • 830
  • 1
  • 7
  • 24
0

Use systemd. https://www.digitalocean.com/community/tutorials/what-is-systemd

You can schedule it when you want, and monitor it with journalctl

CrabbyPete
  • 505
  • 9
  • 18