Updates rssi

This commit is contained in:
Rune Harlyk
2024-04-29 22:10:57 +02:00
committed by Rune Harlyk
parent a706a377b2
commit f11b4b0c35
4 changed files with 73 additions and 48 deletions
+35 -25
View File
@@ -3,33 +3,43 @@
import WiFi0 from '~icons/tabler/wifi-0';
import WiFi1 from '~icons/tabler/wifi-1';
import WiFi2 from '~icons/tabler/wifi-2';
import WifiOff from '~icons/tabler/wifi-off';
export let showDBm = false;
export let showDBm = true;
export let rssi_dbm = 0;
export let ssid = '';
$: if (ssid === '') {
ssid = 'Unknown';
}
</script>
<div class="indicator">
{#if showDBm}
<span class="indicator-item indicator-start badge badge-accent badge-outline badge-xs">
{rssi_dbm} dBm
</span>
{/if}
{#if rssi_dbm >= -55}
<WiFi class={$$props.class || ''} />
{:else if rssi_dbm >= -75}
<div class="{$$props.class || ''} relative">
<WiFi class="absolute inset-0 h-full w-full opacity-30" />
<WiFi2 class="absolute inset-0 h-full w-full" />
</div>
{:else if rssi_dbm >= -85}
<div class="{$$props.class || ''} relative">
<WiFi class="absolute inset-0 h-full w-full opacity-30" />
<WiFi1 class="absolute inset-0 h-full w-full" />
</div>
{:else}
<div class="{$$props.class || ''} relative">
<WiFi class="absolute inset-0 h-full w-full opacity-30" />
<WiFi0 class="absolute inset-0 h-full w-full" />
</div>
{/if}
</div>
<div class="tooltip tooltip-left" data-tip={ssid}>
{#if showDBm}
<span class="indicator-item indicator-start badge badge-accent badge-outline badge-xs">
{rssi_dbm} dBm
</span>
{/if}
{#if rssi_dbm >= -55}
<WiFi class={$$props.class || ''} />
{:else if rssi_dbm >= -75}
<div class="{$$props.class || ''} relative">
<WiFi class="absolute inset-0 h-full w-full opacity-30" />
<WiFi2 class="absolute inset-0 h-full w-full" />
</div>
{:else if rssi_dbm >= -85}
<div class="{$$props.class || ''} relative">
<WiFi class="absolute inset-0 h-full w-full opacity-30" />
<WiFi1 class="absolute inset-0 h-full w-full" />
</div>
{:else if rssi_dbm === 0}
<WifiOff class={$$props.class || ''} />
{:else}
<div class="{$$props.class || ''} relative">
<WiFi class="absolute inset-0 h-full w-full opacity-30" />
<WiFi0 class="absolute inset-0 h-full w-full" />
</div>
{/if}
</div>
</div>
+12 -18
View File
@@ -1,9 +1,9 @@
import type { Battery, DownloadOTA } from '$lib/types/models';
import { writable } from 'svelte/store';
let telemetry_data = {
rssi: {
rssi: 0,
disconnected: true
rssi: 0
},
battery: {
soc: 100,
@@ -21,28 +21,22 @@ function createTelemetry() {
return {
subscribe,
setRSSI: (data: string) => {
if (!isNaN(Number(data))) {
update((telemetry_data) => ({
...telemetry_data,
rssi: { rssi: Number(data), disconnected: false }
}));
} else {
update((telemetry_data) => ({ ...telemetry_data, rssi: { rssi: 0, disconnected: true } }));
}
},
setBattery: (data: string) => {
const content = JSON.parse(data);
setRSSI: (data: number) => {
update((telemetry_data) => ({
...telemetry_data,
battery: { soc: content.soc, charging: content.charging }
rssi: { rssi: data }
}));
},
setDownloadOTA: (data: string) => {
const content = JSON.parse(data);
setBattery: (data: Battery) => {
update((telemetry_data) => ({
...telemetry_data,
download_ota: { status: content.status, progress: content.progress, error: content.error }
battery: { soc: data.soc, charging: data.charging }
}));
},
setDownloadOTA: (data: DownloadOTA) => {
update((telemetry_data) => ({
...telemetry_data,
download_ota: { status: data.status, progress: data.progress, error: data.error }
}));
}
};
+21
View File
@@ -74,6 +74,22 @@ export type NTPStatus = {
uptime: number;
};
export type RSSI = {
rssi: number;
ssid: string;
};
export type Battery = {
soc: number;
charging: boolean;
};
export type DownloadOTA = {
status: string;
progress: number;
error: string;
};
export type NTPSettings = {
enabled: boolean;
server: string;
@@ -94,6 +110,11 @@ export type Analytics = {
uptime: number;
};
export type Rssi = {
rssi: number;
ssid: string;
};
export type StaticSystemInformation = {
esp_platform: string;
firmware_version: string;
+5 -5
View File
@@ -15,7 +15,7 @@
import Statusbar from './statusbar.svelte';
import Login from './login.svelte';
import { mode, outControllerData, servoAnglesOut, socket } from '$lib/stores';
import type { Analytics } from '$lib/types/models';
import type { Analytics, Battery, DownloadOTA, Rssi } from '$lib/types/models';
export let data: LayoutData;
@@ -87,7 +87,7 @@
const handleClose = () => {
notifications.error('Connection to device lost', 5000);
telemetry.setRSSI('lost');
telemetry.setRSSI(0);
};
const handleError = (data: any) => console.error(data);
@@ -99,11 +99,11 @@
const handleAnalytics = (data: Analytics) => analytics.addData(data);
const handleNetworkStatus = (data: string) => telemetry.setRSSI(data);
const handleNetworkStatus = (data: number) => telemetry.setRSSI(data);
const handleBattery = (data: string) => telemetry.setBattery(data);
const handleBattery = (data: Battery) => telemetry.setBattery(data);
const handleOAT = (data: string) => telemetry.setDownloadOTA(data);
const handleOAT = (data: DownloadOTA) => telemetry.setDownloadOTA(data);
let menuOpen = false;