diff --git a/interface/src/lib/stores/analytics.ts b/interface/src/lib/stores/analytics.ts index 68d9a424..3720083b 100644 --- a/interface/src/lib/stores/analytics.ts +++ b/interface/src/lib/stores/analytics.ts @@ -1,3 +1,4 @@ +import { type Analytics } from '$lib/types/models'; import { writable } from 'svelte/store'; let analytics_data = { @@ -11,26 +12,33 @@ let analytics_data = { core_temp: [] }; +const maxAnalyticsData = 100; + function createAnalytics() { - const { subscribe, set, update } = writable(analytics_data); + const { subscribe, update } = writable(analytics_data); return { subscribe, - addData: (data: string) => { - const content = JSON.parse(data); + addData: (content: Analytics) => { update((analytics_data) => ({ ...analytics_data, - uptime: [...analytics_data.uptime, content.uptime], - free_heap: [...analytics_data.free_heap, content.free_heap / 1000], - total_heap: [...analytics_data.total_heap, content.total_heap / 1000], - min_free_heap: [...analytics_data.min_free_heap, content.min_free_heap / 1000], - max_alloc_heap: [...analytics_data.max_alloc_heap, content.max_alloc_heap / 1000], - fs_used: [...analytics_data.fs_used, content.fs_used / 1000], - fs_total: [...analytics_data.fs_total, content.fs_total / 1000], - core_temp: [...analytics_data.core_temp, content.core_temp] + uptime: [...analytics_data.uptime, content.uptime].slice(-maxAnalyticsData), + free_heap: [...analytics_data.free_heap, content.free_heap / 1000].slice(-maxAnalyticsData), + total_heap: [...analytics_data.total_heap, content.total_heap / 1000].slice( + -maxAnalyticsData + ), + min_free_heap: [...analytics_data.min_free_heap, content.min_free_heap / 1000].slice( + -maxAnalyticsData + ), + max_alloc_heap: [...analytics_data.max_alloc_heap, content.max_alloc_heap / 1000].slice( + -maxAnalyticsData + ), + fs_used: [...analytics_data.fs_used, content.fs_used / 1000].slice(-maxAnalyticsData), + fs_total: [...analytics_data.fs_total, content.fs_total / 1000].slice(-maxAnalyticsData), + core_temp: [...analytics_data.core_temp, content.core_temp].slice(-maxAnalyticsData) })); } }; } -export const analytics = createAnalytics(); +export const analytics = createAnalytics(); \ No newline at end of file diff --git a/interface/src/lib/types/models.ts b/interface/src/lib/types/models.ts new file mode 100644 index 00000000..e4035996 --- /dev/null +++ b/interface/src/lib/types/models.ts @@ -0,0 +1,113 @@ +export type WifiStatus = { + status: number; + local_ip: string; + mac_address: string; + rssi: number; + ssid: string; + bssid: string; + channel: number; + subnet_mask: string; + gateway_ip: string; + dns_ip_1: string; + dns_ip_2?: string; +}; + +export type WifiSettings = { + hostname: string; + priority_RSSI: boolean; + wifi_networks: networkItem[]; +}; + +export type KnownNetworkItem = { + ssid: string; + password: string; + static_ip_config: boolean; + local_ip?: string; + subnet_mask?: string; + gateway_ip?: string; + dns_ip_1?: string; + dns_ip_2?: string; +}; + +export type NetworkItem = { + rssi: number; + ssid: string; + bssid: string; + channel: number; + encryption_type: number; +}; + +export type ApStatus = { + status: number; + ip_address: string; + mac_address: string; + station_num: number; +}; + +export type ApSettings = { + provision_mode: number; + ssid: string; + password: string; + channel: number; + ssid_hidden: boolean; + max_clients: number; + local_ip: string; + gateway_ip: string; + subnet_mask: string; +}; + +export type LightState = { + led_on: boolean; +}; + +export type BrokerSettings = { + mqtt_path: string; + name: string; + unique_id: string; +}; + +export type NTPStatus = { + status: number; + utc_time: string; + local_time: string; + server: string; + uptime: number; +}; + +export type NTPSettings = { + enabled: boolean; + server: string; + tz_label: string; + tz_format: string; +}; + +export type Analytics = { + max_alloc_heap: number; + psram_size: number; + free_psram: number; + free_heap: number; + total_heap: number; + min_free_heap: number; + core_temp: number; + fs_total: number; + fs_used: number; + uptime: number; +}; + +export type StaticSystemInformation = { + esp_platform: string; + firmware_version: string; + cpu_freq_mhz: number; + cpu_type: string; + cpu_rev: number; + cpu_cores: number; + sketch_size: number; + free_sketch_space: number; + sdk_version: string; + arduino_version: string; + flash_chip_size: number; + flash_chip_speed: number; + cpu_reset_reason: string; +}; + +export type SystemInformation = Analytics & StaticSystemInformation; diff --git a/interface/src/routes/+layout.svelte b/interface/src/routes/+layout.svelte index 0c3db3eb..bf5778c8 100644 --- a/interface/src/routes/+layout.svelte +++ b/interface/src/routes/+layout.svelte @@ -14,6 +14,7 @@ import Menu from './menu.svelte'; import Statusbar from './statusbar.svelte'; import Login from './login.svelte'; + import type { Analytics } from '$lib/types/models'; export let data: LayoutData; @@ -90,7 +91,8 @@ telemetry.setDownloadOTA(event.data); }); eventSource.addEventListener('analytics', (event) => { - analytics.addData(event.data); + const data = JSON.parse(event.data) as Analytics; + analytics.addData(data); }); } diff --git a/interface/src/routes/connections/mqtt/MQTTConfig.svelte b/interface/src/routes/connections/mqtt/MQTTConfig.svelte index aa8660e3..82fa472d 100644 --- a/interface/src/routes/connections/mqtt/MQTTConfig.svelte +++ b/interface/src/routes/connections/mqtt/MQTTConfig.svelte @@ -8,12 +8,7 @@ import Spinner from '$lib/components/Spinner.svelte'; import MQTT from '~icons/tabler/topology-star-3'; import Info from '~icons/tabler/info-circle'; - - type BrokerSettings = { - mqtt_path: string; - name: string; - unique_id: string; - }; + import type { BrokerSettings } from '$lib/types/models'; let brokerSettings: BrokerSettings; diff --git a/interface/src/routes/connections/ntp/NTP.svelte b/interface/src/routes/connections/ntp/NTP.svelte index a87b68b5..28314e9b 100644 --- a/interface/src/routes/connections/ntp/NTP.svelte +++ b/interface/src/routes/connections/ntp/NTP.svelte @@ -8,28 +8,13 @@ import { user } from '$lib/stores/user'; import { page } from '$app/stores'; import { notifications } from '$lib/components/toasts/notifications'; - import type { TimeZones } from './timezones'; import { TIME_ZONES } from './timezones'; import NTP from '~icons/tabler/clock-check'; import Server from '~icons/tabler/server'; import Clock from '~icons/tabler/clock'; import UTC from '~icons/tabler/clock-pin'; import Stopwatch from '~icons/tabler/24-hours'; - - type NTPStatus = { - status: number; - utc_time: string; - local_time: string; - server: string; - uptime: number; - }; - - type NTPSettings = { - enabled: boolean; - server: string; - tz_label: string; - tz_format: string; - }; + import type { NTPSettings, NTPStatus } from '$lib/types/models'; let ntpSettings: NTPSettings; let ntpStatus: NTPStatus; diff --git a/interface/src/routes/demo/Demo.svelte b/interface/src/routes/demo/Demo.svelte index b45b458c..e1ba44db 100644 --- a/interface/src/routes/demo/Demo.svelte +++ b/interface/src/routes/demo/Demo.svelte @@ -8,10 +8,7 @@ import Info from '~icons/tabler/info-circle'; import Save from '~icons/tabler/device-floppy'; import Reload from '~icons/tabler/reload'; - - type LightState = { - led_on: boolean; - }; + import type { LightState } from '$lib/types/models'; let lightState: LightState = { led_on: false }; diff --git a/interface/src/routes/system/status/SystemStatus.svelte b/interface/src/routes/system/status/SystemStatus.svelte index 4a40cc16..39ea5315 100644 --- a/interface/src/routes/system/status/SystemStatus.svelte +++ b/interface/src/routes/system/status/SystemStatus.svelte @@ -24,33 +24,9 @@ import Health from '~icons/tabler/stethoscope'; import Stopwatch from '~icons/tabler/24-hours'; import SDK from '~icons/tabler/sdk'; + import type { SystemInformation } from '$lib/types/models'; - type SystemStatus = { - esp_platform: string; - firmware_version: string; - max_alloc_heap: number; - psram_size: number; - free_psram: number; - cpu_freq_mhz: number; - cpu_type: string; - cpu_rev: number; - cpu_cores: number; - free_heap: number; - min_free_heap: number; - sketch_size: number; - free_sketch_space: number; - sdk_version: string; - arduino_version: string; - flash_chip_size: number; - flash_chip_speed: number; - fs_total: number; - fs_used: number; - core_temp: number; - cpu_reset_reason: string; - uptime: number; - }; - - let systemStatus: SystemStatus; + let systemInformation: SystemInformation; async function getSystemStatus() { try { @@ -61,11 +37,11 @@ 'Content-Type': 'application/json' } }); - systemStatus = await response.json(); + systemInformation = await response.json(); } catch (error) { console.log('Error:', error); } - return systemStatus; + return systemInformation; } const interval = setInterval(async () => { @@ -195,7 +171,7 @@
Chip
- {systemStatus.cpu_type} Rev {systemStatus.cpu_rev} + {systemInformation.cpu_type} Rev {systemInformation.cpu_rev}
@@ -207,7 +183,7 @@
SDK Version
- ESP-IDF {systemStatus.sdk_version} / Arduino {systemStatus.arduino_version} + ESP-IDF {systemInformation.sdk_version} / Arduino {systemInformation.arduino_version}
@@ -219,7 +195,7 @@
Firmware Version
- {systemStatus.firmware_version} + {systemInformation.firmware_version}
@@ -231,7 +207,7 @@
CPU Frequency
- {systemStatus.cpu_freq_mhz} MHz {systemStatus.cpu_cores == 2 + {systemInformation.cpu_freq_mhz} MHz {systemInformation.cpu_cores == 2 ? 'Dual Core' : 'Single Core'}
@@ -245,7 +221,7 @@
Heap (Free / Max Alloc)
- {systemStatus.free_heap.toLocaleString('en-US')} / {systemStatus.max_alloc_heap.toLocaleString( + {systemInformation.free_heap.toLocaleString('en-US')} / {systemInformation.max_alloc_heap.toLocaleString( 'en-US' )} bytes
@@ -259,7 +235,7 @@
PSRAM (Size / Free)
- {systemStatus.psram_size.toLocaleString('en-US')} / {systemStatus.psram_size.toLocaleString( + {systemInformation.psram_size.toLocaleString('en-US')} / {systemInformation.psram_size.toLocaleString( 'en-US' )} bytes
@@ -274,13 +250,13 @@
Sketch (Used / Free)
- {((systemStatus.sketch_size / systemStatus.free_sketch_space) * 100).toFixed(1)} % of - {(systemStatus.free_sketch_space / 1000000).toLocaleString('en-US')} MB used + {((systemInformation.sketch_size / systemInformation.free_sketch_space) * 100).toFixed(1)} % of + {(systemInformation.free_sketch_space / 1000000).toLocaleString('en-US')} MB used ({( - (systemStatus.free_sketch_space - systemStatus.sketch_size) / + (systemInformation.free_sketch_space - systemInformation.sketch_size) / 1000000 ).toLocaleString('en-US')} MB free) @@ -295,8 +271,8 @@
Flash Chip (Size / Speed)
- {(systemStatus.flash_chip_size / 1000000).toLocaleString('en-US')} MB / {( - systemStatus.flash_chip_speed / 1000000 + {(systemInformation.flash_chip_size / 1000000).toLocaleString('en-US')} MB / {( + systemInformation.flash_chip_speed / 1000000 ).toLocaleString('en-US')} MHz
@@ -310,13 +286,13 @@
File System (Used / Total)
{((systemStatus.fs_used / systemStatus.fs_total) * 100).toFixed(1)} % of {( - systemStatus.fs_total / 1000000 + >{((systemInformation.fs_used / systemInformation.fs_total) * 100).toFixed(1)} % of {( + systemInformation.fs_total / 1000000 ).toLocaleString('en-US')} MB used ({((systemStatus.fs_total - systemStatus.fs_used) / 1000000).toLocaleString( + >({((systemInformation.fs_total - systemInformation.fs_used) / 1000000).toLocaleString( 'en-US' )} MB free)
Core Temperature
- {systemStatus.core_temp == 53.33 ? 'NaN' : systemStatus.core_temp.toFixed(2) + ' °C'} + {systemInformation.core_temp == 53.33 ? 'NaN' : systemInformation.core_temp.toFixed(2) + ' °C'}
@@ -344,7 +320,7 @@
Uptime
- {convertSeconds(systemStatus.uptime)} + {convertSeconds(systemInformation.uptime)}
@@ -356,7 +332,7 @@
Reset Reason
- {systemStatus.cpu_reset_reason} + {systemInformation.cpu_reset_reason}
diff --git a/interface/src/routes/wifi/ap/Accesspoint.svelte b/interface/src/routes/wifi/ap/Accesspoint.svelte index a4b617ac..6b110897 100644 --- a/interface/src/routes/wifi/ap/Accesspoint.svelte +++ b/interface/src/routes/wifi/ap/Accesspoint.svelte @@ -13,25 +13,7 @@ import MAC from '~icons/tabler/dna-2'; import Home from '~icons/tabler/home'; import Devices from '~icons/tabler/devices'; - - type ApStatus = { - status: number; - ip_address: string; - mac_address: string; - station_num: number; - }; - - type ApSettings = { - provision_mode: number; - ssid: string; - password: string; - channel: number; - ssid_hidden: boolean; - max_clients: number; - local_ip: string; - gateway_ip: string; - subnet_mask: string; - }; + import type { ApSettings, ApStatus } from '$lib/types/models'; let apSettings: ApSettings; let apStatus: ApStatus; diff --git a/interface/src/routes/wifi/sta/Scan.svelte b/interface/src/routes/wifi/sta/Scan.svelte index 61a38ce7..469113ff 100644 --- a/interface/src/routes/wifi/sta/Scan.svelte +++ b/interface/src/routes/wifi/sta/Scan.svelte @@ -10,6 +10,7 @@ import Reload from '~icons/tabler/reload'; import { onMount, onDestroy } from 'svelte'; import RssiIndicator from '$lib/components/RSSIIndicator.svelte'; + import type { NetworkItem } from '$lib/types/models'; // provided by export let isOpen: boolean; @@ -27,15 +28,7 @@ 'WAPI PSK' ]; - type networkItem = { - rssi: number; - ssid: string; - bssid: string; - channel: number; - encryption_type: number; - }; - - let listOfNetworks: networkItem[] = []; + let listOfNetworks: NetworkItem[] = []; let scanActive = false; diff --git a/interface/src/routes/wifi/sta/Wifi.svelte b/interface/src/routes/wifi/sta/Wifi.svelte index fb27c89c..a5542b07 100644 --- a/interface/src/routes/wifi/sta/Wifi.svelte +++ b/interface/src/routes/wifi/sta/Wifi.svelte @@ -32,39 +32,9 @@ import Cancel from '~icons/tabler/x'; import Check from '~icons/tabler/check'; import InfoDialog from '$lib/components/InfoDialog.svelte'; + import type { KnownNetworkItem, WifiSettings, WifiStatus } from '$lib/types/models'; - type WifiStatus = { - status: number; - local_ip: string; - mac_address: string; - rssi: number; - ssid: string; - bssid: string; - channel: number; - subnet_mask: string; - gateway_ip: string; - dns_ip_1: string; - dns_ip_2?: string; - }; - - type WifiSettings = { - hostname: string; - priority_RSSI: boolean; - wifi_networks: networkItem[]; - }; - - type networkItem = { - ssid: string; - password: string; - static_ip_config: boolean; - local_ip?: string; - subnet_mask?: string; - gateway_ip?: string; - dns_ip_1?: string; - dns_ip_2?: string; - }; - - let networkEditable: networkItem = { + let networkEditable: KnownNetworkItem = { ssid: '', password: '', static_ip_config: false, @@ -81,7 +51,7 @@ let wifiStatus: WifiStatus; let wifiSettings: WifiSettings; - let dndNetworkList: networkItem[] = []; + let dndNetworkList: KnownNetworkItem[] = []; let showWifiDetails = false;