Skip to content

Commit

Permalink
Woo Yeah Baby! That's What I've Been Waiting For!
Browse files Browse the repository at this point in the history
Got flatbuffers working :)
  • Loading branch information
hhvrc committed Oct 14, 2023
1 parent da7bee7 commit 7691343
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
4 changes: 3 additions & 1 deletion WebUI/src/lib/MessageHandlers/Local/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -101,6 +101,8 @@ PayloadHandlers[DeviceToLocalMessagePayload.WifiNetworkDiscoveredEvent] = (cli,
saved: fbsNetwork.saved(),
};

console.log('[WS] Received network discovered event: ', network);

WiFiStateStore.addNetwork(network);
};

Expand Down
41 changes: 26 additions & 15 deletions WebUI/src/lib/components/WiFiList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -61,27 +72,27 @@
</button>
</div>
<div class="max-h-64 overflow-auto">
{#each Object.values($WiFiStateStore.networks) as item (item.bssid)}
{#each $WiFiStateStore.networks as [key, network] (key)}
<div class="card mb-2 p-2 flex justify-between items-center">
<span>
{#if item.bssid === connectedBSSID}
{#if network.bssid === connectedBSSID}
<i class="fa fa-wifi text-green-500" />
{:else}
<i class="fa fa-wifi" />
{/if}
{#if item.ssid}
<span class="ml-2">{item.ssid}</span>
{#if network.ssid}
<span class="ml-2">{network.ssid}</span>
{:else}
<span class="ml-2">{item.bssid}</span><span class="text-gray-500 ml-1">(Hidden)</span>
<span class="ml-2">{network.bssid}</span><span class="text-gray-500 ml-1">(Hidden)</span>
{/if}
</span>
<div class="btn-group variant-outline">
{#if item.saved}
<button on:click={() => wifiConnect(item)}><i class="fa fa-arrow-right text-green-500" /></button>
{#if network.saved}
<button on:click={() => wifiConnect(network)}><i class="fa fa-arrow-right text-green-500" /></button>
{:else}
<button on:click={() => wifiAuthenticate(item)}><i class="fa fa-link text-green-500" /></button>
<button on:click={() => wifiAuthenticate(network)}><i class="fa fa-link text-green-500" /></button>
{/if}
<button on:click={() => wifiSettings(item)}><i class="fa fa-cog" /></button>
<button on:click={() => wifiSettings(network)}><i class="fa fa-cog" /></button>
</div>
</div>
{/each}
Expand Down
2 changes: 1 addition & 1 deletion WebUI/src/lib/components/modals/WiFiDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const modalStore = getModalStore();
$: item = $WiFiStateStore.networks[bssid];
$: item = $WiFiStateStore.networks.get(bssid);
$: rows = item
? [
Expand Down
4 changes: 3 additions & 1 deletion src/EventHandlers/WiFiScanEventHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7691343

Please sign in to comment.