Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/theelims/ESP32-sveltekit in…
Browse files Browse the repository at this point in the history
…to main
  • Loading branch information
theelims committed Apr 6, 2024
2 parents b843406 + b2cb6ee commit 2bb2395
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 145 deletions.
32 changes: 20 additions & 12 deletions interface/src/lib/stores/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type Analytics } from '$lib/types/models';
import { writable } from 'svelte/store';

let analytics_data = {
Expand All @@ -11,26 +12,33 @@ let analytics_data = {
core_temp: <number[]>[]
};

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();
113 changes: 113 additions & 0 deletions interface/src/lib/types/models.ts
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 3 additions & 1 deletion interface/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
}
Expand Down
7 changes: 1 addition & 6 deletions interface/src/routes/connections/mqtt/MQTTConfig.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 1 addition & 16 deletions interface/src/routes/connections/ntp/NTP.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions interface/src/routes/demo/Demo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
Loading

0 comments on commit 2bb2395

Please sign in to comment.