Makes wifi settings you eventsocket
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
import Check from '~icons/tabler/check';
|
import Check from '~icons/tabler/check';
|
||||||
import InfoDialog from '$lib/components/InfoDialog.svelte';
|
import InfoDialog from '$lib/components/InfoDialog.svelte';
|
||||||
import type { KnownNetworkItem, WifiSettings, WifiStatus } from '$lib/types/models';
|
import type { KnownNetworkItem, WifiSettings, WifiStatus } from '$lib/types/models';
|
||||||
|
import { socket } from '$lib/stores';
|
||||||
|
|
||||||
let networkEditable: KnownNetworkItem = {
|
let networkEditable: KnownNetworkItem = {
|
||||||
ssid: '',
|
ssid: '',
|
||||||
@@ -101,16 +102,13 @@
|
|||||||
return wifiSettings;
|
return wifiSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
const interval = setInterval(async () => {
|
onDestroy(() => socket.off('WiFiSettings'));
|
||||||
getWifiStatus();
|
|
||||||
}, 5000);
|
|
||||||
|
|
||||||
onDestroy(() => clearInterval(interval));
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!$page.data.features.security || $user.admin) {
|
socket.on<WifiSettings>('WiFiSettings', (data) => {
|
||||||
getWifiSettings();
|
wifiSettings = data
|
||||||
}
|
dndNetworkList = wifiSettings.wifi_networks
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
async function postWiFiSettings(data: WifiSettings) {
|
async function postWiFiSettings(data: WifiSettings) {
|
||||||
|
|||||||
@@ -14,13 +14,13 @@
|
|||||||
|
|
||||||
#include <WiFiSettingsService.h>
|
#include <WiFiSettingsService.h>
|
||||||
|
|
||||||
WiFiSettingsService::WiFiSettingsService(PsychicHttpServer *server,
|
WiFiSettingsService::WiFiSettingsService(PsychicHttpServer *server, FS *fs, SecurityManager *securityManager,
|
||||||
FS *fs,
|
EventSocket *socket)
|
||||||
SecurityManager *securityManager,
|
: _server(server), _securityManager(securityManager),
|
||||||
EventSocket *socket) : _server(server),
|
|
||||||
_securityManager(securityManager),
|
|
||||||
_httpEndpoint(WiFiSettings::read, WiFiSettings::update, this, server, WIFI_SETTINGS_SERVICE_PATH, securityManager,
|
_httpEndpoint(WiFiSettings::read, WiFiSettings::update, this, server, WIFI_SETTINGS_SERVICE_PATH, securityManager,
|
||||||
AuthenticationPredicates::IS_ADMIN, WIFI_SETTINGS_BUFFER_SIZE),
|
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),
|
_fsPersistence(WiFiSettings::read, WiFiSettings::update, this, fs, WIFI_SETTINGS_FILE), _lastConnectionAttempt(0),
|
||||||
_socket(socket)
|
_socket(socket)
|
||||||
{
|
{
|
||||||
@@ -52,6 +52,7 @@ void WiFiSettingsService::begin()
|
|||||||
_socket->registerEvent(EVENT_RSSI);
|
_socket->registerEvent(EVENT_RSSI);
|
||||||
|
|
||||||
_httpEndpoint.begin();
|
_httpEndpoint.begin();
|
||||||
|
_eventEndpoint.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WiFiSettingsService::reconfigureWiFiConnection()
|
void WiFiSettingsService::reconfigureWiFiConnection()
|
||||||
|
|||||||
@@ -15,16 +15,17 @@
|
|||||||
* the terms of the LGPL v3 license. See the LICENSE file for details.
|
* the terms of the LGPL v3 license. See the LICENSE file for details.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#include <WiFi.h>
|
#include <EventEndpoint.h>
|
||||||
#include <WiFiMulti.h>
|
|
||||||
#include <SettingValue.h>
|
|
||||||
#include <StatefulService.h>
|
|
||||||
#include <EventSocket.h>
|
#include <EventSocket.h>
|
||||||
#include <FSPersistence.h>
|
#include <FSPersistence.h>
|
||||||
#include <HttpEndpoint.h>
|
#include <HttpEndpoint.h>
|
||||||
#include <JsonUtils.h>
|
#include <JsonUtils.h>
|
||||||
#include <SecurityManager.h>
|
|
||||||
#include <PsychicHttp.h>
|
#include <PsychicHttp.h>
|
||||||
|
#include <SecurityManager.h>
|
||||||
|
#include <SettingValue.h>
|
||||||
|
#include <StatefulService.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <WiFiMulti.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifndef FACTORY_WIFI_SSID
|
#ifndef FACTORY_WIFI_SSID
|
||||||
@@ -52,6 +53,7 @@
|
|||||||
#define WIFI_SETTINGS_BUFFER_SIZE 2048
|
#define WIFI_SETTINGS_BUFFER_SIZE 2048
|
||||||
|
|
||||||
#define EVENT_RSSI "rssi"
|
#define EVENT_RSSI "rssi"
|
||||||
|
#define EVENT_WIFI_SETTINGS "WiFiSettings"
|
||||||
|
|
||||||
// Struct defining the wifi settings
|
// Struct defining the wifi settings
|
||||||
typedef struct
|
typedef struct
|
||||||
@@ -214,6 +216,7 @@ private:
|
|||||||
PsychicHttpServer *_server;
|
PsychicHttpServer *_server;
|
||||||
SecurityManager *_securityManager;
|
SecurityManager *_securityManager;
|
||||||
HttpEndpoint<WiFiSettings> _httpEndpoint;
|
HttpEndpoint<WiFiSettings> _httpEndpoint;
|
||||||
|
EventEndpoint<WiFiSettings> _eventEndpoint;
|
||||||
FSPersistence<WiFiSettings> _fsPersistence;
|
FSPersistence<WiFiSettings> _fsPersistence;
|
||||||
EventSocket *_socket;
|
EventSocket *_socket;
|
||||||
unsigned long _lastConnectionAttempt;
|
unsigned long _lastConnectionAttempt;
|
||||||
|
|||||||
Reference in New Issue
Block a user