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
  • 4,960
  • 7
  • 46
  • 70
David Gölzhäuser
  • 3,435
  • 8
  • 46
  • 97
  • 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

3 Answers3

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
  • 250
  • 2
  • 8
  • 23
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
  • 56,214
  • 26
  • 121
  • 139
0

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

mmoore
  • 786
  • 1
  • 6
  • 21