From 5148891fc4a29b4850e35160cc36beffa20fd0a8 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Tue, 23 Apr 2024 19:35:29 +0200 Subject: [PATCH] Updates the esp32 template to use eventsocket --- app2/src/lib/services/index.ts | 1 - app2/src/lib/services/socket-service.ts | 95 ---- app2/src/lib/stores/analytics.ts | 30 +- app2/src/lib/stores/index.ts | 1 + app2/src/lib/stores/socket-store.ts | 1 - app2/src/lib/stores/socket.ts | 115 +++++ app2/src/lib/stores/telemetry.ts | 15 +- app2/src/lib/types/models.ts | 113 +++++ app2/src/routes/+layout.svelte | 173 +++---- app2/src/routes/connections/mqtt/MQTT.svelte | 2 +- .../routes/connections/mqtt/MQTTConfig.svelte | 7 +- app2/src/routes/connections/ntp/NTP.svelte | 17 +- app2/src/routes/controller/+layout.svelte | 4 +- app2/src/routes/controller/Controls.svelte | 2 +- app2/src/routes/demo/+page.svelte | 13 - app2/src/routes/demo/+page.ts | 7 - app2/src/routes/demo/Demo.svelte | 83 ---- app2/src/routes/mqtt/+page.svelte | 15 - app2/src/routes/mqtt/+page.ts | 7 - app2/src/routes/mqtt/MQTT.svelte | 304 ------------ app2/src/routes/mqtt/MQTTConfig.svelte | 192 -------- app2/src/routes/ntp/+page.svelte | 13 - app2/src/routes/ntp/+page.ts | 7 - app2/src/routes/ntp/NTP.svelte | 303 ------------ app2/src/routes/ntp/timezones.ts | 466 ------------------ app2/src/routes/statusbar.svelte | 2 +- .../routes/system/status/SystemStatus.svelte | 110 ++--- app2/src/routes/wifi/ap/Accesspoint.svelte | 20 +- app2/src/routes/wifi/sta/Scan.svelte | 13 +- app2/src/routes/wifi/sta/Wifi.svelte | 36 +- app2/vite.config.ts | 8 +- 31 files changed, 366 insertions(+), 1809 deletions(-) delete mode 100644 app2/src/lib/services/socket-service.ts create mode 100644 app2/src/lib/stores/socket.ts create mode 100644 app2/src/lib/types/models.ts delete mode 100644 app2/src/routes/demo/+page.svelte delete mode 100644 app2/src/routes/demo/+page.ts delete mode 100644 app2/src/routes/demo/Demo.svelte delete mode 100644 app2/src/routes/mqtt/+page.svelte delete mode 100644 app2/src/routes/mqtt/+page.ts delete mode 100644 app2/src/routes/mqtt/MQTT.svelte delete mode 100644 app2/src/routes/mqtt/MQTTConfig.svelte delete mode 100644 app2/src/routes/ntp/+page.svelte delete mode 100644 app2/src/routes/ntp/+page.ts delete mode 100644 app2/src/routes/ntp/NTP.svelte delete mode 100644 app2/src/routes/ntp/timezones.ts diff --git a/app2/src/lib/services/index.ts b/app2/src/lib/services/index.ts index 5b10489..7a112d0 100644 --- a/app2/src/lib/services/index.ts +++ b/app2/src/lib/services/index.ts @@ -1,3 +1,2 @@ export { default as fileService } from './file-service'; -export { default as socketService } from './socket-service'; export { default as resultService } from './result-service'; diff --git a/app2/src/lib/services/socket-service.ts b/app2/src/lib/services/socket-service.ts deleted file mode 100644 index b9078f5..0000000 --- a/app2/src/lib/services/socket-service.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { isConnected, socketData } from '$lib/stores'; -import { Result, Ok } from '$lib/utilities'; -import { resultService } from '$lib/services'; -import { type WebSocketJsonMsg } from '$lib/models'; -import type { Writable } from 'svelte/store'; - -type WebsocketOutData = string | ArrayBufferLike | Blob | ArrayBufferView; - -// TODO -/** - * MOVE THE store to a store.ts file - * - * Make an object on the class that encapsulate all the stores - * - * Make the handle message function look up the type and set the value, to simplify the code - */ - -class SocketService { - private socket!: WebSocket; - - constructor() {} - - public connect(url: string): void { - if (typeof WebSocket === 'undefined') return; - this.socket = new WebSocket(url); - this.socket.binaryType = 'arraybuffer'; - this.socket.onopen = () => this.handleConnected(); - this.socket.onclose = () => this.handleDisconnected(); - this.socket.onmessage = (event: MessageEvent) => - resultService.handleResult(this.handleMessage(event), 'SocketService'); - this.socket.onerror = (error: Event) => console.log(error); - } - - public send(data: WebsocketOutData): Result { - if (typeof WebSocket === 'undefined') return Result.err('The connection is not open'); - if (this.socket?.readyState === WebSocket.OPEN) { - this.socket.send(data); - return Ok.void(); - } - return Result.err('The connection is not open'); - } - - public addPublisher(store: Writable, type?: string) { - const publish = (data: WebsocketOutData) => - this.send(type ? JSON.stringify({ type, data }) : data); - store.subscribe(publish); - } - - private handleConnected(): void { - isConnected.set(true); - } - - private handleDisconnected(): void { - isConnected.set(false); - } - - private getJsonFromMessage(msg: string): Result { - try { - return Result.ok(JSON.parse(msg) as WebSocketJsonMsg); - } catch (error) { - return Result.err('Failed to parse socket message', error); - } - } - - private handleBufferMessage(buffer: ArrayBuffer): Result { - console.log(buffer); - return Ok.void(); - } - - private handleMessage(event: MessageEvent): Result { - if (event.data instanceof ArrayBuffer) { - return this.handleBufferMessage(event.data); - } - let msgRes = this.getJsonFromMessage(event.data); - if (msgRes.isErr()) { - return msgRes; - } - const msg = msgRes.inner; - - if (msg.type === 'log') { - socketData.logs.update((entries) => { - entries.push(msg.data); - return entries; - }); - return Ok.void(); - } else if (msg.data && msg.type in socketData) { - socketData[msg.type].set(msg.data); - return Ok.void(); - } - - return Result.err(`Got invalid msg: ${JSON.stringify(msg)}`); - } -} - -export default new SocketService(); diff --git a/app2/src/lib/stores/analytics.ts b/app2/src/lib/stores/analytics.ts index 68d9a42..d8fdb17 100644 --- a/app2/src/lib/stores/analytics.ts +++ b/app2/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,23 +12,30 @@ let analytics_data = { core_temp: [] }; +const maxAnalyticsData = 1000; // roughly 33 Minutes of data at 1 update per 2 seconds + 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) })); } }; diff --git a/app2/src/lib/stores/index.ts b/app2/src/lib/stores/index.ts index cd14a59..7684643 100644 --- a/app2/src/lib/stores/index.ts +++ b/app2/src/lib/stores/index.ts @@ -1,3 +1,4 @@ export * from './socket-store'; export * from './logging-store'; export * from './model-store'; +export * from './socket'; diff --git a/app2/src/lib/stores/socket-store.ts b/app2/src/lib/stores/socket-store.ts index 94e9740..11dc6f6 100644 --- a/app2/src/lib/stores/socket-store.ts +++ b/app2/src/lib/stores/socket-store.ts @@ -1,7 +1,6 @@ import { writable, type Writable } from 'svelte/store'; import { type angles } from '$lib/models'; -export const isConnected = writable(false); export const servoAnglesOut: Writable = writable([ 0, 45, -90, 0, 45, -90, 0, 45, -90, 0, 45, -90 ]); diff --git a/app2/src/lib/stores/socket.ts b/app2/src/lib/stores/socket.ts new file mode 100644 index 0000000..e230c25 --- /dev/null +++ b/app2/src/lib/stores/socket.ts @@ -0,0 +1,115 @@ +import { writable } from 'svelte/store'; + +function createWebSocket() { + let listeners = new Map void>>(); + const { subscribe, set } = writable(false); + const socketEvents = ['open', 'close', 'error', 'message', 'unresponsive'] as const; + type SocketEvent = (typeof socketEvents)[number]; + let unresponsiveTimeoutId: number; + let reconnectTimeoutId: number; + let ws: WebSocket; + let socketUrl: string | URL; + + function init(url: string | URL) { + socketUrl = url; + connect(); + } + + function disconnect(reason: SocketEvent, event?: Event) { + ws.close(); + set(false); + clearTimeout(unresponsiveTimeoutId); + clearTimeout(reconnectTimeoutId); + listeners.get(reason)?.forEach((listener) => listener(event)); + reconnectTimeoutId = setTimeout(connect, 1000); + } + + function connect() { + ws = new WebSocket(socketUrl); + ws.onopen = (ev) => { + set(true); + clearTimeout(reconnectTimeoutId); + listeners.get('open')?.forEach((listener) => listener(ev)); + for (const event of listeners.keys()) { + if (socketEvents.includes(event as SocketEvent)) continue; + sendEvent('subscribe', event); + } + }; + ws.onmessage = (message) => { + resetUnresponsiveCheck(); + let data = message.data; + + if (data instanceof ArrayBuffer) { + listeners.get('binary')?.forEach((listener) => listener(data)); + return; + } + listeners.get('message')?.forEach((listener) => listener(data)); + try { + data = JSON.parse(message.data); + } catch (error) { + listeners.get('error')?.forEach((listener) => listener(error)); + return; + } + listeners.get('json')?.forEach((listener) => listener(data)); + const [event, payload] = data; + if (event) listeners.get(event)?.forEach((listener) => listener(payload)); + }; + ws.onerror = (ev) => disconnect('error', ev); + ws.onclose = (ev) => disconnect('close', ev); + } + + function unsubscribe(event: string, listener?: (data: any) => void) { + let eventListeners = listeners.get(event); + if (!eventListeners) return; + + if (!eventListeners.size) { + sendEvent('unsubscribe', event); + } + if (listener) { + eventListeners?.delete(listener); + } else { + listeners.delete(event); + } + } + + function resetUnresponsiveCheck() { + clearTimeout(unresponsiveTimeoutId); + unresponsiveTimeoutId = setTimeout(() => disconnect('unresponsive'), 2000); + } + + function send(msg: unknown) { + if (!ws || ws.readyState !== WebSocket.OPEN) return; + ws.send(JSON.stringify(msg)); + } + + function sendEvent(event: string, data: unknown) { + send({ event, data }); + } + + return { + subscribe, + send, + sendEvent, + init, + on: (event: string, listener: (data: T) => void): (() => void) => { + let eventListeners = listeners.get(event); + if (!eventListeners) { + if (!socketEvents.includes(event as SocketEvent)) { + sendEvent('subscribe', event); + } + eventListeners = new Set(); + listeners.set(event, eventListeners); + } + eventListeners.add(listener as (data: any) => void); + + return () => { + unsubscribe(event, listener); + }; + }, + off: (event: string, listener?: (data: any) => void) => { + unsubscribe(event, listener); + } + }; +} + +export const socket = createWebSocket(); diff --git a/app2/src/lib/stores/telemetry.ts b/app2/src/lib/stores/telemetry.ts index 0c3893c..c6eead6 100644 --- a/app2/src/lib/stores/telemetry.ts +++ b/app2/src/lib/stores/telemetry.ts @@ -1,7 +1,6 @@ import { writable } from 'svelte/store'; let telemetry_data = { - serverAvailable: true, rssi: { rssi: 0, disconnected: true @@ -24,25 +23,25 @@ function createTelemetry() { subscribe, setRSSI: (data: string) => { if (!isNaN(Number(data))) { - update((telemerty_data) => ({ - ...telemerty_data, + update((telemetry_data) => ({ + ...telemetry_data, rssi: { rssi: Number(data), disconnected: false } })); } else { - update((telemerty_data) => ({ ...telemerty_data, rssi: { rssi: 0, disconnected: true } })); + update((telemetry_data) => ({ ...telemetry_data, rssi: { rssi: 0, disconnected: true } })); } }, setBattery: (data: string) => { const content = JSON.parse(data); - update((telemerty_data) => ({ - ...telemerty_data, + update((telemetry_data) => ({ + ...telemetry_data, battery: { soc: content.soc, charging: content.charging } })); }, setDownloadOTA: (data: string) => { const content = JSON.parse(data); - update((telemerty_data) => ({ - ...telemerty_data, + update((telemetry_data) => ({ + ...telemetry_data, download_ota: { status: content.status, progress: content.progress, error: content.error } })); } diff --git a/app2/src/lib/types/models.ts b/app2/src/lib/types/models.ts new file mode 100644 index 0000000..e403599 --- /dev/null +++ b/app2/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/app2/src/routes/+layout.svelte b/app2/src/routes/+layout.svelte index 9106ded..036512d 100644 --- a/app2/src/routes/+layout.svelte +++ b/app2/src/routes/+layout.svelte @@ -14,65 +14,57 @@ import Menu from './menu.svelte'; import Statusbar from './statusbar.svelte'; import Login from './login.svelte'; - import { get, type Writable } from 'svelte/store'; - import { isConnected, mode, outControllerData, servoAngles, servoAnglesOut, socketData } from '$lib/stores'; - import { throttler } from '$lib/utilities'; + import { mode, outControllerData, servoAnglesOut, socket } from '$lib/stores'; + import type { Analytics } from '$lib/types/models'; export let data: LayoutData; - type WebsocketOutData = string | ArrayBufferLike | Blob | ArrayBufferView; - onMount(async () => { if ($user.bearer_token !== '') { await validateUser($user); } - connectToEventSource(); - connectToSocket() - addPublisher(outControllerData, "controller") - addPublisher(mode as unknown as Writable, "mode") - addPublisher(servoAnglesOut as unknown as Writable, "angles") - }); - - const connectToSocket = () => { const ws_token = $page.data.features.security ? '?access_token=' + $user.bearer_token : ''; + socket.init(`ws://${window.location.host}/ws/events${ws_token}`); - socket = new WebSocket('ws://' + $page.url.host + '/ws' + ws_token); - socket.onopen = (event) => isConnected.set(true); - socket.onclose = (event) => { - isConnected.set(false) - notifications.error('Websocket disconnected', 5000); - }; - socket.onmessage = ((event: MessageEvent) => { - const message = JSON.parse(event.data); - if (message.type === 'log') { - socketData.logs.update((entries) => { - entries.push(message.data); - return entries; - }); - } else if (message.data && message.type in socketData) { - const store = socketData[message.type as keyof typeof socketData]; - if (JSON.stringify(get(store)) !== JSON.stringify(message.data)) - store.set(message.data); - } - }); - } + addEventListeners(); - const addPublisher = (store: Writable, type?: string) => { - const publish = (data: WebsocketOutData) => { - if (socket.readyState === WebSocket.OPEN) - throttle.throttle( - () => socket.send(type ? JSON.stringify({ type, data }) : data), - 100); - } - store.subscribe(publish); - } - - onDestroy(() => { - disconnectEventSource(); - socket?.close(); + outControllerData.subscribe((data) => socket.sendEvent("input", data)); + mode.subscribe((data) => socket.sendEvent("mode", data)); + servoAnglesOut.subscribe((data) => socket.sendEvent("angles", data)); }); - async function validateUser(userdata: userProfile) { + onDestroy(() => { + removeEventListeners(); + }); + + const addEventListeners = () => { + socket.on('open', handleOpen); + socket.on('close', handleClose); + socket.on('error', handleError); + socket.on('rssi', handleNetworkStatus); + socket.on('infoToast', handleInfoToast); + socket.on('successToast', handleSuccessToast); + socket.on('warningToast', handleWarningToast); + socket.on('errorToast', handleErrorToast); + if ($page.data.features.analytics) socket.on('analytics', handleAnalytics); + if ($page.data.features.battery) socket.on('battery', handleBattery); + if ($page.data.features.download_firmware) socket.on('otastatus', handleOAT); + }; + + const removeEventListeners = () => { + socket.off('analytics', handleAnalytics); + socket.off('open', handleOpen); + socket.off('close', handleClose); + socket.off('rssi', handleNetworkStatus); + socket.off('infoToast', handleInfoToast); + socket.off('successToast', handleSuccessToast); + socket.off('warningToast', handleWarningToast); + socket.off('errorToast', handleErrorToast); + socket.off('battery', handleBattery); + socket.off('otastatus', handleOAT); + }; + + async function validateUser(userdata: userProfile) { try { const response = await fetch('/rest/verifyAuthorization', { method: 'GET', @@ -89,74 +81,31 @@ } } - let menuOpen = false; - let throttle = new throttler(); + const handleOpen = () => { + notifications.success('Connection to device established', 5000); + }; - let socket: WebSocket - let eventSourceUrl = '/events'; - let eventSource: EventSource; - let unresponsiveTimeoutId: number; - - function connectToEventSource() { - eventSource = new EventSource(eventSourceUrl); - - eventSource.addEventListener('open', () => { - notifications.success('Connection to device established', 5000); - telemetry.setRSSI('found'); // Update store and flag as server being available again - }); - - eventSource.addEventListener('rssi', (event) => { - telemetry.setRSSI(event.data); - resetUnresponsiveCheck(); - }); - - eventSource.addEventListener('error', (event) => { - reconnectEventSource(); - }); - - eventSource.addEventListener('infoToast', (event) => { - notifications.info(event.data, 5000); - }); - - eventSource.addEventListener('successToast', (event) => { - notifications.success(event.data, 5000); - }); - - eventSource.addEventListener('warningToast', (event) => { - notifications.warning(event.data, 5000); - }); - - eventSource.addEventListener('errorToast', (event) => { - notifications.error(event.data, 5000); - }); - - eventSource.addEventListener('battery', (event) => { - telemetry.setBattery(event.data); - }); - - eventSource.addEventListener('download_ota', (event) => { - telemetry.setDownloadOTA(event.data); - }); - eventSource.addEventListener('analytics', (event) => { - analytics.addData(event.data); - }); - } - - function disconnectEventSource() { - clearTimeout(unresponsiveTimeoutId); - eventSource?.close(); - } - - function reconnectEventSource() { + const handleClose = () => { notifications.error('Connection to device lost', 5000); - disconnectEventSource(); - connectToEventSource(); - } + telemetry.setRSSI('lost'); + }; - function resetUnresponsiveCheck() { - clearTimeout(unresponsiveTimeoutId); - unresponsiveTimeoutId = setTimeout(() => reconnectEventSource(), 2000); - } + const handleError = (data: any) => console.error(data); + + const handleInfoToast = (data: string) => notifications.info(data, 5000); + const handleWarningToast = (data: string) => notifications.warning(data, 5000); + const handleErrorToast = (data: string) => notifications.error(data, 5000); + const handleSuccessToast = (data: string) => notifications.success(data, 5000); + + const handleAnalytics = (data: Analytics) => analytics.addData(data); + + const handleNetworkStatus = (data: string) => telemetry.setRSSI(data); + + const handleBattery = (data: string) => telemetry.setBattery(data); + + const handleOAT = (data: string) => telemetry.setDownloadOTA(data); + + let menuOpen = false; diff --git a/app2/src/routes/connections/mqtt/MQTT.svelte b/app2/src/routes/connections/mqtt/MQTT.svelte index 81e6d9e..30b66ef 100644 --- a/app2/src/routes/connections/mqtt/MQTT.svelte +++ b/app2/src/routes/connections/mqtt/MQTT.svelte @@ -96,7 +96,7 @@ body: JSON.stringify(data) }); if (response.status == 200) { - notifications.success('Security settings updated.', 3000); + notifications.success('MQTT settings updated.', 3000); mqttSettings = await response.json(); } else { notifications.error('User not authorized.', 3000); diff --git a/app2/src/routes/connections/mqtt/MQTTConfig.svelte b/app2/src/routes/connections/mqtt/MQTTConfig.svelte index aa8660e..82fa472 100644 --- a/app2/src/routes/connections/mqtt/MQTTConfig.svelte +++ b/app2/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/app2/src/routes/connections/ntp/NTP.svelte b/app2/src/routes/connections/ntp/NTP.svelte index a87b68b..28314e9 100644 --- a/app2/src/routes/connections/ntp/NTP.svelte +++ b/app2/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/app2/src/routes/controller/+layout.svelte b/app2/src/routes/controller/+layout.svelte index cec36c6..3a8517f 100644 --- a/app2/src/routes/controller/+layout.svelte +++ b/app2/src/routes/controller/+layout.svelte @@ -1,9 +1,9 @@
- {#if $isConnected} + {#if $socket} {:else} diff --git a/app2/src/routes/controller/Controls.svelte b/app2/src/routes/controller/Controls.svelte index 65137a9..6f26b1c 100644 --- a/app2/src/routes/controller/Controls.svelte +++ b/app2/src/routes/controller/Controls.svelte @@ -2,7 +2,7 @@ import nipplejs from 'nipplejs'; import { onMount } from 'svelte'; import { capitalize, throttler, toInt8 } from '$lib/utilities'; - import { input, outControllerData, mode, modes, type Modes, ModesEnum } from '$lib/stores'; + import { input, outControllerData, mode, modes, type Modes, ModesEnum, socket } from '$lib/stores'; import type { vector } from '$lib/models'; let throttle = new throttler(); diff --git a/app2/src/routes/demo/+page.svelte b/app2/src/routes/demo/+page.svelte deleted file mode 100644 index 788b655..0000000 --- a/app2/src/routes/demo/+page.svelte +++ /dev/null @@ -1,13 +0,0 @@ - - -
- -
diff --git a/app2/src/routes/demo/+page.ts b/app2/src/routes/demo/+page.ts deleted file mode 100644 index 84b638f..0000000 --- a/app2/src/routes/demo/+page.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { PageLoad } from './$types'; - -export const load = (async ({ fetch }) => { - return { - title: 'Demo App' - }; -}) satisfies PageLoad; diff --git a/app2/src/routes/demo/Demo.svelte b/app2/src/routes/demo/Demo.svelte deleted file mode 100644 index a950bfb..0000000 --- a/app2/src/routes/demo/Demo.svelte +++ /dev/null @@ -1,83 +0,0 @@ - - - - - Light State -
-

Websocket Example

-
-
- {#each $servoAngles as angle, index} - updateAngle(index, parseFloat(event.target?.value))} - /> - {/each} -
-
-
-
diff --git a/app2/src/routes/mqtt/+page.svelte b/app2/src/routes/mqtt/+page.svelte deleted file mode 100644 index 7895d99..0000000 --- a/app2/src/routes/mqtt/+page.svelte +++ /dev/null @@ -1,15 +0,0 @@ - - -
- - -
diff --git a/app2/src/routes/mqtt/+page.ts b/app2/src/routes/mqtt/+page.ts deleted file mode 100644 index 1b2b841..0000000 --- a/app2/src/routes/mqtt/+page.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { PageLoad } from './$types'; - -export const load = (async () => { - return { - title: "MQTT" - }; -}) satisfies PageLoad; \ No newline at end of file diff --git a/app2/src/routes/mqtt/MQTT.svelte b/app2/src/routes/mqtt/MQTT.svelte deleted file mode 100644 index 81e6d9e..0000000 --- a/app2/src/routes/mqtt/MQTT.svelte +++ /dev/null @@ -1,304 +0,0 @@ - - - - - MQTT -
- {#await getMQTTStatus()} - - {:then nothing} -
-
-
- -
-
-
Status
-
- {#if mqttStatus.connected} - Connected - {:else if !mqttStatus.enabled} - MQTT Disabled - {:else} - {mqttStatus.last_error} - {/if} -
-
-
- -
-
- -
-
-
Client ID
-
- {mqttStatus.client_id} -
-
-
-
- {/await} -
- - {#if !$page.data.features.security || $user.admin} - - Change MQTT Settings - -
-
- - - -
-
- -
- - - {/if} - diff --git a/app2/src/routes/mqtt/MQTTConfig.svelte b/app2/src/routes/mqtt/MQTTConfig.svelte deleted file mode 100644 index aa8660e..0000000 --- a/app2/src/routes/mqtt/MQTTConfig.svelte +++ /dev/null @@ -1,192 +0,0 @@ - - - - - MQTT Broker Settings -
- {#await getBrokerSettings()} - - {:then nothing} -
-
- - The LED is controllable via MQTT with the demo project designed to work with Home - Assistant's auto discovery feature. -
-
-
- - - -
-
- - - -
-
- - - -
-
-
-
- -
- - {/await} -
- diff --git a/app2/src/routes/ntp/+page.svelte b/app2/src/routes/ntp/+page.svelte deleted file mode 100644 index baed7e8..0000000 --- a/app2/src/routes/ntp/+page.svelte +++ /dev/null @@ -1,13 +0,0 @@ - - -
- -
diff --git a/app2/src/routes/ntp/+page.ts b/app2/src/routes/ntp/+page.ts deleted file mode 100644 index 6ced9b9..0000000 --- a/app2/src/routes/ntp/+page.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { PageLoad } from './$types'; - -export const load = (async () => { - return { - title: 'NTP' - }; -}) satisfies PageLoad; diff --git a/app2/src/routes/ntp/NTP.svelte b/app2/src/routes/ntp/NTP.svelte deleted file mode 100644 index a87b68b..0000000 --- a/app2/src/routes/ntp/NTP.svelte +++ /dev/null @@ -1,303 +0,0 @@ - - - - - Network Time -
- {#await getNTPStatus()} - - {:then nothing} -
-
-
- -
-
-
Status
-
- {ntpStatus.status === 1 ? 'Active' : 'Inactive'} -
-
-
- -
-
- -
-
-
NTP Server
-
- {ntpStatus.server} -
-
-
- -
-
- -
-
-
Local Time
-
- {new Intl.DateTimeFormat('en-GB', { - dateStyle: 'long', - timeStyle: 'long' - }).format(new Date(ntpStatus.local_time))} -
-
-
- -
-
- -
-
-
UTC Time
-
- {new Intl.DateTimeFormat('en-GB', { - dateStyle: 'long', - timeStyle: 'long', - timeZone: 'UTC' - }).format(new Date(ntpStatus.utc_time))} -
-
-
- -
-
- -
-
-
Uptime
-
- {convertSeconds(ntpStatus.uptime)} -
-
-
-
- {/await} -
- - {#if !$page.data.features.security || $user.admin} - - Change NTP Settings -
- - - - - - - -
- -
-
-
- {/if} -
diff --git a/app2/src/routes/ntp/timezones.ts b/app2/src/routes/ntp/timezones.ts deleted file mode 100644 index ad6c0ee..0000000 --- a/app2/src/routes/ntp/timezones.ts +++ /dev/null @@ -1,466 +0,0 @@ -export type TimeZones = { - [name: string]: string - }; - -export const TIME_ZONES: TimeZones = { - "Africa/Abidjan": "GMT0", - "Africa/Accra": "GMT0", - "Africa/Addis_Ababa": "EAT-3", - "Africa/Algiers": "CET-1", - "Africa/Asmara": "EAT-3", - "Africa/Bamako": "GMT0", - "Africa/Bangui": "WAT-1", - "Africa/Banjul": "GMT0", - "Africa/Bissau": "GMT0", - "Africa/Blantyre": "CAT-2", - "Africa/Brazzaville": "WAT-1", - "Africa/Bujumbura": "CAT-2", - "Africa/Cairo": "EET-2", - "Africa/Casablanca": "UNK-1", - "Africa/Ceuta": "CET-1CEST,M3.5.0,M10.5.0/3", - "Africa/Conakry": "GMT0", - "Africa/Dakar": "GMT0", - "Africa/Dar_es_Salaam": "EAT-3", - "Africa/Djibouti": "EAT-3", - "Africa/Douala": "WAT-1", - "Africa/El_Aaiun": "UNK-1", - "Africa/Freetown": "GMT0", - "Africa/Gaborone": "CAT-2", - "Africa/Harare": "CAT-2", - "Africa/Johannesburg": "SAST-2", - "Africa/Juba": "EAT-3", - "Africa/Kampala": "EAT-3", - "Africa/Khartoum": "CAT-2", - "Africa/Kigali": "CAT-2", - "Africa/Kinshasa": "WAT-1", - "Africa/Lagos": "WAT-1", - "Africa/Libreville": "WAT-1", - "Africa/Lome": "GMT0", - "Africa/Luanda": "WAT-1", - "Africa/Lubumbashi": "CAT-2", - "Africa/Lusaka": "CAT-2", - "Africa/Malabo": "WAT-1", - "Africa/Maputo": "CAT-2", - "Africa/Maseru": "SAST-2", - "Africa/Mbabane": "SAST-2", - "Africa/Mogadishu": "EAT-3", - "Africa/Monrovia": "GMT0", - "Africa/Nairobi": "EAT-3", - "Africa/Ndjamena": "WAT-1", - "Africa/Niamey": "WAT-1", - "Africa/Nouakchott": "GMT0", - "Africa/Ouagadougou": "GMT0", - "Africa/Porto-Novo": "WAT-1", - "Africa/Sao_Tome": "GMT0", - "Africa/Tripoli": "EET-2", - "Africa/Tunis": "CET-1", - "Africa/Windhoek": "CAT-2", - "America/Adak": "HST10HDT,M3.2.0,M11.1.0", - "America/Anchorage": "AKST9AKDT,M3.2.0,M11.1.0", - "America/Anguilla": "AST4", - "America/Antigua": "AST4", - "America/Araguaina": "UNK3", - "America/Argentina/Buenos_Aires": "UNK3", - "America/Argentina/Catamarca": "UNK3", - "America/Argentina/Cordoba": "UNK3", - "America/Argentina/Jujuy": "UNK3", - "America/Argentina/La_Rioja": "UNK3", - "America/Argentina/Mendoza": "UNK3", - "America/Argentina/Rio_Gallegos": "UNK3", - "America/Argentina/Salta": "UNK3", - "America/Argentina/San_Juan": "UNK3", - "America/Argentina/San_Luis": "UNK3", - "America/Argentina/Tucuman": "UNK3", - "America/Argentina/Ushuaia": "UNK3", - "America/Aruba": "AST4", - "America/Asuncion": "UNK4UNK,M10.1.0/0,M3.4.0/0", - "America/Atikokan": "EST5", - "America/Bahia": "UNK3", - "America/Bahia_Banderas": "CST6CDT,M4.1.0,M10.5.0", - "America/Barbados": "AST4", - "America/Belem": "UNK3", - "America/Belize": "CST6", - "America/Blanc-Sablon": "AST4", - "America/Boa_Vista": "UNK4", - "America/Bogota": "UNK5", - "America/Boise": "MST7MDT,M3.2.0,M11.1.0", - "America/Cambridge_Bay": "MST7MDT,M3.2.0,M11.1.0", - "America/Campo_Grande": "UNK4", - "America/Cancun": "EST5", - "America/Caracas": "UNK4", - "America/Cayenne": "UNK3", - "America/Cayman": "EST5", - "America/Chicago": "CST6CDT,M3.2.0,M11.1.0", - "America/Chihuahua": "MST7MDT,M4.1.0,M10.5.0", - "America/Costa_Rica": "CST6", - "America/Creston": "MST7", - "America/Cuiaba": "UNK4", - "America/Curacao": "AST4", - "America/Danmarkshavn": "GMT0", - "America/Dawson": "MST7", - "America/Dawson_Creek": "MST7", - "America/Denver": "MST7MDT,M3.2.0,M11.1.0", - "America/Detroit": "EST5EDT,M3.2.0,M11.1.0", - "America/Dominica": "AST4", - "America/Edmonton": "MST7MDT,M3.2.0,M11.1.0", - "America/Eirunepe": "UNK5", - "America/El_Salvador": "CST6", - "America/Fort_Nelson": "MST7", - "America/Fortaleza": "UNK3", - "America/Glace_Bay": "AST4ADT,M3.2.0,M11.1.0", - "America/Godthab": "UNK3UNK,M3.5.0/-2,M10.5.0/-1", - "America/Goose_Bay": "AST4ADT,M3.2.0,M11.1.0", - "America/Grand_Turk": "EST5EDT,M3.2.0,M11.1.0", - "America/Grenada": "AST4", - "America/Guadeloupe": "AST4", - "America/Guatemala": "CST6", - "America/Guayaquil": "UNK5", - "America/Guyana": "UNK4", - "America/Halifax": "AST4ADT,M3.2.0,M11.1.0", - "America/Havana": "CST5CDT,M3.2.0/0,M11.1.0/1", - "America/Hermosillo": "MST7", - "America/Indiana/Indianapolis": "EST5EDT,M3.2.0,M11.1.0", - "America/Indiana/Knox": "CST6CDT,M3.2.0,M11.1.0", - "America/Indiana/Marengo": "EST5EDT,M3.2.0,M11.1.0", - "America/Indiana/Petersburg": "EST5EDT,M3.2.0,M11.1.0", - "America/Indiana/Tell_City": "CST6CDT,M3.2.0,M11.1.0", - "America/Indiana/Vevay": "EST5EDT,M3.2.0,M11.1.0", - "America/Indiana/Vincennes": "EST5EDT,M3.2.0,M11.1.0", - "America/Indiana/Winamac": "EST5EDT,M3.2.0,M11.1.0", - "America/Inuvik": "MST7MDT,M3.2.0,M11.1.0", - "America/Iqaluit": "EST5EDT,M3.2.0,M11.1.0", - "America/Jamaica": "EST5", - "America/Juneau": "AKST9AKDT,M3.2.0,M11.1.0", - "America/Kentucky/Louisville": "EST5EDT,M3.2.0,M11.1.0", - "America/Kentucky/Monticello": "EST5EDT,M3.2.0,M11.1.0", - "America/Kralendijk": "AST4", - "America/La_Paz": "UNK4", - "America/Lima": "UNK5", - "America/Los_Angeles": "PST8PDT,M3.2.0,M11.1.0", - "America/Lower_Princes": "AST4", - "America/Maceio": "UNK3", - "America/Managua": "CST6", - "America/Manaus": "UNK4", - "America/Marigot": "AST4", - "America/Martinique": "AST4", - "America/Matamoros": "CST6CDT,M3.2.0,M11.1.0", - "America/Mazatlan": "MST7MDT,M4.1.0,M10.5.0", - "America/Menominee": "CST6CDT,M3.2.0,M11.1.0", - "America/Merida": "CST6CDT,M4.1.0,M10.5.0", - "America/Metlakatla": "AKST9AKDT,M3.2.0,M11.1.0", - "America/Mexico_City": "CST6CDT,M4.1.0,M10.5.0", - "America/Miquelon": "UNK3UNK,M3.2.0,M11.1.0", - "America/Moncton": "AST4ADT,M3.2.0,M11.1.0", - "America/Monterrey": "CST6CDT,M4.1.0,M10.5.0", - "America/Montevideo": "UNK3", - "America/Montreal": "EST5EDT,M3.2.0,M11.1.0", - "America/Montserrat": "AST4", - "America/Nassau": "EST5EDT,M3.2.0,M11.1.0", - "America/New_York": "EST5EDT,M3.2.0,M11.1.0", - "America/Nipigon": "EST5EDT,M3.2.0,M11.1.0", - "America/Nome": "AKST9AKDT,M3.2.0,M11.1.0", - "America/Noronha": "UNK2", - "America/North_Dakota/Beulah": "CST6CDT,M3.2.0,M11.1.0", - "America/North_Dakota/Center": "CST6CDT,M3.2.0,M11.1.0", - "America/North_Dakota/New_Salem": "CST6CDT,M3.2.0,M11.1.0", - "America/Ojinaga": "MST7MDT,M3.2.0,M11.1.0", - "America/Panama": "EST5", - "America/Pangnirtung": "EST5EDT,M3.2.0,M11.1.0", - "America/Paramaribo": "UNK3", - "America/Phoenix": "MST7", - "America/Port-au-Prince": "EST5EDT,M3.2.0,M11.1.0", - "America/Port_of_Spain": "AST4", - "America/Porto_Velho": "UNK4", - "America/Puerto_Rico": "AST4", - "America/Punta_Arenas": "UNK3", - "America/Rainy_River": "CST6CDT,M3.2.0,M11.1.0", - "America/Rankin_Inlet": "CST6CDT,M3.2.0,M11.1.0", - "America/Recife": "UNK3", - "America/Regina": "CST6", - "America/Resolute": "CST6CDT,M3.2.0,M11.1.0", - "America/Rio_Branco": "UNK5", - "America/Santarem": "UNK3", - "America/Santiago": "UNK4UNK,M9.1.6/24,M4.1.6/24", - "America/Santo_Domingo": "AST4", - "America/Sao_Paulo": "UNK3", - "America/Scoresbysund": "UNK1UNK,M3.5.0/0,M10.5.0/1", - "America/Sitka": "AKST9AKDT,M3.2.0,M11.1.0", - "America/St_Barthelemy": "AST4", - "America/St_Johns": "NST3:30NDT,M3.2.0,M11.1.0", - "America/St_Kitts": "AST4", - "America/St_Lucia": "AST4", - "America/St_Thomas": "AST4", - "America/St_Vincent": "AST4", - "America/Swift_Current": "CST6", - "America/Tegucigalpa": "CST6", - "America/Thule": "AST4ADT,M3.2.0,M11.1.0", - "America/Thunder_Bay": "EST5EDT,M3.2.0,M11.1.0", - "America/Tijuana": "PST8PDT,M3.2.0,M11.1.0", - "America/Toronto": "EST5EDT,M3.2.0,M11.1.0", - "America/Tortola": "AST4", - "America/Vancouver": "PST8PDT,M3.2.0,M11.1.0", - "America/Whitehorse": "MST7", - "America/Winnipeg": "CST6CDT,M3.2.0,M11.1.0", - "America/Yakutat": "AKST9AKDT,M3.2.0,M11.1.0", - "America/Yellowknife": "MST7MDT,M3.2.0,M11.1.0", - "Antarctica/Casey": "UNK-8", - "Antarctica/Davis": "UNK-7", - "Antarctica/DumontDUrville": "UNK-10", - "Antarctica/Macquarie": "UNK-11", - "Antarctica/Mawson": "UNK-5", - "Antarctica/McMurdo": "NZST-12NZDT,M9.5.0,M4.1.0/3", - "Antarctica/Palmer": "UNK3", - "Antarctica/Rothera": "UNK3", - "Antarctica/Syowa": "UNK-3", - "Antarctica/Troll": "UNK0UNK-2,M3.5.0/1,M10.5.0/3", - "Antarctica/Vostok": "UNK-6", - "Arctic/Longyearbyen": "CET-1CEST,M3.5.0,M10.5.0/3", - "Asia/Aden": "UNK-3", - "Asia/Almaty": "UNK-6", - "Asia/Amman": "EET-2EEST,M3.5.4/24,M10.5.5/1", - "Asia/Anadyr": "UNK-12", - "Asia/Aqtau": "UNK-5", - "Asia/Aqtobe": "UNK-5", - "Asia/Ashgabat": "UNK-5", - "Asia/Atyrau": "UNK-5", - "Asia/Baghdad": "UNK-3", - "Asia/Bahrain": "UNK-3", - "Asia/Baku": "UNK-4", - "Asia/Bangkok": "UNK-7", - "Asia/Barnaul": "UNK-7", - "Asia/Beirut": "EET-2EEST,M3.5.0/0,M10.5.0/0", - "Asia/Bishkek": "UNK-6", - "Asia/Brunei": "UNK-8", - "Asia/Chita": "UNK-9", - "Asia/Choibalsan": "UNK-8", - "Asia/Colombo": "UNK-5:30", - "Asia/Damascus": "EET-2EEST,M3.5.5/0,M10.5.5/0", - "Asia/Dhaka": "UNK-6", - "Asia/Dili": "UNK-9", - "Asia/Dubai": "UNK-4", - "Asia/Dushanbe": "UNK-5", - "Asia/Famagusta": "EET-2EEST,M3.5.0/3,M10.5.0/4", - "Asia/Gaza": "EET-2EEST,M3.5.5/0,M10.5.6/1", - "Asia/Hebron": "EET-2EEST,M3.5.5/0,M10.5.6/1", - "Asia/Ho_Chi_Minh": "UNK-7", - "Asia/Hong_Kong": "HKT-8", - "Asia/Hovd": "UNK-7", - "Asia/Irkutsk": "UNK-8", - "Asia/Jakarta": "WIB-7", - "Asia/Jayapura": "WIT-9", - "Asia/Jerusalem": "IST-2IDT,M3.4.4/26,M10.5.0", - "Asia/Kabul": "UNK-4:30", - "Asia/Kamchatka": "UNK-12", - "Asia/Karachi": "PKT-5", - "Asia/Kathmandu": "UNK-5:45", - "Asia/Khandyga": "UNK-9", - "Asia/Kolkata": "IST-5:30", - "Asia/Krasnoyarsk": "UNK-7", - "Asia/Kuala_Lumpur": "UNK-8", - "Asia/Kuching": "UNK-8", - "Asia/Kuwait": "UNK-3", - "Asia/Macau": "CST-8", - "Asia/Magadan": "UNK-11", - "Asia/Makassar": "WITA-8", - "Asia/Manila": "PST-8", - "Asia/Muscat": "UNK-4", - "Asia/Nicosia": "EET-2EEST,M3.5.0/3,M10.5.0/4", - "Asia/Novokuznetsk": "UNK-7", - "Asia/Novosibirsk": "UNK-7", - "Asia/Omsk": "UNK-6", - "Asia/Oral": "UNK-5", - "Asia/Phnom_Penh": "UNK-7", - "Asia/Pontianak": "WIB-7", - "Asia/Pyongyang": "KST-9", - "Asia/Qatar": "UNK-3", - "Asia/Qyzylorda": "UNK-5", - "Asia/Riyadh": "UNK-3", - "Asia/Sakhalin": "UNK-11", - "Asia/Samarkand": "UNK-5", - "Asia/Seoul": "KST-9", - "Asia/Shanghai": "CST-8", - "Asia/Singapore": "UNK-8", - "Asia/Srednekolymsk": "UNK-11", - "Asia/Taipei": "CST-8", - "Asia/Tashkent": "UNK-5", - "Asia/Tbilisi": "UNK-4", - "Asia/Tehran": "UNK-3:30UNK,J79/24,J263/24", - "Asia/Thimphu": "UNK-6", - "Asia/Tokyo": "JST-9", - "Asia/Tomsk": "UNK-7", - "Asia/Ulaanbaatar": "UNK-8", - "Asia/Urumqi": "UNK-6", - "Asia/Ust-Nera": "UNK-10", - "Asia/Vientiane": "UNK-7", - "Asia/Vladivostok": "UNK-10", - "Asia/Yakutsk": "UNK-9", - "Asia/Yangon": "UNK-6:30", - "Asia/Yekaterinburg": "UNK-5", - "Asia/Yerevan": "UNK-4", - "Atlantic/Azores": "UNK1UNK,M3.5.0/0,M10.5.0/1", - "Atlantic/Bermuda": "AST4ADT,M3.2.0,M11.1.0", - "Atlantic/Canary": "WET0WEST,M3.5.0/1,M10.5.0", - "Atlantic/Cape_Verde": "UNK1", - "Atlantic/Faroe": "WET0WEST,M3.5.0/1,M10.5.0", - "Atlantic/Madeira": "WET0WEST,M3.5.0/1,M10.5.0", - "Atlantic/Reykjavik": "GMT0", - "Atlantic/South_Georgia": "UNK2", - "Atlantic/St_Helena": "GMT0", - "Atlantic/Stanley": "UNK3", - "Australia/Adelaide": "ACST-9:30ACDT,M10.1.0,M4.1.0/3", - "Australia/Brisbane": "AEST-10", - "Australia/Broken_Hill": "ACST-9:30ACDT,M10.1.0,M4.1.0/3", - "Australia/Currie": "AEST-10AEDT,M10.1.0,M4.1.0/3", - "Australia/Darwin": "ACST-9:30", - "Australia/Eucla": "UNK-8:45", - "Australia/Hobart": "AEST-10AEDT,M10.1.0,M4.1.0/3", - "Australia/Lindeman": "AEST-10", - "Australia/Lord_Howe": "UNK-10:30UNK-11,M10.1.0,M4.1.0", - "Australia/Melbourne": "AEST-10AEDT,M10.1.0,M4.1.0/3", - "Australia/Perth": "AWST-8", - "Australia/Sydney": "AEST-10AEDT,M10.1.0,M4.1.0/3", - "Etc/GMT": "GMT0", - "Etc/GMT+0": "GMT0", - "Etc/GMT+1": "UNK1", - "Etc/GMT+10": "UNK10", - "Etc/GMT+11": "UNK11", - "Etc/GMT+12": "UNK12", - "Etc/GMT+2": "UNK2", - "Etc/GMT+3": "UNK3", - "Etc/GMT+4": "UNK4", - "Etc/GMT+5": "UNK5", - "Etc/GMT+6": "UNK6", - "Etc/GMT+7": "UNK7", - "Etc/GMT+8": "UNK8", - "Etc/GMT+9": "UNK9", - "Etc/GMT-0": "GMT0", - "Etc/GMT-1": "UNK-1", - "Etc/GMT-10": "UNK-10", - "Etc/GMT-11": "UNK-11", - "Etc/GMT-12": "UNK-12", - "Etc/GMT-13": "UNK-13", - "Etc/GMT-14": "UNK-14", - "Etc/GMT-2": "UNK-2", - "Etc/GMT-3": "UNK-3", - "Etc/GMT-4": "UNK-4", - "Etc/GMT-5": "UNK-5", - "Etc/GMT-6": "UNK-6", - "Etc/GMT-7": "UNK-7", - "Etc/GMT-8": "UNK-8", - "Etc/GMT-9": "UNK-9", - "Etc/GMT0": "GMT0", - "Etc/Greenwich": "GMT0", - "Etc/UCT": "UTC0", - "Etc/UTC": "UTC0", - "Etc/Universal": "UTC0", - "Etc/Zulu": "UTC0", - "Europe/Amsterdam": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Andorra": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Astrakhan": "UNK-4", - "Europe/Athens": "EET-2EEST,M3.5.0/3,M10.5.0/4", - "Europe/Belgrade": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Berlin": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Bratislava": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Brussels": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Bucharest": "EET-2EEST,M3.5.0/3,M10.5.0/4", - "Europe/Budapest": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Busingen": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Chisinau": "EET-2EEST,M3.5.0,M10.5.0/3", - "Europe/Copenhagen": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Dublin": "IST-1GMT0,M10.5.0,M3.5.0/1", - "Europe/Gibraltar": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Guernsey": "GMT0BST,M3.5.0/1,M10.5.0", - "Europe/Helsinki": "EET-2EEST,M3.5.0/3,M10.5.0/4", - "Europe/Isle_of_Man": "GMT0BST,M3.5.0/1,M10.5.0", - "Europe/Istanbul": "UNK-3", - "Europe/Jersey": "GMT0BST,M3.5.0/1,M10.5.0", - "Europe/Kaliningrad": "EET-2", - "Europe/Kiev": "EET-2EEST,M3.5.0/3,M10.5.0/4", - "Europe/Kirov": "UNK-3", - "Europe/Lisbon": "WET0WEST,M3.5.0/1,M10.5.0", - "Europe/Ljubljana": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/London": "GMT0BST,M3.5.0/1,M10.5.0", - "Europe/Luxembourg": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Madrid": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Malta": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Mariehamn": "EET-2EEST,M3.5.0/3,M10.5.0/4", - "Europe/Minsk": "UNK-3", - "Europe/Monaco": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Moscow": "MSK-3", - "Europe/Oslo": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Paris": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Podgorica": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Prague": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Riga": "EET-2EEST,M3.5.0/3,M10.5.0/4", - "Europe/Rome": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Samara": "UNK-4", - "Europe/San_Marino": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Sarajevo": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Saratov": "UNK-4", - "Europe/Simferopol": "MSK-3", - "Europe/Skopje": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Sofia": "EET-2EEST,M3.5.0/3,M10.5.0/4", - "Europe/Stockholm": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Tallinn": "EET-2EEST,M3.5.0/3,M10.5.0/4", - "Europe/Tirane": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Ulyanovsk": "UNK-4", - "Europe/Uzhgorod": "EET-2EEST,M3.5.0/3,M10.5.0/4", - "Europe/Vaduz": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Vatican": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Vienna": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Vilnius": "EET-2EEST,M3.5.0/3,M10.5.0/4", - "Europe/Volgograd": "UNK-4", - "Europe/Warsaw": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Zagreb": "CET-1CEST,M3.5.0,M10.5.0/3", - "Europe/Zaporozhye": "EET-2EEST,M3.5.0/3,M10.5.0/4", - "Europe/Zurich": "CET-1CEST,M3.5.0,M10.5.0/3", - "Indian/Antananarivo": "EAT-3", - "Indian/Chagos": "UNK-6", - "Indian/Christmas": "UNK-7", - "Indian/Cocos": "UNK-6:30", - "Indian/Comoro": "EAT-3", - "Indian/Kerguelen": "UNK-5", - "Indian/Mahe": "UNK-4", - "Indian/Maldives": "UNK-5", - "Indian/Mauritius": "UNK-4", - "Indian/Mayotte": "EAT-3", - "Indian/Reunion": "UNK-4", - "Pacific/Apia": "UNK-13UNK,M9.5.0/3,M4.1.0/4", - "Pacific/Auckland": "NZST-12NZDT,M9.5.0,M4.1.0/3", - "Pacific/Bougainville": "UNK-11", - "Pacific/Chatham": "UNK-12:45UNK,M9.5.0/2:45,M4.1.0/3:45", - "Pacific/Chuuk": "UNK-10", - "Pacific/Easter": "UNK6UNK,M9.1.6/22,M4.1.6/22", - "Pacific/Efate": "UNK-11", - "Pacific/Enderbury": "UNK-13", - "Pacific/Fakaofo": "UNK-13", - "Pacific/Fiji": "UNK-12UNK,M11.2.0,M1.2.3/99", - "Pacific/Funafuti": "UNK-12", - "Pacific/Galapagos": "UNK6", - "Pacific/Gambier": "UNK9", - "Pacific/Guadalcanal": "UNK-11", - "Pacific/Guam": "ChST-10", - "Pacific/Honolulu": "HST10", - "Pacific/Kiritimati": "UNK-14", - "Pacific/Kosrae": "UNK-11", - "Pacific/Kwajalein": "UNK-12", - "Pacific/Majuro": "UNK-12", - "Pacific/Marquesas": "UNK9:30", - "Pacific/Midway": "SST11", - "Pacific/Nauru": "UNK-12", - "Pacific/Niue": "UNK11", - "Pacific/Norfolk": "UNK-11UNK,M10.1.0,M4.1.0/3", - "Pacific/Noumea": "UNK-11", - "Pacific/Pago_Pago": "SST11", - "Pacific/Palau": "UNK-9", - "Pacific/Pitcairn": "UNK8", - "Pacific/Pohnpei": "UNK-11", - "Pacific/Port_Moresby": "UNK-10", - "Pacific/Rarotonga": "UNK10", - "Pacific/Saipan": "ChST-10", - "Pacific/Tahiti": "UNK10", - "Pacific/Tarawa": "UNK-12", - "Pacific/Tongatapu": "UNK-13", - "Pacific/Wake": "UNK-12", - "Pacific/Wallis": "UNK-12" - }; diff --git a/app2/src/routes/statusbar.svelte b/app2/src/routes/statusbar.svelte index 4907fb8..d46fa0e 100644 --- a/app2/src/routes/statusbar.svelte +++ b/app2/src/routes/statusbar.svelte @@ -39,7 +39,7 @@ } - @@ -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,16 @@
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 +274,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,15 +289,16 @@
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( - 'en-US' - )} + >({( + (systemInformation.fs_total - systemInformation.fs_used) / + 1000000 + ).toLocaleString('en-US')} MB free)
@@ -332,7 +312,9 @@
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 +326,7 @@
Uptime
- {convertSeconds(systemStatus.uptime)} + {convertSeconds(systemInformation.uptime)}
@@ -356,31 +338,7 @@
Reset Reason
- {systemStatus.cpu_reset_reason} -
-
-
- -
-
- -
-
-
Uptime
-
- {convertSeconds(systemStatus.uptime)} -
-
-
- -
-
- -
-
-
Reset Reason
-
- {systemStatus.cpu_reset_reason} + {systemInformation.cpu_reset_reason}
diff --git a/app2/src/routes/wifi/ap/Accesspoint.svelte b/app2/src/routes/wifi/ap/Accesspoint.svelte index a4b617a..6b11089 100644 --- a/app2/src/routes/wifi/ap/Accesspoint.svelte +++ b/app2/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/app2/src/routes/wifi/sta/Scan.svelte b/app2/src/routes/wifi/sta/Scan.svelte index 722fe0c..469113f 100644 --- a/app2/src/routes/wifi/sta/Scan.svelte +++ b/app2/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; @@ -103,7 +96,7 @@ use:focusTrap >

Scan Networks

diff --git a/app2/src/routes/wifi/sta/Wifi.svelte b/app2/src/routes/wifi/sta/Wifi.svelte index fb27c89..a5542b0 100644 --- a/app2/src/routes/wifi/sta/Wifi.svelte +++ b/app2/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; diff --git a/app2/vite.config.ts b/app2/vite.config.ts index 5c03941..0dfbd5b 100644 --- a/app2/vite.config.ts +++ b/app2/vite.config.ts @@ -17,15 +17,11 @@ export default defineConfig({ server: { proxy: { '/rest': { - target: 'http://192.168.0.130', - changeOrigin: true - }, - '/events': { - target: 'http://192.168.0.130', + target: 'http://192.168.0.172', changeOrigin: true }, '/ws': { - target: 'ws://192.168.0.130', + target: 'ws://192.168.0.172', changeOrigin: true, ws: true }