diff --git a/WebUI/src/lib/MessageHandlers/Local/index.ts b/WebUI/src/lib/MessageHandlers/Local/index.ts index fdb723fc..9e9d1276 100644 --- a/WebUI/src/lib/MessageHandlers/Local/index.ts +++ b/WebUI/src/lib/MessageHandlers/Local/index.ts @@ -88,7 +88,7 @@ PayloadHandlers[DeviceToLocalMessagePayload.WifiNetworkDiscoveredEvent] = (cli, const bssid = fbsNetwork.bssid(); if (!ssid || !bssid) { - console.warn('[WS] Received invalid network lost event: ', fbsNetwork.ssid(), fbsNetwork.bssid(), fbsNetwork.rssi(), fbsNetwork.channel(), fbsNetwork.authMode(), fbsNetwork.saved()); + console.warn('[WS] Received invalid network lost event'); return; } @@ -101,6 +101,8 @@ PayloadHandlers[DeviceToLocalMessagePayload.WifiNetworkDiscoveredEvent] = (cli, saved: fbsNetwork.saved(), }; + console.log('[WS] Received network discovered event: ', network); + WiFiStateStore.addNetwork(network); }; diff --git a/WebUI/src/lib/components/WiFiList.svelte b/WebUI/src/lib/components/WiFiList.svelte index 3eab0c9d..68c7f2e9 100644 --- a/WebUI/src/lib/components/WiFiList.svelte +++ b/WebUI/src/lib/components/WiFiList.svelte @@ -4,20 +4,31 @@ import type { WiFiNetwork } from '$lib/types/WiFiNetwork'; import { WiFiStateStore } from '$lib/stores'; import { WebSocketClient } from '$lib/WebSocketClient'; + import { Builder as FlatbufferBuilder } from 'flatbuffers'; + import { WifiScanCommand } from '$lib/fbs/open-shock/serialization/local/wifi-scan-command'; + import { LocalToDeviceMessage } from '$lib/fbs/open-shock/serialization/local/local-to-device-message'; + import { LocalToDeviceMessagePayload } from '$lib/fbs/open-shock/serialization/local/local-to-device-message-payload'; + import { WifiAuthMode } from '$lib/fbs/open-shock/wifi-auth-mode'; const modalStore = getModalStore(); let connectedBSSID: string | null = null; function wifiScan() { - if ($WiFiStateStore.scanning) { - WebSocketClient.Instance.Send('{ "type": "wifi", "action": "scan", "run": false }'); - } else { - WebSocketClient.Instance.Send('{ "type": "wifi", "action": "scan", "run": true }'); - } + const fbb = new FlatbufferBuilder(64); + + const cmdOffset = WifiScanCommand.createWifiScanCommand(fbb, !$WiFiStateStore.scanning); + + const payloadOffset = LocalToDeviceMessage.createLocalToDeviceMessage(fbb, LocalToDeviceMessagePayload.WifiScanCommand, cmdOffset); + + fbb.finish(payloadOffset); + + const buf = fbb.asUint8Array(); + + WebSocketClient.Instance.Send(buf); } function wifiAuthenticate(item: WiFiNetwork) { - if (item.security !== 'Open') { + if (item.security !== WifiAuthMode.Open) { modalStore.trigger({ type: 'prompt', title: 'Enter password', @@ -61,27 +72,27 @@
- {#each Object.values($WiFiStateStore.networks) as item (item.bssid)} + {#each $WiFiStateStore.networks as [key, network] (key)}
- {#if item.bssid === connectedBSSID} + {#if network.bssid === connectedBSSID} {:else} {/if} - {#if item.ssid} - {item.ssid} + {#if network.ssid} + {network.ssid} {:else} - {item.bssid}(Hidden) + {network.bssid}(Hidden) {/if}
- {#if item.saved} - + {#if network.saved} + {:else} - + {/if} - +
{/each} diff --git a/WebUI/src/lib/components/modals/WiFiDetails.svelte b/WebUI/src/lib/components/modals/WiFiDetails.svelte index 163ea0aa..fbb83647 100644 --- a/WebUI/src/lib/components/modals/WiFiDetails.svelte +++ b/WebUI/src/lib/components/modals/WiFiDetails.svelte @@ -7,7 +7,7 @@ const modalStore = getModalStore(); - $: item = $WiFiStateStore.networks[bssid]; + $: item = $WiFiStateStore.networks.get(bssid); $: rows = item ? [ diff --git a/src/EventHandlers/WiFiScanEventHandlers.cpp b/src/EventHandlers/WiFiScanEventHandlers.cpp index 780b6be5..eac940ed 100644 --- a/src/EventHandlers/WiFiScanEventHandlers.cpp +++ b/src/EventHandlers/WiFiScanEventHandlers.cpp @@ -45,7 +45,9 @@ void _scanNetworkDiscoveryHandler(const wifi_ap_record_t* record) { auto wifiNetworkOffset = Serialization::Local::CreateWifiNetwork(builder, ssidOffset, bssidOffset, record->rssi, record->primary, authMode, WiFiManager::IsSaved(ssid, record->bssid)); - auto msg = Serialization::Local::CreateDeviceToLocalMessage(builder, Serialization::Local::DeviceToLocalMessagePayload::WifiNetworkDiscoveredEvent, wifiNetworkOffset.Union()); + auto disoveryEventOffset = Serialization::Local::CreateWifiNetworkDiscoveredEvent(builder, wifiNetworkOffset); + + auto msg = Serialization::Local::CreateDeviceToLocalMessage(builder, Serialization::Local::DeviceToLocalMessagePayload::WifiNetworkDiscoveredEvent, disoveryEventOffset.Union()); builder.Finish(msg);