Files
MeshCoreTel-firmware/src/helpers/web/WebService.h
T
Valentin V. Bartenev ce510738d5 Web: delay WiFi shutdown and reorder stop logs
This fixes accidental crash when disabling the web panel without an
active MQTT uplink.

When the web panel was disabled, isWebEnabled() immediately returned
false.  If no other network consumer was active, network.loop(false)
tore down WiFi *before* web.loop() stopped the httpd server.

Calling httpd_stop() while WiFi was being freed sometimes caused a
LoadProhibited panic (ieee80211_output_do -> wifi_free).  This only
occurred when the server was stopped after WiFi teardown began.

Fix by including _panel.isRunning() in isWebEnabled(): WiFi stays up
for one extra iteration, so the server is stopped while the stack is
still valid.  Only on the next loop cycle does the network shut down.

Additionally, move the "server stopped" and "redirect server stopped"
log messages to after the actual httpd_stop() / httpd_ssl_stop()
calls.  This prevents a misleading "stopped" message if a crash
happens during teardown.
2026-05-08 20:22:18 +03:00

45 lines
1.1 KiB
C++

#pragma once
#include <Arduino.h>
#include <helpers/IdentityStore.h>
#include <helpers/NetworkStateProvider.h>
#include "WebPanelServer.h"
#include "WebPrefs.h"
class WebService {
public:
WebService();
void begin(FILESYSTEM* fs);
void end();
void loop();
void suspendForOTA();
void prepareForOTAStart();
void setCommandRunner(WebPanelCommandRunner* runner);
void setNetworkStateProvider(NetworkStateProvider* network) { _network = network; }
bool setWebEnabled(bool enabled);
bool isWebEnabled() const { return _prefs.web_enabled != 0 || _panel.isRunning(); }
bool setWebStatsEnabled(bool enabled);
bool isWebStatsEnabled() const { return _prefs.web_stats_enabled != 0; }
void formatWebStatusReply(char* reply, size_t reply_size) const;
bool isPanelRunning() const { return _panel.isRunning(); }
bool isPanelUnlocked() const { return _panel.hasSessionToken(); }
private:
#if defined(ESP_PLATFORM) && WITH_WEB_PANEL
void ensureWebServer();
#endif
bool savePrefs();
FILESYSTEM* _fs;
WebPrefs _prefs;
WebPanelCommandRunner* _runner;
NetworkStateProvider* _network;
WebPanelServer _panel;
bool _suspended_for_ota;
};