Adds event bus

This commit is contained in:
Rune Harlyk
2026-01-31 22:44:06 +01:00
parent ff1444b2bc
commit 780d178e87
26 changed files with 1127 additions and 243 deletions
+20 -11
View File
@@ -5,18 +5,15 @@
#include <mdns.h>
#include <string>
#include <filesystem.h>
#include <utils/timing.h>
#include <template/stateful_service.h>
#include <template/stateful_persistence_pb.h>
#include <template/stateful_proto_endpoint.h>
#include <event_bus/event_bus.h>
#include <settings/wifi_settings.h>
#include <utils/timing.h>
#define WIFI_EVENT_STA_DISCONNECTED_IDF WIFI_EVENT_STA_DISCONNECTED
#define WIFI_EVENT_STA_STOP_IDF WIFI_EVENT_STA_STOP
#define IP_EVENT_STA_GOT_IP_IDF 1000
class WiFiService : public StatefulService<WiFiSettings> {
class WiFiService {
public:
WiFiService();
~WiFiService();
@@ -27,27 +24,39 @@ class WiFiService : public StatefulService<WiFiSettings> {
void setupMDNS(const char *hostname);
void selectNetwork(uint32_t index);
const char *getHostname() { return state().hostname; }
const char *getHostname() {
static api_WifiSettings cached_settings;
EventBus::peek(cached_settings);
return cached_settings.hostname;
}
static esp_err_t handleScan(httpd_req_t *request);
static esp_err_t getNetworks(httpd_req_t *request);
static esp_err_t getNetworkStatus(httpd_req_t *request);
StatefulProtoEndpoint<WiFiSettings, api_WifiSettings> protoEndpoint;
private:
void onStationModeDisconnected(int32_t event, void *event_data);
void onStationModeStop(int32_t event, void *event_data);
static void onStationModeGotIP(int32_t event, void *event_data);
FSPersistencePB<WiFiSettings> _persistence;
void onSettingsChanged(const api_WifiSettings &newSettings);
void reconfigureWiFiConnection();
void manageSTA();
void configureNetwork(WiFiNetwork &network);
void configureNetwork(const WiFiNetwork &network);
api_WifiSettings getSettings() const {
api_WifiSettings settings;
EventBus::peek(settings);
return settings;
}
EventBus::Handle<api_WifiSettings> _settingsHandle;
bool _initialized;
unsigned long _lastConnectionAttempt;
bool _stopping;
constexpr static uint16_t reconnectDelay {10000};
static constexpr const char *TAG = "WiFiService";
};