You need to sign in or sign up before continuing.
Commit 270b2a17 authored by sikhin.vc's avatar sikhin.vc

Add new file

parent 46bc8919
import datetime
import requests
import logging
import ctypes
import ctypes.util
import time
def set_time(time_):
CLOCK_REALTIME = 0
class TimesSpec(ctypes.Structure):
_fields_ = [("tv_sec", ctypes.c_long),
("tv_nsec", ctypes.c_long)]
librt = ctypes.CDLL(ctypes.util.find_library("rt"))
ts = TimesSpec()
ts.tv_sec = int(time.mktime(datetime.datetime(*time_[:6]).timetuple()))
ts.tv_nsec = time_[6] * 1000000 # Millisecond to nanosecond
librt.clock_settime(CLOCK_REALTIME, ctypes.byref(ts))
logging.info(f"Successfully set time to {time_}")
try:
response = requests.get("http://192.168.3.181/camera_api/get_curr_datetime")
time_tuple = tuple(response.json()["current_time"])
logging.info(f"Fetched datetime from API : {time_tuple}")
set_time(time_tuple)
except Exception as e:
logging.info(f"Failed to update datetime : {e}")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment