I need to set the date and time of my raspberry pi with a php script. After some research I use a php script to call a python script. My datetime.php :
$date = '2015-09-05';
$output = shell_exec('/usr/bin/python/home/pi/datalogger/modules/sys/write_date.py ' . $date);
echo $output;
os.system("sudo date -s "+"'"+date_object+"'")
write_date.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
from datetime import datetime
def main():
date=sys.argv[1]
time='22:04'
print(date) #for debug
string_date=date+' '+time+':00'
date_object2=datetime.strptime(string_date, "%Y-%m-%d %H:%M:%S")
date_object=date_object2.strftime("%a %b %d %H:%M:%S"+" UTC "+"%Y")
os.system("sudo date -s "+"'"+date_object+"'")
if __name__ == '__main__':
main()
When I refresh my datetime.php I got my date print, so the script works... the problem is that my date is not update. But if I run write_date.py my command line I can update the datetime of raspberry.