-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Update .gitignore and package-lock.json, add system monitor co…
…mponent, and update settings functionality
- Loading branch information
1 parent
5e6daab
commit f4e3974
Showing
10 changed files
with
235 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.vscode/ | ||
.env | ||
dev | ||
node_modules | ||
node_modules | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"TARGET_BT_ADDRESSES": [ | ||
{ | ||
"address": "XX:XX:XX:XX:XX:XX", | ||
"name": "Device 1" | ||
}, | ||
{ | ||
"address": "XX:XX:XX:XX:XX:XX", | ||
"name": "Device 2" | ||
} | ||
], | ||
"TARGET_AP_MAC_ADDRESSES": [ | ||
{ | ||
"address": "XX:XX:XX:XX:XX:XX", | ||
"name": "Device 1" | ||
}, | ||
{ | ||
"address": "XX:XX:XX:XX:XX:XX", | ||
"name": "Device 2" | ||
} | ||
], | ||
"VideoSaveLocation": "./recordings" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import json | ||
import os | ||
|
||
SETTINGS_FILE = './settings/settings.json' | ||
|
||
def get_settings(): | ||
with open(SETTINGS_FILE, 'r') as f: | ||
settings = json.load(f) | ||
return settings | ||
|
||
def update_settings(new_settings): | ||
with open(SETTINGS_FILE, 'r+') as f: | ||
settings = json.load(f) | ||
settings.update(new_settings) | ||
f.seek(0) | ||
json.dump(settings, f, indent=4) | ||
f.truncate() | ||
|
||
def is_valid_directory(path): | ||
if not os.path.exists(path): | ||
try: | ||
os.makedirs(path) | ||
return True | ||
except Exception as e: | ||
print(f"Error creating directory: {e}") | ||
return False | ||
elif os.path.isdir(path) and os.access(path, os.W_OK): | ||
return True | ||
else: | ||
return False | ||
|
||
def update_video_save_location(new_location): | ||
if is_valid_directory(new_location): | ||
update_settings({"VideoSaveLocation": new_location}) | ||
return True | ||
else: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,60 @@ | ||
import psutil | ||
|
||
|
||
def get_cpu_temp() -> float | None: | ||
def get_cpu_temp() -> int | None: | ||
""" | ||
Returns the CPU temperature of the Raspberry Pi. | ||
Returns: | ||
float: The CPU temperature in Celsius. | ||
int: The CPU temperature in Celsius rounded to the nearest integer. | ||
None: If the temperature file is not found. | ||
""" | ||
|
||
try: | ||
with open("/sys/class/thermal/thermal_zone0/temp", "r") as file: | ||
temp_str = file.read().strip() | ||
cpu_temp = int(temp_str) / 1000.0 | ||
return cpu_temp | ||
return round(cpu_temp) | ||
except FileNotFoundError: | ||
return None | ||
|
||
|
||
def get_cpu_load() -> float: | ||
def get_cpu_load() -> int: | ||
""" | ||
Returns the CPU load as a percentage. | ||
Returns the CPU load as a percentage, considering the maximum load across all cores. | ||
Returns: | ||
float: The CPU load as a percentage. | ||
int: The CPU load as a percentage rounded to the nearest integer. | ||
""" | ||
return psutil.cpu_percent(interval=1) | ||
|
||
per_core_loads = psutil.cpu_percent(interval=1, percpu=True) | ||
max_load = max(per_core_loads) | ||
return round(max_load) | ||
|
||
|
||
def get_storage_info() -> dict[str, float]: | ||
def get_storage_info() -> dict[str, int]: | ||
""" | ||
Returns the total size and used space of the disk where the root directory is mounted. | ||
Returns: | ||
dict[str, float]: A dictionary containing the total and used space in GB. | ||
dict[str, int]: A dictionary containing the total and used space in GB, each rounded to the nearest integer. | ||
""" | ||
|
||
usage = psutil.disk_usage('/') | ||
total = usage.total / (1024 ** 3) # Convert bytes to GB | ||
used = usage.used / (1024 ** 3) # Convert bytes to GB | ||
return {'total_gb': total, 'used_gb': used} | ||
return {'total_gb': round(total), 'used_gb': round(used)} | ||
|
||
|
||
def get_ram_usage() -> dict[str, float]: | ||
def get_ram_usage() -> dict[str, int]: | ||
""" | ||
Returns the total and used RAM in MB. | ||
Returns: | ||
dict[str, float]: A dictionary containing the total and used RAM in MB. | ||
dict[str, int]: A dictionary containing the total and used RAM in MB, each rounded to the nearest integer. | ||
""" | ||
|
||
mem = psutil.virtual_memory() | ||
total = mem.total / (1024 ** 2) # Convert bytes to MB | ||
used = mem.used / (1024 ** 2) # Convert bytes to MB | ||
return {'total_mb': total, 'used_mb': used} | ||
return {'total_mb': round(total), 'used_mb': round(used)} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,76 @@ | ||
const page = () => { | ||
'use client'; | ||
import React, { useState, useEffect } from "react"; | ||
|
||
const Page = () => { | ||
const [settings, setSettings] = useState({ | ||
VideoSaveLocation: "Loading...", | ||
}); | ||
const [newLocation, setNewLocation] = useState(""); | ||
|
||
useEffect(() => { | ||
const settingsFeedUrl = `${window.location.protocol}//${window.location.hostname}:5005/settings`; | ||
|
||
const fetchSettingsInfo = async () => { | ||
try { | ||
const response = await fetch(settingsFeedUrl); | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
const data = await response.json(); | ||
console.log("Fetched Settings Info:", data); | ||
setSettings(data); | ||
} catch (error) { | ||
console.error("Error fetching settings info:", error); | ||
setSettings({ | ||
VideoSaveLocation: "Error loading data", | ||
}); | ||
} | ||
}; | ||
|
||
fetchSettingsInfo(); | ||
}, []); | ||
|
||
const handleSaveLocationChange = async () => { | ||
const settingsFeedUrl = `${window.location.protocol}//${window.location.hostname}:5005/settings`; | ||
try { | ||
const response = await fetch(settingsFeedUrl, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ VideoSaveLocation: newLocation }), | ||
}); | ||
|
||
const result = await response.json(); | ||
if (!response.ok) { | ||
alert(result.message || "Error updating settings"); | ||
} else { | ||
alert("Settings updated successfully"); | ||
setSettings(prevSettings => ({ ...prevSettings, VideoSaveLocation: newLocation })); | ||
} | ||
} catch (error) { | ||
console.error("Error updating settings:", error); | ||
alert("Error updating settings"); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div>bt device mac</div> | ||
<div>wifi device mac</div> | ||
<div>modular trigger sensors</div> | ||
<div>video save location</div> | ||
<div>{`Video save location: ${settings.VideoSaveLocation}`}</div> | ||
<div> | ||
<input | ||
type="text" | ||
value={newLocation} | ||
onChange={(e) => setNewLocation(e.target.value)} | ||
placeholder="Enter new video save location" | ||
/> | ||
<button onClick={handleSaveLocationChange}>Update Location</button> | ||
</div> | ||
<div className="text-gray-300">modular trigger sensors: TBD</div> | ||
</div> | ||
) | ||
} | ||
); | ||
}; | ||
|
||
export default page | ||
export default Page; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use client'; | ||
import React, { useState, useEffect } from "react"; | ||
|
||
const SystemMonitor = () => { | ||
const [systemInfo, setSystemInfo] = useState({ | ||
cpu_temp_celsius: "Loading...", | ||
cpu_load_percent: "Loading...", | ||
storage_info_gb: { total_gb: "Loading...", used_gb: "Loading..." }, | ||
ram_usage_mb: { total_mb: "Loading...", used_mb: "Loading..." }, | ||
}); | ||
|
||
const systemFeedUrl = `${window.location.protocol}//${window.location.hostname}:5005/system_info`; | ||
|
||
useEffect(() => { | ||
const fetchSystemInfo = async () => { | ||
try { | ||
const response = await fetch(systemFeedUrl); | ||
const data = await response.json(); | ||
console.log("Fetched System Info:", data); // Log the data structure | ||
setSystemInfo(data); | ||
} catch (error) { | ||
console.error("Error fetching system info:", error); | ||
} | ||
}; | ||
|
||
fetchSystemInfo(); | ||
}, [systemFeedUrl]); | ||
|
||
return ( | ||
<div className="grid grid-cols-3 border border-red-200 gap-10"> | ||
<div className="border border-red-500 text-center">Temp: {systemInfo.cpu_temp_celsius}°C</div> | ||
<div className="border border-red-500 text-center">CPU: {systemInfo.cpu_load_percent}%</div> | ||
<div className="border border-red-500 text-center"> | ||
Storage: {systemInfo.storage_info_gb.used_gb} GB / {systemInfo.storage_info_gb.total_gb} GB | ||
</div> | ||
<div className="border border-red-500 text-center"> | ||
RAM: {systemInfo.ram_usage_mb.used_mb} MB / {systemInfo.ram_usage_mb.total_mb} MB | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SystemMonitor; |