397 lines
15 KiB
HTML
Executable File
397 lines
15 KiB
HTML
Executable File
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>ModuleAir</title>
|
|
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
|
|
<style>
|
|
body {
|
|
overflow-x: hidden;
|
|
}
|
|
#sidebar a.nav-link {
|
|
position: relative;
|
|
display: flex;
|
|
align-items: center;
|
|
}
|
|
#sidebar a.nav-link:hover {
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
}
|
|
#sidebar a.nav-link svg {
|
|
margin-right: 8px; /* Add spacing between icons and text */
|
|
}
|
|
#sidebar {
|
|
transition: transform 0.3s ease-in-out;
|
|
}
|
|
.offcanvas-backdrop {
|
|
z-index: 1040;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<!-- Topbar -->
|
|
<span id="topbar"></span>
|
|
|
|
<!-- Sidebar Offcanvas for Mobile -->
|
|
<div class="offcanvas offcanvas-start text-white bg-dark" tabindex="-1" id="sidebarOffcanvas" aria-labelledby="sidebarOffcanvasLabel">
|
|
<div class="offcanvas-header">
|
|
<h5 class="offcanvas-title" id="sidebarOffcanvasLabel">NebuleAir</h5>
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
|
|
</div>
|
|
<div class="offcanvas-body" id="sidebar_mobile">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container-fluid mt-5">
|
|
<div class="row">
|
|
<!-- Side bar -->
|
|
<aside class="col-md-2 col-lg-1 d-none d-md-block vh-100 position-fixed bg-dark text-white" id="sidebar">
|
|
</aside>
|
|
<!-- Main content -->
|
|
<main class="col-md-10 ms-sm-auto col-lg-11 offset-md-2 offset-lg-1 px-md-4">
|
|
<h1 class="mt-4">Admin</h1>
|
|
|
|
|
|
<div class="row mb-3">
|
|
|
|
<div class="col-lg-3 col-12">
|
|
<h3 class="mt-4">Parameters</h3>
|
|
|
|
<form>
|
|
|
|
<!--
|
|
|
|
<div class="form-check form-switch mb-2">
|
|
<input class="form-check-input" type="checkbox" role="switch" id="flex_loop" onchange="update_config('loop_activation',this.checked)">
|
|
<label class="form-check-label" for="flex_loop">Loop activation</label>
|
|
</div>
|
|
|
|
<div class="form-check form-switch mb-2">
|
|
<input class="form-check-input" type="checkbox" role="switch" id="flex_loop_log" onchange="update_config('loop_log', this.checked)">
|
|
<label class="form-check-label" for="flex_loop_log">Loop Logs</label>
|
|
</div>
|
|
|
|
<div class="form-check form-switch mb-2">
|
|
<input class="form-check-input" type="checkbox" role="switch" id="flex_start_log" onchange="update_config('boot_log', this.checked)">
|
|
<label class="form-check-label" for="flex_start_log">Boot Logs</label>
|
|
</div>
|
|
-->
|
|
|
|
<div class="form-check mb-3">
|
|
<input class="form-check-input" type="checkbox" value="" id="check_NPM_5channels" onchange="update_config('NextPM_5channels', this.checked)">
|
|
<label class="form-check-label" for="check_NPM_5channels">
|
|
Next PM 5 canaux
|
|
</label>
|
|
</div>
|
|
|
|
<div class="form-check mb-3">
|
|
<input class="form-check-input" type="checkbox" value="" id="check_bme280" onchange="update_config('BME280/get_data_v2.py', this.checked)">
|
|
<label class="form-check-label" for="check_bme280">
|
|
Sonde temp/hum (BME280)
|
|
</label>
|
|
</div>
|
|
|
|
<div class="form-check mb-3">
|
|
<input class="form-check-input" type="checkbox" value="" id="check_envea" onchange="update_config('envea/read_value_v2.py', this.checked)">
|
|
<label class="form-check-label" for="check_envea">
|
|
Sonde Envea
|
|
</label>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="device_name" class="form-label">Device Name</label>
|
|
<input type="text" class="form-control" id="device_name" onchange="update_config('deviceName', this.value)">
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="device_ID" class="form-label">Device ID</label>
|
|
<input type="text" class="form-control" id="device_ID" disabled>
|
|
</div>
|
|
|
|
<!--<button type="submit" class="btn btn-primary">Submit</button>-->
|
|
</form>
|
|
</div>
|
|
|
|
<!-- CLOCK-->
|
|
<div class="col-lg-3 col-12">
|
|
|
|
<h3 class="mt-4">Clock</h3>
|
|
|
|
<div class="form-check mb-3">
|
|
<input class="form-check-input" type="checkbox" value="" id="check_RTC" onchange="update_config('i2c_RTC', this.checked)">
|
|
<label class="form-check-label" for="check_RTC">
|
|
RTC module (DS3231)
|
|
</label>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="sys_local_time" class="form-label">System time (local)</label>
|
|
<input type="text" class="form-control" id="sys_local_time" disabled>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="sys_UTC_time" class="form-label">System time (UTC)</label>
|
|
<input type="text" class="form-control" id="sys_UTC_time" disabled>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="RTC_utc_time" class="form-label">RTC time (UTC)</label>
|
|
<input type="text" class="form-control" id="RTC_utc_time" disabled>
|
|
</div>
|
|
|
|
|
|
<div id="alert_container"></div>
|
|
|
|
<h5 class="mt-4">Set RTC</h5>
|
|
|
|
<button type="submit" class="btn btn-primary mb-1" onclick="set_RTC_withNTP()">WiFi (NTP) </button>
|
|
<button type="submit" class="btn btn-primary mb-1" onclick="set_RTC_withBrowser()">Browser time </button>
|
|
<button type="submit" class="btn btn-primary mb-1" onclick="set_RTC_with4G()" disabled>4G (NTP) </button>
|
|
|
|
|
|
</div>
|
|
|
|
<!-- UPDATE-->
|
|
|
|
<div class="col-lg-4 col-12">
|
|
<h3 class="mt-4">Updates</h3>
|
|
|
|
<button type="submit" class="btn btn-primary" onclick="updateGitPull()">Update firmware</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
</main>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- JAVASCRIPT -->
|
|
|
|
<!-- Link Ajax locally -->
|
|
<script src="assets/jquery/jquery-3.7.1.min.js"></script>
|
|
<!-- Link Bootstrap JS and Popper.js locally -->
|
|
<script src="assets/js/bootstrap.bundle.js"></script>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
const elementsToLoad = [
|
|
{ id: 'topbar', file: 'topbar.html' },
|
|
{ id: 'sidebar', file: 'sidebar.html' },
|
|
{ id: 'sidebar_mobile', file: 'sidebar.html' }
|
|
];
|
|
|
|
elementsToLoad.forEach(({ id, file }) => {
|
|
fetch(file)
|
|
.then(response => response.text())
|
|
.then(data => {
|
|
const element = document.getElementById(id);
|
|
if (element) {
|
|
element.innerHTML = data;
|
|
}
|
|
})
|
|
.catch(error => console.error(`Error loading ${file}:`, error));
|
|
});
|
|
});
|
|
|
|
window.onload = function() {
|
|
|
|
fetch('../config.json') // Replace 'deviceID.txt' with 'config.json'
|
|
.then(response => response.json()) // Parse response as JSON
|
|
.then(data => {
|
|
console.log("Getting config file (onload)");
|
|
//get device ID
|
|
const deviceID = data.deviceID.trim().toUpperCase();
|
|
//document.getElementById('pageTitle_plus_ID').innerText = 'token: ' + deviceID;
|
|
//get device Name
|
|
const deviceName = data.deviceName;
|
|
|
|
console.log("Device Name: " + deviceName);
|
|
console.log("Device ID: " + deviceID);
|
|
|
|
|
|
|
|
const elements = document.querySelectorAll('.sideBar_sensorName');
|
|
elements.forEach((element) => {
|
|
element.innerText = deviceName;
|
|
});
|
|
|
|
//get BME check
|
|
const checkbox = document.getElementById("check_bme280");
|
|
checkbox.checked = data["BME280/get_data_v2.py"];
|
|
|
|
//get NPM-5channels check
|
|
const checkbox_NPM_5channels = document.getElementById("check_NPM_5channels");
|
|
checkbox_NPM_5channels.checked = data["NextPM_5channels"];
|
|
|
|
//get sonde Envea check
|
|
const checkbox_envea = document.getElementById("check_envea");
|
|
checkbox_envea.checked = data["envea/read_value_v2.py"];
|
|
|
|
//get RTC check
|
|
const checkbox_RTC = document.getElementById("check_RTC");
|
|
checkbox_RTC.checked = data.i2c_RTC;
|
|
|
|
|
|
//device name
|
|
const device_name = document.getElementById("device_name");
|
|
device_name.value = data.deviceName;
|
|
|
|
//device ID
|
|
const device_ID = document.getElementById("device_ID");
|
|
device_ID.value = data.deviceID.toUpperCase();
|
|
|
|
//get system time and RTC module
|
|
$.ajax({
|
|
url: 'launcher.php?type=sys_RTC_module_time',
|
|
dataType: 'json', // Specify that you expect a JSON response
|
|
method: 'GET', // Use GET or POST depending on your needs
|
|
success: function(response) {
|
|
console.log(response);
|
|
// Update the input fields with the received JSON data
|
|
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-success" 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);
|
|
}
|
|
});
|
|
|
|
//get local RTC
|
|
$.ajax({
|
|
url: 'launcher.php?type=RTC_time',
|
|
dataType: 'text', // Specify that you expect a JSON response
|
|
method: 'GET', // Use GET or POST depending on your needs
|
|
success: function(response) {
|
|
console.log("Local RTC: " + response);
|
|
const RTC_Element = document.getElementById("RTC_time");
|
|
RTC_Element.textContent = response;
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('AJAX request failed:', status, error);
|
|
}
|
|
});
|
|
|
|
})
|
|
.catch(error => console.error('Error loading config.json:', error));
|
|
}
|
|
|
|
|
|
function update_config(param, value){
|
|
console.log("Updating ",param," : ", value);
|
|
$.ajax({
|
|
url: 'launcher.php?type=update_config¶m='+param+'&value='+value,
|
|
dataType: 'text', // Specify that you expect a JSON response
|
|
method: 'GET', // Use GET or POST depending on your needs
|
|
cache: false, // Prevent AJAX from caching
|
|
success: function(response) {
|
|
console.log(response);
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('AJAX request failed:', status, error);
|
|
}
|
|
});
|
|
}
|
|
|
|
function updateGitPull(){
|
|
console.log("Updating device (git pull)");
|
|
|
|
$.ajax({
|
|
url: 'launcher.php?type=git_pull',
|
|
method: 'GET', // Use GET or POST depending on your needs
|
|
dataType: 'text', // Specify that you expect a JSON response
|
|
|
|
success: function(response) {
|
|
// Handle success response if needed
|
|
console.log(response);
|
|
alert(response);
|
|
// Reload the page after the device update
|
|
location.reload(); // This will reload the page
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('AJAX request failed:', status, error);
|
|
}
|
|
});
|
|
}
|
|
|
|
function set_RTC_withNTP(){
|
|
console.log("Set RTC module with WIFI (NTP server)");
|
|
|
|
$.ajax({
|
|
url: 'launcher.php?type=set_RTC_withNTP',
|
|
method: 'GET', // Use GET or POST depending on your needs
|
|
dataType: 'text', // Specify that you expect a JSON response
|
|
|
|
success: function(response) {
|
|
// Handle success response if needed
|
|
console.log(response);
|
|
alert(response);
|
|
// Reload the page after the device update
|
|
location.reload(); // This will reload the page
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('AJAX request failed:', status, error);
|
|
}
|
|
});
|
|
}
|
|
|
|
function set_RTC_withBrowser(){
|
|
console.log("Set RTC module with browser time");
|
|
const browserTime = new Date(); // Get the current time in the browser
|
|
const formattedTime = browserTime.toISOString(); // Convert to ISO string (UTC)
|
|
console.log(formattedTime);
|
|
|
|
$.ajax({
|
|
url: `launcher.php?type=set_RTC_withBrowser&time=${encodeURIComponent(formattedTime)}`,
|
|
method: 'GET', // Use GET or POST depending on your needs
|
|
dataType: 'json', // Specify that you expect a JSON response
|
|
|
|
success: function(response) {
|
|
// Handle success response if needed
|
|
console.log(response);
|
|
if (response.success) {
|
|
alert("RTC successfully updated!");
|
|
} else {
|
|
alert(`Error: ${response.message}`);
|
|
} // Reload the page after the device update
|
|
location.reload(); // This will reload the page
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error('AJAX request failed:', status, error);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|