update
This commit is contained in:
@@ -47,7 +47,7 @@ def main():
|
||||
# Calculate time difference (in seconds) if RTC is connected
|
||||
if rtc_time:
|
||||
rtc_time_str = rtc_time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
time_difference = int((system_utc_time - rtc_time).total_seconds()) # Convert to int
|
||||
time_difference = int((utc_time - rtc_time).total_seconds()) # Convert to int
|
||||
else:
|
||||
rtc_time_str = "not connected"
|
||||
time_difference = "N/A" # Not applicable
|
||||
|
||||
@@ -122,6 +122,10 @@
|
||||
<input type="text" class="form-control" id="RTC_utc_time" disabled>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="alert_container"></div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<!-- UPDATE-->
|
||||
@@ -222,6 +226,30 @@ window.onload = function() {
|
||||
document.getElementById("sys_local_time").value = response.system_local_time;
|
||||
document.getElementById("sys_UTC_time").value = response.system_utc_time;
|
||||
document.getElementById("RTC_utc_time").value = response.rtc_module_time;
|
||||
|
||||
// Get the time difference
|
||||
const timeDiff = response.time_difference_seconds;
|
||||
|
||||
// Reference to the alert container
|
||||
const alertContainer = document.getElementById("alert_container");
|
||||
|
||||
// Remove any previous alert
|
||||
alertContainer.innerHTML = "";
|
||||
|
||||
// Add an alert based on time difference
|
||||
if (typeof timeDiff === "number") {
|
||||
if (timeDiff >= 0 && timeDiff <= 10) {
|
||||
alertContainer.innerHTML = `
|
||||
<div class="alert alert-primary" role="alert">
|
||||
RTC and system time are in sync (Difference: ${timeDiff} sec).
|
||||
</div>`;
|
||||
} else if (timeDiff > 10) {
|
||||
alertContainer.innerHTML = `
|
||||
<div class="alert alert-danger" role="alert">
|
||||
RTC time is out of sync! (Difference: ${timeDiff} sec).
|
||||
</div>`;
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
|
||||
Reference in New Issue
Block a user