From e2ab64f8c8d1959f22d49abd32f791d4d94054ed Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sat, 9 Nov 2024 19:21:01 -0500 Subject: [PATCH 01/23] Added placeholder table --- ui/general/health.html | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ui/general/health.html b/ui/general/health.html index 86b6d5a..33e9ed8 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -19,6 +19,31 @@ + + + + + + + + + + + + + + + + + + + + + + + +
droneMu1Mu2Mu3
IP Address123
Docker ContainerContainer1Container2Container3
+ -- 2.40.1 From dc0049f818e480f51a9004403a9f885f313230a4 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sun, 10 Nov 2024 00:22:00 -0500 Subject: [PATCH 02/23] Added royalty free drone icon from https://uxwing.com/drone-icon/ --- ui/general/assets/drone-icon.svg | 1 + ui/general/health.html | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 ui/general/assets/drone-icon.svg diff --git a/ui/general/assets/drone-icon.svg b/ui/general/assets/drone-icon.svg new file mode 100644 index 0000000..6ab5781 --- /dev/null +++ b/ui/general/assets/drone-icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ui/general/health.html b/ui/general/health.html index 33e9ed8..ed9a7f0 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -18,11 +18,30 @@ + +
+
+
+
+ Select a Drone for Inspection +
+
+
+
+ + +
+
+
+
+
+
+ - + -- 2.40.1 From 64822a68c76bbcc7b9f60c2bcd26380c3ed5608a Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sun, 10 Nov 2024 02:13:25 -0500 Subject: [PATCH 03/23] trying to make a working dropdown --- ui/general/assets/{ => icons}/drone-icon.svg | 0 ui/general/health.html | 14 +++++++-- ui/general/health.js | 31 ++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) rename ui/general/assets/{ => icons}/drone-icon.svg (100%) diff --git a/ui/general/assets/drone-icon.svg b/ui/general/assets/icons/drone-icon.svg similarity index 100% rename from ui/general/assets/drone-icon.svg rename to ui/general/assets/icons/drone-icon.svg diff --git a/ui/general/health.html b/ui/general/health.html index ed9a7f0..e474b52 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -23,13 +23,21 @@
- Select a Drone for Inspection + Select a Drone for Inspection
- - +
diff --git a/ui/general/health.js b/ui/general/health.js index 8f3dacd..b754384 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -1,9 +1,40 @@ // Elements +const drone = document.getElementById("drone"); + +const drones = [ + // 2.4 GHz Channels + ["1", "mu1"], ["2", "mu2"], ["3", "mu3"], + ["4", "mu4"], ["5", "mu5"], ["6", "mu6"] +] // Load initial settings document.onload = initPage(); // Function to initialize the page function initPage() { + +} + +function successReadFile(content) { + try { + // Drone selection + const currentDrone = getValueByKey(content, "common", "drone"); + + addDropDown(drone, drones, currentDrone); + } catch (e) { + failureReadFile(e); + } +} + +// Restart wifibroadcast service +function restartDroneDisplayService() { + cockpit.spawn(["systemctl", "restart", "dronedisplay@drone"], { superuser: "require" }) + .then(() => { + displaySuccess("dronedisplay@drone service restarted."); + }) + .catch((error) => { + console.error("Failed to restart dronedisplay@drone service:", error); + displayFail("Failed to restart dronedisplay@drone service: " + error); + }); } -- 2.40.1 From 6e9049c3a475aa595f645ec4d2e089681fd36557 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sun, 10 Nov 2024 02:46:13 -0500 Subject: [PATCH 04/23] dropdown not dropping --- ui/general/health.html | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/ui/general/health.html b/ui/general/health.html index e474b52..20ac22a 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -26,18 +26,14 @@ Select a Drone for Inspection
-
-
- +
-- 2.40.1 From 4c6b679bab15e613f09c09816e3fae97fa05ec9c Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Mon, 11 Nov 2024 01:37:29 -0500 Subject: [PATCH 05/23] Trying different dropdowns to see if I can get any to work --- ui/general/health.html | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ui/general/health.html b/ui/general/health.html index 20ac22a..44b66b0 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -36,6 +36,27 @@ Drone3
+ +
-- 2.40.1 From 364cb5f85a59aced6c6e78cce67100672a35e723 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Mon, 11 Nov 2024 02:06:30 -0500 Subject: [PATCH 06/23] Still looking at getting a dropdown working --- ui/general/health.html | 5 +++++ ui/general/health.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/ui/general/health.html b/ui/general/health.html index 44b66b0..a95a4e9 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -57,6 +57,11 @@
  • Something else here
  • +
    + + + +
    diff --git a/ui/general/health.js b/ui/general/health.js index b754384..3f3570c 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -13,7 +13,22 @@ document.onload = initPage(); // Function to initialize the page function initPage() { + // TODO: Replace /home/spiri/services with some root level path + // Search for drones files in the services directory and populate the dropdown with directory names + const currentDrone = getValueByKey(content, "common", "drone"); + addDropDown(drone, drones, currentDrone); +} + +function dockerComposeFileChanged() { + if (composeFileSelection.value === "") { + populateEditor(""); + return; + } + const composeLocation = composeFileSelection.value + "/docker-compose.yaml"; + cockpit.file(composeLocation) + .read().then((content) => successReadFile(content)) + .catch(error => failureReadFile(error)); } function successReadFile(content) { -- 2.40.1 From 01a2ada8103dba5df5a15b0b8822e8d9a32d8b53 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Mon, 11 Nov 2024 11:53:05 -0500 Subject: [PATCH 07/23] Trying different methods for dropdown --- ui/general/health.html | 9 +++++++++ ui/general/health.js | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ui/general/health.html b/ui/general/health.html index a95a4e9..2c7510c 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -66,6 +66,15 @@ + +
    droneDrone Mu1 Mu2 Mu3
    diff --git a/ui/general/health.js b/ui/general/health.js index 3f3570c..36c86f9 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -3,7 +3,6 @@ const drone = document.getElementById("drone"); const drones = [ - // 2.4 GHz Channels ["1", "mu1"], ["2", "mu2"], ["3", "mu3"], ["4", "mu4"], ["5", "mu5"], ["6", "mu6"] ] @@ -20,6 +19,16 @@ function initPage() { addDropDown(drone, drones, currentDrone); } +function handleSelect(account) { + var drone1Table = "
    test
    "; + switch(account) + { + case "Drone1": + document.getElementById("myTableContainer").innerHTML = drone1Table + break; + } +} + function dockerComposeFileChanged() { if (composeFileSelection.value === "") { populateEditor(""); -- 2.40.1 From beef00e14ae061e6678a6a7ebce6e5ce4ebdf078 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Mon, 11 Nov 2024 13:04:12 -0500 Subject: [PATCH 08/23] Trying to get values to appear for bootstrap dropdowns --- ui/general/health.html | 19 +++++++++++++++---- ui/general/health.js | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/ui/general/health.html b/ui/general/health.html index 2c7510c..867dea5 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -5,6 +5,7 @@ Health Status + @@ -62,17 +63,27 @@ +
    diff --git a/ui/general/health.js b/ui/general/health.js index 36c86f9..ebb7343 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -20,12 +20,28 @@ function initPage() { } function handleSelect(account) { - var drone1Table = "
    test
    "; + var drone1Table = "
    Drone1
    "; + var drone2Table = "
    Drone2
    "; + var drone3Table = "
    Drone3/td>
    "; + var drone4Table = "
    Drone4
    "; + var drone5Table = "
    Drone5
    "; switch(account) { case "Drone1": document.getElementById("myTableContainer").innerHTML = drone1Table break; + case "Drone2": + document.getElementById("myTableContainer").innerHTML = drone2Table + break; + case "Drone3": + document.getElementById("myTableContainer").innerHTML = drone3Table + break; + case "Drone4": + document.getElementById("myTableContainer").innerHTML = drone4Table + break; + case "Drone5": + document.getElementById("myTableContainer").innerHTML = drone5Table + break; } } -- 2.40.1 From a8c2d628e0c2bd296b516866125a48b9369cbc03 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sat, 16 Nov 2024 18:38:52 -0500 Subject: [PATCH 09/23] Deleted some code for one of the dropdowns so it no longer works, and the new code copied over also doesn't work --- ui/general/health.js | 70 ++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/ui/general/health.js b/ui/general/health.js index ebb7343..56ed570 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -10,6 +10,8 @@ const drones = [ // Load initial settings document.onload = initPage(); +document.getElementById("save").addEventListener("click", saveSettings); + // Function to initialize the page function initPage() { // TODO: Replace /home/spiri/services with some root level path @@ -45,36 +47,54 @@ function handleSelect(account) { } } -function dockerComposeFileChanged() { - if (composeFileSelection.value === "") { - populateEditor(""); - return; - } - const composeLocation = composeFileSelection.value + "/docker-compose.yaml"; - cockpit.file(composeLocation) - .read().then((content) => successReadFile(content)) - .catch(error => failureReadFile(error)); -} +// Save configuration values to the configuration file +function saveSettings() { -function successReadFile(content) { try { - // Drone selection - const currentDrone = getValueByKey(content, "common", "drone"); - - addDropDown(drone, drones, currentDrone); + cockpit.file(confLocation) + .read() + .then((content) => { + // WiFi & Temperature Configuration + content = setValueByKey(content, "[common]", "drone_channel", drone_channel.value); + + cockpit.file(confLocation, { superuser: "try" }).replace(content) + .then(() => { + displayDroneTable(); + displaySuccess("table updated successfully."); + }) + .catch((error) => { + displayFail("Failed to update table: " + error.message); + }); + }) + .catch(error => { + displayFail("Failed to update table: " + error.message); + }); } catch (e) { + console.error("Error during update operation:", e); failureReadFile(e); } } -// Restart wifibroadcast service -function restartDroneDisplayService() { - cockpit.spawn(["systemctl", "restart", "dronedisplay@drone"], { superuser: "require" }) - .then(() => { - displaySuccess("dronedisplay@drone service restarted."); - }) - .catch((error) => { - console.error("Failed to restart dronedisplay@drone service:", error); - displayFail("Failed to restart dronedisplay@drone service: " + error); - }); + +// Restart drone service +function displayDroneTable() { + upaate table } + +function addDropDown(box, pairs, defaultValue) { + try { + for(let i = 0; i < pairs.length; i++){ + if (pairs[i].length == 0 || pairs[i][0] === "" || pairs[i][1] === "") continue; + const option = document.createElement("option"); + option.value = pairs[i][0]; + option.text = pairs[i][1]; + box.add(option); + if (defaultValue === option.value) { + box.value = option.value; + } + } + } + catch(e) { + displayFail(e) + } +} \ No newline at end of file -- 2.40.1 From a339e910c40450e1640958a171c6ffcffa2b5151 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sat, 16 Nov 2024 23:02:56 -0500 Subject: [PATCH 10/23] Asking ChatGPT for help --- ui/general/health.html | 15 ++++++++++++++- ui/general/health.js | 6 +++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ui/general/health.html b/ui/general/health.html index 867dea5..e6656f8 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -7,6 +7,9 @@ + + + @@ -85,8 +88,18 @@ +
    - + diff --git a/ui/general/health.js b/ui/general/health.js index 56ed570..c75f668 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -12,6 +12,9 @@ document.onload = initPage(); document.getElementById("save").addEventListener("click", saveSettings); +const dropdownElement = document.getElementById('dropdownMenuButton1'); +new bootstrap.Dropdown(dropdownElement); + // Function to initialize the page function initPage() { // TODO: Replace /home/spiri/services with some root level path @@ -78,7 +81,8 @@ function saveSettings() { // Restart drone service function displayDroneTable() { - upaate table + // upaate table + ; } function addDropDown(box, pairs, defaultValue) { -- 2.40.1 From 48d28615fe20f033a4f86e1932ce4506d8edb678 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sun, 17 Nov 2024 00:26:52 -0500 Subject: [PATCH 11/23] Still nothing working --- ui/general/health.js | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/general/health.js b/ui/general/health.js index c75f668..fd75152 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -14,7 +14,6 @@ document.getElementById("save").addEventListener("click", saveSettings); const dropdownElement = document.getElementById('dropdownMenuButton1'); new bootstrap.Dropdown(dropdownElement); - // Function to initialize the page function initPage() { // TODO: Replace /home/spiri/services with some root level path -- 2.40.1 From d04c1bd2c5f63e407acd77ce0d202e6013e36132 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Mon, 18 Nov 2024 15:51:17 -0500 Subject: [PATCH 12/23] Youssof explained a dropdown --- ui/general/assets/icons/drone-icon.svg | 2 +- ui/general/health.html | 69 ++------------------------ ui/general/health.js | 42 +++------------- 3 files changed, 13 insertions(+), 100 deletions(-) diff --git a/ui/general/assets/icons/drone-icon.svg b/ui/general/assets/icons/drone-icon.svg index 6ab5781..5f510a9 100644 --- a/ui/general/assets/icons/drone-icon.svg +++ b/ui/general/assets/icons/drone-icon.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/ui/general/health.html b/ui/general/health.html index e6656f8..94f52c9 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -7,9 +7,6 @@ - - - @@ -30,76 +27,20 @@ Select a Drone for Inspection
    - - - +
    - +
    - +
    - -
    -
    diff --git a/ui/general/health.js b/ui/general/health.js index fd75152..a4c3115 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -1,6 +1,7 @@ // Elements const drone = document.getElementById("drone"); +const droneDropdown = document.getElementById("droneSelection"); const drones = [ ["1", "mu1"], ["2", "mu2"], ["3", "mu3"], @@ -10,26 +11,25 @@ const drones = [ // Load initial settings document.onload = initPage(); -document.getElementById("save").addEventListener("click", saveSettings); +droneDropdown.addEventListener("change", droneChange); -const dropdownElement = document.getElementById('dropdownMenuButton1'); -new bootstrap.Dropdown(dropdownElement); // Function to initialize the page function initPage() { // TODO: Replace /home/spiri/services with some root level path // Search for drones files in the services directory and populate the dropdown with directory names - const currentDrone = getValueByKey(content, "common", "drone"); - addDropDown(drone, drones, currentDrone); + addDropDown(droneDropdown, drones, "1"); } -function handleSelect(account) { +function droneChange() { + console.log(droneDropdown.value); + return ; var drone1Table = "
    Drone1
    "; var drone2Table = "
    Drone2
    "; var drone3Table = "
    Drone3/td>
    "; var drone4Table = "
    Drone4
    "; var drone5Table = "
    Drone5
    "; - switch(account) + switch(droneDropdown.value) { case "Drone1": document.getElementById("myTableContainer").innerHTML = drone1Table @@ -49,34 +49,6 @@ function handleSelect(account) { } } -// Save configuration values to the configuration file -function saveSettings() { - - try { - cockpit.file(confLocation) - .read() - .then((content) => { - // WiFi & Temperature Configuration - content = setValueByKey(content, "[common]", "drone_channel", drone_channel.value); - - cockpit.file(confLocation, { superuser: "try" }).replace(content) - .then(() => { - displayDroneTable(); - displaySuccess("table updated successfully."); - }) - .catch((error) => { - displayFail("Failed to update table: " + error.message); - }); - }) - .catch(error => { - displayFail("Failed to update table: " + error.message); - }); - } catch (e) { - console.error("Error during update operation:", e); - failureReadFile(e); - } -} - // Restart drone service function displayDroneTable() { -- 2.40.1 From 957d0319dfcb0edad28a5162534f45ebe433a8e9 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sun, 24 Nov 2024 16:47:47 -0500 Subject: [PATCH 13/23] updating table based on host computer --- ui/general/health.html | 12 +++--------- ui/general/health.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ui/general/health.html b/ui/general/health.html index 94f52c9..1f76b66 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -46,23 +46,17 @@ Drone - Mu1 - Mu2 - Mu3 + IP Address - 1 - 2 - 3 + Docker Container - Container1 - Container2 - Container3 + diff --git a/ui/general/health.js b/ui/general/health.js index a4c3115..1a8391d 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -19,6 +19,24 @@ function initPage() { // Search for drones files in the services directory and populate the dropdown with directory names addDropDown(droneDropdown, drones, "1"); + const command1 = "hostname -I" + const command2 = "hostname" + const command3 = "docker container ls" + cockpit.spawn(["bash", "-c", command1]) + .then((data) => { + console.log(data.split(" ")[0]); + }) + .catch((error) => console.log(error)); + cockpit.spawn(["bash", "-c", command2]) + .then((data) => { + console.log(data.split(" ")[0]); + }) + .catch((error) => console.log(error)); + cockpit.spawn(["bash", "-c", command3]) + .then((data) => { + console.log(data.split(" ")[0]); + }) + .catch((error) => console.log(error)); } function droneChange() { -- 2.40.1 From d11117844f4d89659b78ed0ffa0916a56fad47d4 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sun, 24 Nov 2024 17:23:45 -0500 Subject: [PATCH 14/23] I think the table works --- ui/general/health.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ui/general/health.js b/ui/general/health.js index 1a8391d..ac3e35d 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -2,6 +2,9 @@ // Elements const drone = document.getElementById("drone"); const droneDropdown = document.getElementById("droneSelection"); +const droneName = document.getElementById("name"); +const address = document.getElementById("address"); +const container = document.getElementById("container"); const drones = [ ["1", "mu1"], ["2", "mu2"], ["3", "mu3"], @@ -19,22 +22,27 @@ function initPage() { // Search for drones files in the services directory and populate the dropdown with directory names addDropDown(droneDropdown, drones, "1"); - const command1 = "hostname -I" - const command2 = "hostname" + const command1 = "hostname" + const command2 = "hostname -I" const command3 = "docker container ls" cockpit.spawn(["bash", "-c", command1]) .then((data) => { - console.log(data.split(" ")[0]); + droneName.innerHTML = data.split(" ")[0]; }) .catch((error) => console.log(error)); cockpit.spawn(["bash", "-c", command2]) .then((data) => { - console.log(data.split(" ")[0]); + address.innerHTML = data.split(" ")[0]; }) .catch((error) => console.log(error)); cockpit.spawn(["bash", "-c", command3]) .then((data) => { - console.log(data.split(" ")[0]); + const datalist = data.split("\n"); + for (let i = 0; i < datalist.length - 2; i++) { + container.innerHTML += datalist[i + 1].split(" ")[0]; + container.innerHTML += "
    "; + } + container.innerHTML += datalist[datalist.length - 1].split(" ")[0] }) .catch((error) => console.log(error)); } -- 2.40.1 From 8d2f837c013937ae8290d9d556da7d38042f2367 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Wed, 27 Nov 2024 03:53:47 -0500 Subject: [PATCH 15/23] Cleaned up Health page to remove dropdown, and delete any random code in the JS file --- ui/general/health.html | 23 ++------------ ui/general/health.js | 72 +++--------------------------------------- 2 files changed, 6 insertions(+), 89 deletions(-) diff --git a/ui/general/health.html b/ui/general/health.html index 1f76b66..75493a4 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -15,27 +15,8 @@

    Health Status

    -

    At a glance view of the status of the drone.

    -
    -
    - - -
    -
    -
    -
    - Select a Drone for Inspection -
    -
    - -
    - - - -
    - +
    + At a glance view of the status of the drone.
    diff --git a/ui/general/health.js b/ui/general/health.js index ac3e35d..80cd38d 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -1,27 +1,16 @@ - // Elements -const drone = document.getElementById("drone"); -const droneDropdown = document.getElementById("droneSelection"); const droneName = document.getElementById("name"); const address = document.getElementById("address"); const container = document.getElementById("container"); -const drones = [ - ["1", "mu1"], ["2", "mu2"], ["3", "mu3"], - ["4", "mu4"], ["5", "mu5"], ["6", "mu6"] -] - -// Load initial settings +// Load page + drone settings document.onload = initPage(); -droneDropdown.addEventListener("change", droneChange); - // Function to initialize the page function initPage() { - // TODO: Replace /home/spiri/services with some root level path - // Search for drones files in the services directory and populate the dropdown with directory names - - addDropDown(droneDropdown, drones, "1"); + // Populate table with drone name, drone IP address, and drone docker containers that are running + // Name corresponds to host computer's name, IP address is host computer's address + // and docker containers are all those displayed by docker container ls const command1 = "hostname" const command2 = "hostname -I" const command3 = "docker container ls" @@ -45,57 +34,4 @@ function initPage() { container.innerHTML += datalist[datalist.length - 1].split(" ")[0] }) .catch((error) => console.log(error)); -} - -function droneChange() { - console.log(droneDropdown.value); - return ; - var drone1Table = "
    Drone1
    "; - var drone2Table = "
    Drone2
    "; - var drone3Table = "
    Drone3/td>
    "; - var drone4Table = "
    Drone4
    "; - var drone5Table = "
    Drone5
    "; - switch(droneDropdown.value) - { - case "Drone1": - document.getElementById("myTableContainer").innerHTML = drone1Table - break; - case "Drone2": - document.getElementById("myTableContainer").innerHTML = drone2Table - break; - case "Drone3": - document.getElementById("myTableContainer").innerHTML = drone3Table - break; - case "Drone4": - document.getElementById("myTableContainer").innerHTML = drone4Table - break; - case "Drone5": - document.getElementById("myTableContainer").innerHTML = drone5Table - break; - } -} - - -// Restart drone service -function displayDroneTable() { - // upaate table - ; -} - -function addDropDown(box, pairs, defaultValue) { - try { - for(let i = 0; i < pairs.length; i++){ - if (pairs[i].length == 0 || pairs[i][0] === "" || pairs[i][1] === "") continue; - const option = document.createElement("option"); - option.value = pairs[i][0]; - option.text = pairs[i][1]; - box.add(option); - if (defaultValue === option.value) { - box.value = option.value; - } - } - } - catch(e) { - displayFail(e) - } } \ No newline at end of file -- 2.40.1 From d739e3de6934b4b0cc875c53c7a4c57065b17c93 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Fri, 29 Nov 2024 13:35:27 -0500 Subject: [PATCH 16/23] Added new rows and containers error message --- ui/general/health.html | 32 ++++++++++++++++++++++++++++++++ ui/general/health.js | 14 ++++++++++---- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/ui/general/health.html b/ui/general/health.html index 75493a4..da77730 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -39,6 +39,38 @@ Docker Container + + Connection Upstream + + + + Network SSID + + + + Camera Devices + + + + Connected Devices + + + + Zerotier IP + N/A + + + Hotspot Connections + N/A + + + GCS + N/A + + + FCU Firmware + N/A + diff --git a/ui/general/health.js b/ui/general/health.js index 80cd38d..ff6e2f4 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -14,6 +14,7 @@ function initPage() { const command1 = "hostname" const command2 = "hostname -I" const command3 = "docker container ls" + const command4 = "" cockpit.spawn(["bash", "-c", command1]) .then((data) => { droneName.innerHTML = data.split(" ")[0]; @@ -27,11 +28,16 @@ function initPage() { cockpit.spawn(["bash", "-c", command3]) .then((data) => { const datalist = data.split("\n"); - for (let i = 0; i < datalist.length - 2; i++) { - container.innerHTML += datalist[i + 1].split(" ")[0]; - container.innerHTML += "
    "; + if (datalist[1].split(" ")[0] == ""){ + container.className = "p-3 mb-2 bg-danger text-white"; + container.innerHTML += "Error: No Docker Containers to Display"; + } else { + for (let i = 0; i < datalist.length - 2; i++) { + container.innerHTML += datalist[i + 1].split(" ")[0]; + container.innerHTML += "
    "; + } + container.innerHTML += datalist[datalist.length - 1].split(" ")[0]; } - container.innerHTML += datalist[datalist.length - 1].split(" ")[0] }) .catch((error) => console.log(error)); } \ No newline at end of file -- 2.40.1 From 6e4c4fe37190f7279a51e02bcd3dccef6d4fb7c1 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Fri, 29 Nov 2024 16:04:26 -0500 Subject: [PATCH 17/23] working on getting information for connections upstream, camera devices, and connected devices --- ui/general/health.js | 72 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/ui/general/health.js b/ui/general/health.js index ff6e2f4..71cb195 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -2,6 +2,10 @@ const droneName = document.getElementById("name"); const address = document.getElementById("address"); const container = document.getElementById("container"); +const upstream = document.getElementById("upstream"); +const ssid = document.getElementById("ssid"); +const camera = document.getElementById("camera"); +const devices = document.getElementById("devices"); // Load page + drone settings document.onload = initPage(); @@ -14,17 +18,22 @@ function initPage() { const command1 = "hostname" const command2 = "hostname -I" const command3 = "docker container ls" - const command4 = "" + const command4 = "ping google.com" + const command5 = "iwgetid -r" + const command6 = "ls /dev/" + cockpit.spawn(["bash", "-c", command1]) .then((data) => { droneName.innerHTML = data.split(" ")[0]; }) .catch((error) => console.log(error)); + cockpit.spawn(["bash", "-c", command2]) .then((data) => { address.innerHTML = data.split(" ")[0]; }) .catch((error) => console.log(error)); + cockpit.spawn(["bash", "-c", command3]) .then((data) => { const datalist = data.split("\n"); @@ -40,4 +49,65 @@ function initPage() { } }) .catch((error) => console.log(error)); + + cockpit.spawn(["bash", "-c", command4]) + .then((data) => { + const datalist = data.split(" "); + if (datalist[0] == "ping:"){ + upstream.innerHTML = "Connection LIMITED - No upstream"; + } else if (datalist[0] == "PING") { + upstream.innerHTML = "Connection OK" + } else { + upstream.innerHTML = "Connection DOWN" + } + }) + .catch((error) => console.log(error)); + + cockpit.spawn(["bash", "-c", command5]) + .then((data) => { + if (data.length == 0) { + ssid.innerHTML = "None"; + } else { + ssid.innerHTML = data + } + }) + .catch((error) => console.log(error)); + + cockpit.spawn(["bash", "-c", command6]) + .then((data) => { + const datalist = data.split(" "); + count = 0 + for (let i = 0; i < datalist.length - 2; i++) { + if (datalist[i].contains(video)){ + if (count == 0) { + camera.innerHTML += "/dev/" + datalist[i]; + count++ + } else { + camera.innerHTML += "
    "; + camera.innerHTML += "/dev/" + datalist[i]; + count++ + } + } + } + if (count == 0) { + camera.innerHTML = "No Video Devices"; + } + }) + .catch((error) => console.log(error)); + + cockpit.spawn(["bash", "-c", command7]) + .then((data) => { + const datalist = data.split("\n"); + if (datalist[1].split(" ")[0] == ""){ + container.className = "p-3 mb-2 bg-danger text-white"; + container.innerHTML += "Error: No Docker Containers to Display"; + } else { + for (let i = 0; i < datalist.length - 2; i++) { + container.innerHTML += datalist[i + 1].split(" ")[0]; + container.innerHTML += "
    "; + } + container.innerHTML += datalist[datalist.length - 1].split(" ")[0]; + } + }) + .catch((error) => console.log(error)); } \ No newline at end of file -- 2.40.1 From 447a0348a244ae2ca92a7b9e6bd9a156fc8a5348 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sat, 30 Nov 2024 20:30:05 -0500 Subject: [PATCH 18/23] finished adding something for each row of health table, will have to have it reviewed ofc --- index.html | 14 ++++++++ index.html.1 | 14 ++++++++ ui/general/health.html | 1 - ui/general/health.js | 79 ++++++++++++++++++++++++------------------ 4 files changed, 74 insertions(+), 34 deletions(-) create mode 100644 index.html create mode 100644 index.html.1 diff --git a/index.html b/index.html new file mode 100644 index 0000000..86991f9 --- /dev/null +++ b/index.html @@ -0,0 +1,14 @@ +Google



     

    Advanced search

    Google offered in: Français

    © 2024 - Privacy - Terms

    \ No newline at end of file diff --git a/index.html.1 b/index.html.1 new file mode 100644 index 0000000..5efaa2c --- /dev/null +++ b/index.html.1 @@ -0,0 +1,14 @@ +Google



     

    Advanced search

    Google offered in: Français

    © 2024 - Privacy - Terms

    \ No newline at end of file diff --git a/ui/general/health.html b/ui/general/health.html index da77730..e5af317 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -5,7 +5,6 @@ Health Status - diff --git a/ui/general/health.js b/ui/general/health.js index 71cb195..fab1f36 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -18,9 +18,32 @@ function initPage() { const command1 = "hostname" const command2 = "hostname -I" const command3 = "docker container ls" - const command4 = "ping google.com" + const command4 = "ping google.com -c 1" const command5 = "iwgetid -r" - const command6 = "ls /dev/" + const command6 = "ls /dev/video*" + + // Commands for listing all Connected Devices + const command7 = "ls /dev/block/*" + const command8 = "ls /dev/bus/*" + const command9 = "ls /dev/char/*" + const command10 = "ls /dev/cpu/*" + const command11 = "ls /dev/disk/*" + const command12 = "ls /dev/dma_heap/*" + const command13 = "ls /dev/dri/*" + const command14 = "ls /dev/fd/*" + const command15 = "ls /dev/hugepages/*" + const command16 = "ls /dev/input/*" + const command17 = "ls /dev/mapper/*" + const command18 = "ls /dev/mqueue/*" + const command19 = "ls /dev/net/*" + const command20 = "ls /dev/pts/*" + const command21 = "ls /dev/shm/*" + const command22 = "ls /dev/snd/*" + const command23 = "ls /dev/v4l/*" + const command24 = "ls /dev/vfio/*" + const devices_commands = [command7, command8, command9, command10, command11, command12, command13, command14, command15, + command16, command17, command18, command19, command20, command21, command22, command23, command24 + ]; cockpit.spawn(["bash", "-c", command1]) .then((data) => { @@ -56,9 +79,9 @@ function initPage() { if (datalist[0] == "ping:"){ upstream.innerHTML = "Connection LIMITED - No upstream"; } else if (datalist[0] == "PING") { - upstream.innerHTML = "Connection OK" + upstream.innerHTML = "Connection OK"; } else { - upstream.innerHTML = "Connection DOWN" + upstream.innerHTML = "Connection DOWN"; } }) .catch((error) => console.log(error)); @@ -75,39 +98,29 @@ function initPage() { cockpit.spawn(["bash", "-c", command6]) .then((data) => { - const datalist = data.split(" "); - count = 0 - for (let i = 0; i < datalist.length - 2; i++) { - if (datalist[i].contains(video)){ - if (count == 0) { - camera.innerHTML += "/dev/" + datalist[i]; - count++ - } else { - camera.innerHTML += "
    "; - camera.innerHTML += "/dev/" + datalist[i]; - count++ - } - } + if (data.length == 0) { + camera.innerHTML = "No Camera Devices Detected"; } - if (count == 0) { - camera.innerHTML = "No Video Devices"; + else { + const datalist = data.replaceAll("\n", "
    "); + camera.innerHTML += datalist; } }) .catch((error) => console.log(error)); - cockpit.spawn(["bash", "-c", command7]) - .then((data) => { - const datalist = data.split("\n"); - if (datalist[1].split(" ")[0] == ""){ - container.className = "p-3 mb-2 bg-danger text-white"; - container.innerHTML += "Error: No Docker Containers to Display"; - } else { - for (let i = 0; i < datalist.length - 2; i++) { - container.innerHTML += datalist[i + 1].split(" ")[0]; - container.innerHTML += "
    "; + count = 0; + for (let i = 0; i < devices_commands.length; i++) { + cockpit.spawn(["bash", "-c", devices_commands[i]]) + .then((data) => { + if (data.length != 0) { + devices.innerHTML += data.replaceAll("\n", "
    "); + devices.innerHTML += "
    "; + count++ } - container.innerHTML += datalist[datalist.length - 1].split(" ")[0]; - } - }) - .catch((error) => console.log(error)); + }) + .catch((error) => console.log(error)); + } + if (count > 0) { + devices.innerHTML -= "
    " + } } \ No newline at end of file -- 2.40.1 From bc4bd7d39bad85c79048b11f8ca072216278a410 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sat, 30 Nov 2024 20:39:45 -0500 Subject: [PATCH 19/23] fixed margins on health table --- ui/general/health.html | 104 ++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/ui/general/health.html b/ui/general/health.html index e5af317..690520a 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -17,61 +17,61 @@
    At a glance view of the status of the drone.
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Drone +
    IP Address
    Docker Container
    Connection Upstream
    Network SSID
    Camera Devices
    Connected Devices
    Zerotier IPN/A
    Hotspot ConnectionsN/A
    GCSN/A
    FCU FirmwareN/A
    +
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Drone -
    IP Address
    Docker Container
    Connection Upstream
    Network SSID
    Camera Devices
    Connected Devices
    Zerotier IPN/A
    Hotspot ConnectionsN/A
    GCSN/A
    FCU FirmwareN/A
    -- 2.40.1 From 5d86cbb74ae294068d90f2008d5f10524b79bb0d Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sat, 30 Nov 2024 22:21:27 -0500 Subject: [PATCH 20/23] Added connected devices list to health table --- ui/general/health.js | 54 +++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/ui/general/health.js b/ui/general/health.js index fab1f36..ec04394 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -22,28 +22,8 @@ function initPage() { const command5 = "iwgetid -r" const command6 = "ls /dev/video*" - // Commands for listing all Connected Devices - const command7 = "ls /dev/block/*" - const command8 = "ls /dev/bus/*" - const command9 = "ls /dev/char/*" - const command10 = "ls /dev/cpu/*" - const command11 = "ls /dev/disk/*" - const command12 = "ls /dev/dma_heap/*" - const command13 = "ls /dev/dri/*" - const command14 = "ls /dev/fd/*" - const command15 = "ls /dev/hugepages/*" - const command16 = "ls /dev/input/*" - const command17 = "ls /dev/mapper/*" - const command18 = "ls /dev/mqueue/*" - const command19 = "ls /dev/net/*" - const command20 = "ls /dev/pts/*" - const command21 = "ls /dev/shm/*" - const command22 = "ls /dev/snd/*" - const command23 = "ls /dev/v4l/*" - const command24 = "ls /dev/vfio/*" - const devices_commands = [command7, command8, command9, command10, command11, command12, command13, command14, command15, - command16, command17, command18, command19, command20, command21, command22, command23, command24 - ]; + // Command for listing all Connected Devices + const devices_command = "lsusb" cockpit.spawn(["bash", "-c", command1]) .then((data) => { @@ -108,19 +88,21 @@ function initPage() { }) .catch((error) => console.log(error)); - count = 0; - for (let i = 0; i < devices_commands.length; i++) { - cockpit.spawn(["bash", "-c", devices_commands[i]]) - .then((data) => { - if (data.length != 0) { - devices.innerHTML += data.replaceAll("\n", "
    "); - devices.innerHTML += "
    "; - count++ + cockpit.spawn(["bash", "-c", devices_command]) + .then((data) => { + const datalist = data.split("\n"); + if (data.length == 0) { + devices.innerHTML = "No devices detected"; + } + for (let i = 0; i < datalist.length - 1; i++) { + const name = datalist[i].split(" "); + for (let j = 6; j < name.length; j++) { + devices.innerHTML += name[j] + " "; } - }) - .catch((error) => console.log(error)); - } - if (count > 0) { - devices.innerHTML -= "
    " - } + devices.innerHTML += "
    "; + devices.innerHTML += "/dev/bus/usb/" + name[1] + "/" + name[3]; + devices.innerHTML += "

    "; + } + }) + .catch((error) => console.log(error)); } \ No newline at end of file -- 2.40.1 From f3dc7acc2fde87d3dd75bf879bbc5d50ae483737 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Sat, 30 Nov 2024 22:26:00 -0500 Subject: [PATCH 21/23] Removed weird colons and extra space from health table --- ui/general/health.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/general/health.js b/ui/general/health.js index ec04394..dc7629b 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -100,8 +100,10 @@ function initPage() { devices.innerHTML += name[j] + " "; } devices.innerHTML += "
    "; - devices.innerHTML += "/dev/bus/usb/" + name[1] + "/" + name[3]; - devices.innerHTML += "

    "; + devices.innerHTML += "/dev/bus/usb/" + name[1] + "/" + name[3].replace(":", ""); + if (i != datalist.length - 2) { + devices.innerHTML += "

    "; + } } }) .catch((error) => console.log(error)); -- 2.40.1 From 51715550c40669739171a0693989a27da6523aa3 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Fri, 6 Dec 2024 22:35:43 -0500 Subject: [PATCH 22/23] Added comments and updated variable names --- ui/general/health.html | 20 ++--- ui/general/health.js | 178 +++++++++++++++++++++-------------------- 2 files changed, 103 insertions(+), 95 deletions(-) diff --git a/ui/general/health.html b/ui/general/health.html index 690520a..0b1403c 100644 --- a/ui/general/health.html +++ b/ui/general/health.html @@ -22,41 +22,41 @@ Drone - + IP Address - + Docker Container - + Connection Upstream - + Network SSID - + Camera Devices - + Connected Devices - + Zerotier IP - N/A + N/A Hotspot Connections - N/A + N/A GCS @@ -64,7 +64,7 @@ FCU Firmware - N/A + N/A diff --git a/ui/general/health.js b/ui/general/health.js index dc7629b..95cfc8f 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -1,11 +1,11 @@ // Elements -const droneName = document.getElementById("name"); -const address = document.getElementById("address"); -const container = document.getElementById("container"); -const upstream = document.getElementById("upstream"); -const ssid = document.getElementById("ssid"); -const camera = document.getElementById("camera"); -const devices = document.getElementById("devices"); +const droneName = document.getElementById("droneName"); +const ipAddress = document.getElementById("ipAddress"); +const dockerContainer = document.getElementById("dockerContainer"); +const connectionUpstream = document.getElementById("connectionUpstream"); +const networkSSID = document.getElementById("networkSSID"); +const cameraDevices = document.getElementById("cameraDevices"); +const connectedDevices = document.getElementById("connectedDevices"); // Load page + drone settings document.onload = initPage(); @@ -15,96 +15,104 @@ function initPage() { // Populate table with drone name, drone IP address, and drone docker containers that are running // Name corresponds to host computer's name, IP address is host computer's address // and docker containers are all those displayed by docker container ls - const command1 = "hostname" - const command2 = "hostname -I" - const command3 = "docker container ls" - const command4 = "ping google.com -c 1" - const command5 = "iwgetid -r" - const command6 = "ls /dev/video*" + const droneNameCommand = "hostname" + const ipAddressCommand = "hostname -I" + const dockerContainerCommand = "docker container ls" + const connectionUpstreamCommand = "ping google.com -c 1" + const networkSSIDCommand = "iwgetid -r" + const cameraDevicesCommand = "ls /dev/video*" // Command for listing all Connected Devices - const devices_command = "lsusb" + const connectedDevicesCommand = "lsusb" - cockpit.spawn(["bash", "-c", command1]) + // Extract the Drone Name from console output + cockpit.spawn(["bash", "-c", droneNameCommand]) .then((data) => { droneName.innerHTML = data.split(" ")[0]; }) .catch((error) => console.log(error)); - cockpit.spawn(["bash", "-c", command2]) - .then((data) => { - address.innerHTML = data.split(" ")[0]; - }) - .catch((error) => console.log(error)); + // Extract the IP Address from console output + cockpit.spawn(["bash", "-c", ipAddressCommand]) + .then((data) => { + ipAddress.innerHTML = data.split(" ")[0]; + }) + .catch((error) => console.log(error)); - cockpit.spawn(["bash", "-c", command3]) - .then((data) => { - const datalist = data.split("\n"); - if (datalist[1].split(" ")[0] == ""){ - container.className = "p-3 mb-2 bg-danger text-white"; - container.innerHTML += "Error: No Docker Containers to Display"; - } else { - for (let i = 0; i < datalist.length - 2; i++) { - container.innerHTML += datalist[i + 1].split(" ")[0]; - container.innerHTML += "
    "; + // Extract the Docker Container IDs from console output + cockpit.spawn(["bash", "-c", dockerContainerCommand]) + .then((data) => { + const datalist = data.split("\n"); + // If no Docker Containers up + if (datalist[1].split(" ")[0] == ""){ + dockerContainer.className = "p-3 mb-2 bg-danger text-white"; + dockerContainer.innerHTML += "Error: No Docker Containers to Display"; + } else { + // List each container on a new line + for (let i = 0; i < datalist.length - 2; i++) { + dockerContainer.innerHTML += datalist[i + 1].split(" ")[0]; + dockerContainer.innerHTML += "
    "; + } + dockerContainer.innerHTML += datalist[datalist.length - 1].split(" ")[0]; } - container.innerHTML += datalist[datalist.length - 1].split(" ")[0]; - } - }) - .catch((error) => console.log(error)); + }) + .catch((error) => console.log(error)); - cockpit.spawn(["bash", "-c", command4]) - .then((data) => { - const datalist = data.split(" "); - if (datalist[0] == "ping:"){ - upstream.innerHTML = "Connection LIMITED - No upstream"; - } else if (datalist[0] == "PING") { - upstream.innerHTML = "Connection OK"; - } else { - upstream.innerHTML = "Connection DOWN"; - } - }) - .catch((error) => console.log(error)); + // Extract the Connection Upstream Status from console output + cockpit.spawn(["bash", "-c", connectionUpstreamCommand]) + .then((data) => { + const datalist = data.split(" "); + // If error no upstream returned + if (datalist[0] == "ping:") {connectionUpstream.innerHTML = "Connection LIMITED - No upstream";} + // If ping succeeded + else if (datalist[0] == "PING") {connectionUpstream.innerHTML = "Connection OK";} + // If some other output returned + else {connectionUpstream.innerHTML = "Connection DOWN";} + }) + .catch((error) => console.log(error)); - cockpit.spawn(["bash", "-c", command5]) - .then((data) => { - if (data.length == 0) { - ssid.innerHTML = "None"; - } else { - ssid.innerHTML = data - } - }) - .catch((error) => console.log(error)); - - cockpit.spawn(["bash", "-c", command6]) - .then((data) => { - if (data.length == 0) { - camera.innerHTML = "No Camera Devices Detected"; - } - else { - const datalist = data.replaceAll("\n", "
    "); - camera.innerHTML += datalist; - } - }) - .catch((error) => console.log(error)); - - cockpit.spawn(["bash", "-c", devices_command]) - .then((data) => { - const datalist = data.split("\n"); - if (data.length == 0) { - devices.innerHTML = "No devices detected"; - } - for (let i = 0; i < datalist.length - 1; i++) { - const name = datalist[i].split(" "); - for (let j = 6; j < name.length; j++) { - devices.innerHTML += name[j] + " "; + // Extract the Network SSID from console output + cockpit.spawn(["bash", "-c", networkSSIDCommand]) + .then((data) => { + if (data.length == 0) { + networkSSID.innerHTML = "None"; + } else { + networkSSID.innerHTML = data } - devices.innerHTML += "
    "; - devices.innerHTML += "/dev/bus/usb/" + name[1] + "/" + name[3].replace(":", ""); - if (i != datalist.length - 2) { - devices.innerHTML += "

    "; + }) + .catch((error) => console.log(error)); + + // Extract the Camera Devices from console output + cockpit.spawn(["bash", "-c", cameraDevicesCommand]) + .then((data) => { + // If no devices detected + if (data.length == 0) {cameraDevices.innerHTML = "No Camera Devices Detected";} + // Otherwise print the list of Camera Devices + else { + const datalist = data.replaceAll("\n", "
    "); + cameraDevices.innerHTML += datalist; } - } - }) - .catch((error) => console.log(error)); + }) + .catch((error) => console.log(error)); + + // Extract the Connected Devices List from console output + cockpit.spawn(["bash", "-c", connectedDevicesCommand]) + .then((data) => { + const datalist = data.split("\n"); + // If no devices listed + if (data.length == 0) {connectedDevices.innerHTML = "No devices detected";} + // Otherwise, list each device by name and path + for (let i = 0; i < datalist.length - 1; i++) { + const name = datalist[i].split(" "); + for (let j = 6; j < name.length; j++) { + connectedDevices.innerHTML += name[j] + " "; + } + connectedDevices.innerHTML += "
    "; + connectedDevices.innerHTML += "/dev/bus/usb/" + name[1] + "/" + name[3].replace(":", ""); + if (i != datalist.length - 2) { + connectedDevices.innerHTML += "

    "; + } + } + }) + .catch((error) => console.log(error)); } \ No newline at end of file -- 2.40.1 From 1f6a41de4484600fe4ed5b3863ee4affcd7baa19 Mon Sep 17 00:00:00 2001 From: Alice Sedgwick Date: Fri, 6 Dec 2024 22:41:35 -0500 Subject: [PATCH 23/23] Added more comments --- ui/general/health.js | 50 +++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/ui/general/health.js b/ui/general/health.js index 95cfc8f..2bcea8f 100644 --- a/ui/general/health.js +++ b/ui/general/health.js @@ -1,4 +1,4 @@ -// Elements +// Initialize Drone Table Elements const droneName = document.getElementById("droneName"); const ipAddress = document.getElementById("ipAddress"); const dockerContainer = document.getElementById("dockerContainer"); @@ -7,39 +7,51 @@ const networkSSID = document.getElementById("networkSSID"); const cameraDevices = document.getElementById("cameraDevices"); const connectedDevices = document.getElementById("connectedDevices"); -// Load page + drone settings +// Load page document.onload = initPage(); // Function to initialize the page function initPage() { - // Populate table with drone name, drone IP address, and drone docker containers that are running - // Name corresponds to host computer's name, IP address is host computer's address - // and docker containers are all those displayed by docker container ls - const droneNameCommand = "hostname" - const ipAddressCommand = "hostname -I" - const dockerContainerCommand = "docker container ls" - const connectionUpstreamCommand = "ping google.com -c 1" - const networkSSIDCommand = "iwgetid -r" - const cameraDevicesCommand = "ls /dev/video*" + // Populate health table with: + // Drone Name + // Drone IP address + // Drone Docker Containers that are running + // Connection Upstream Status + // Network SSID + // Camera Devices List + // Connected Devices List - // Command for listing all Connected Devices + // Below are the list of Commands used to acquire the information to populate the health table + // Name corresponds to host computer's name + const droneNameCommand = "hostname" + // Host Computer's IP + const ipAddressCommand = "hostname -I" + // List of all Docker Container IDs + const dockerContainerCommand = "docker container ls" + // Ping Google to check upstream connection + const connectionUpstreamCommand = "ping google.com -c 1" + // SSID of the network the Drone is connected to + const networkSSIDCommand = "iwgetid -r" + // Camera devices are those listed by /dev/video* + const cameraDevicesCommand = "ls /dev/video*" + // Connected Devices are those listed under /dev/bus/usb const connectedDevicesCommand = "lsusb" - // Extract the Drone Name from console output + // Extract the Drone Name from console output and insert it into the table cockpit.spawn(["bash", "-c", droneNameCommand]) .then((data) => { droneName.innerHTML = data.split(" ")[0]; }) .catch((error) => console.log(error)); - // Extract the IP Address from console output + // Extract the IP Address from console output and insert it into the table cockpit.spawn(["bash", "-c", ipAddressCommand]) .then((data) => { ipAddress.innerHTML = data.split(" ")[0]; }) .catch((error) => console.log(error)); - // Extract the Docker Container IDs from console output + // Extract the Docker Container IDs from console output and insert it into the table cockpit.spawn(["bash", "-c", dockerContainerCommand]) .then((data) => { const datalist = data.split("\n"); @@ -58,7 +70,7 @@ function initPage() { }) .catch((error) => console.log(error)); - // Extract the Connection Upstream Status from console output + // Extract the Connection Upstream Status from console output and insert it into the table cockpit.spawn(["bash", "-c", connectionUpstreamCommand]) .then((data) => { const datalist = data.split(" "); @@ -71,7 +83,7 @@ function initPage() { }) .catch((error) => console.log(error)); - // Extract the Network SSID from console output + // Extract the Network SSID from console output and insert it into the table cockpit.spawn(["bash", "-c", networkSSIDCommand]) .then((data) => { if (data.length == 0) { @@ -82,7 +94,7 @@ function initPage() { }) .catch((error) => console.log(error)); - // Extract the Camera Devices from console output + // Extract the Camera Devices from console output and insert it into the table cockpit.spawn(["bash", "-c", cameraDevicesCommand]) .then((data) => { // If no devices detected @@ -95,7 +107,7 @@ function initPage() { }) .catch((error) => console.log(error)); - // Extract the Connected Devices List from console output + // Extract the Connected Devices List from console output and insert it into the table cockpit.spawn(["bash", "-c", connectedDevicesCommand]) .then((data) => { const datalist = data.split("\n"); -- 2.40.1