views:

286

answers:

2

How do I set the hardware clock with Python on embedded linux systems?

Regards,

+4  A: 

Probably no easy way other than doing an os.system() call.

import os
os.system('hwclock --set %s' % date_str)

or using the 'date' command

import os
os.system('date -s %s' % date_str)

or if you are dying to do some c coding, wrapping the system calls with swig... but I think that would be more work than its worth.

zdav
It should be possible to do -- provided the rtc or rtcN driver is present -- via ioctl, in fcntl per http://docs.python.org/library/fcntl.html and rtc(4) (or the kernel's Documentation/rtc.txt) -- however, if you've got Python on the system, hwclock should be an easy fit.
Arthur Shipkowski
Zdav,thanks for the help. Just a note: I'm using busybox, and first a need to change the system clock with "os.system('date -s %s' % date_str)", and then set the hw clock from system clock with os.system('hwclock -w). Regards
Diego Sueiro
+1  A: 

Use Python's os.system function to call the hwclock command.

Josh Kelley