Makes wifi settings you eventsocket

This commit is contained in:
Rune Harlyk
2024-04-23 20:34:16 +02:00
committed by Rune Harlyk
parent fb9d5637be
commit 5609fe35d7
3 changed files with 24 additions and 22 deletions
+6 -8
View File
@@ -33,6 +33,7 @@
import Check from '~icons/tabler/check';
import InfoDialog from '$lib/components/InfoDialog.svelte';
import type { KnownNetworkItem, WifiSettings, WifiStatus } from '$lib/types/models';
import { socket } from '$lib/stores';
let networkEditable: KnownNetworkItem = {
ssid: '',
@@ -101,16 +102,13 @@
return wifiSettings;
}
const interval = setInterval(async () => {
getWifiStatus();
}, 5000);
onDestroy(() => clearInterval(interval));
onDestroy(() => socket.off('WiFiSettings'));
onMount(() => {
if (!$page.data.features.security || $user.admin) {
getWifiSettings();
}
socket.on<WifiSettings>('WiFiSettings', (data) => {
wifiSettings = data
dndNetworkList = wifiSettings.wifi_networks
})
});
async function postWiFiSettings(data: WifiSettings) {
@@ -14,15 +14,15 @@
#include <WiFiSettingsService.h>
WiFiSettingsService::WiFiSettingsService(PsychicHttpServer *server,
FS *fs,
SecurityManager *securityManager,
EventSocket *socket) : _server(server),
_securityManager(securityManager),
_httpEndpoint(WiFiSettings::read, WiFiSettings::update, this, server, WIFI_SETTINGS_SERVICE_PATH, securityManager,
AuthenticationPredicates::IS_ADMIN, WIFI_SETTINGS_BUFFER_SIZE),
_fsPersistence(WiFiSettings::read, WiFiSettings::update, this, fs, WIFI_SETTINGS_FILE), _lastConnectionAttempt(0),
_socket(socket)
WiFiSettingsService::WiFiSettingsService(PsychicHttpServer *server, FS *fs, SecurityManager *securityManager,
EventSocket *socket)
: _server(server), _securityManager(securityManager),
_httpEndpoint(WiFiSettings::read, WiFiSettings::update, this, server, WIFI_SETTINGS_SERVICE_PATH, securityManager,
AuthenticationPredicates::IS_ADMIN, WIFI_SETTINGS_BUFFER_SIZE),
_eventEndpoint(WiFiSettings::read, WiFiSettings::update, this, socket, EVENT_WIFI_SETTINGS,
WIFI_SETTINGS_BUFFER_SIZE),
_fsPersistence(WiFiSettings::read, WiFiSettings::update, this, fs, WIFI_SETTINGS_FILE), _lastConnectionAttempt(0),
_socket(socket)
{
addUpdateHandler([&](const String &originId)
{ reconfigureWiFiConnection(); },
@@ -52,6 +52,7 @@ void WiFiSettingsService::begin()
_socket->registerEvent(EVENT_RSSI);
_httpEndpoint.begin();
_eventEndpoint.begin();
}
void WiFiSettingsService::reconfigureWiFiConnection()
@@ -15,16 +15,17 @@
* the terms of the LGPL v3 license. See the LICENSE file for details.
**/
#include <WiFi.h>
#include <WiFiMulti.h>
#include <SettingValue.h>
#include <StatefulService.h>
#include <EventEndpoint.h>
#include <EventSocket.h>
#include <FSPersistence.h>
#include <HttpEndpoint.h>
#include <JsonUtils.h>
#include <SecurityManager.h>
#include <PsychicHttp.h>
#include <SecurityManager.h>
#include <SettingValue.h>
#include <StatefulService.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <vector>
#ifndef FACTORY_WIFI_SSID
@@ -52,6 +53,7 @@
#define WIFI_SETTINGS_BUFFER_SIZE 2048
#define EVENT_RSSI "rssi"
#define EVENT_WIFI_SETTINGS "WiFiSettings"
// Struct defining the wifi settings
typedef struct
@@ -214,6 +216,7 @@ private:
PsychicHttpServer *_server;
SecurityManager *_securityManager;
HttpEndpoint<WiFiSettings> _httpEndpoint;
EventEndpoint<WiFiSettings> _eventEndpoint;
FSPersistence<WiFiSettings> _fsPersistence;
EventSocket *_socket;
unsigned long _lastConnectionAttempt;