Skip to content

Commit aadc8f2

Browse files
hmbachertheelims
andauthored
Replaced D'n'D component, rework of network settings, enhanced a couple of UI components, some minor fixes (theelims#100)
* first commit * Implement fans configuration feature with UI and backend support * feat: Add sensor management and control functionality - Implemented a new page for managing sensors in the frontend. - Created an EditSensor component for editing sensor details with validation. - Developed ControllerSettingsService to manage controller settings via HTTP endpoints. - Introduced FanController to handle fan control logic based on temperature readings. - Added OneWireESP32 library for interfacing with DS18B20 temperature sensors. - Implemented TempSensorsService to manage temperature sensors and their data acquisition. - Established persistence for sensor settings and states using file storage. - Enhanced error handling and logging throughout the services. * feat: Enhance temperature sensor handling with error tracking and event updates * migrated from ESP32C3 to ESP32S3 * feat: Implement FFC MQTT Configuration and Alarm Logging - Added FFCMqttConfig component for configuring MQTT settings. - Removed GatewayMQTTConfig component to streamline MQTT configuration. - Updated MQTT routing to use FFCMqttConfig. - Introduced new alarms page for managing alarm events. - Created backend services for alarm logging and MQTT settings. - Integrated alarm notifications via MQTT. - Enhanced temperature sensor service to publish alarms on sensor status changes. - Added utility functions for ISO 8601 date conversion. - Updated UI to include alarm log and relevant error handling. * feat: Integrate alarm state management and update alarm handling in UI * feat: Add RPM sensor functionality and integrate with fan controller * feat: Refactor RPM sensor to include alarm service and enhance error handling * feat: Implement sensor discovery functionality and update controller state management * feat: Remove unused icons and configuration files; update logo in UI * feat: Update navigation to settings page and enhance alarm display with ID * feat: Enhance alarm notifications and add fan/temperature monitoring settings * chore: Update TODO file for project organization and future tasks * feat: Add configuration file and update PWM settings for fan control; enhance temperature sensor discovery logging * - Removed obsolete (default) docs - Changed to PCB v2.0 settings - Updated version string * chore: Add initial TODO file with features and known bugs * Reworked network settings * Fixed complier/IDE warnings * Updated pioarduino platfom and switched to explicit versioning * Cleanup up async worker * Update development server configuration and dependencies * Updated SSL cert creation config, updated pipeline scripts * Fixed vite dev server issue * Fixed bug if now handlers are passed * Added coredump * Finalized Wifi Sta settings * Optimized dirty flag for SettingsCard and Collapsible * Delete lib/framework/WWWData.h * Fixed preprocessor directive * Fixed makro redefinition (cherry picked from commit bda977530a219d6f820a7dec7acd86008004d1ef) * Enhanced logo visualization on login page and on main page * Added $src path alias * Added missing page.ts for Core Dump * Changes to prevent Svelte warning 'binding_property_non_reactive' * Fixed PSRAM chart creation * Fixed PSRAM metric * Implemented delayed wifi reconnect, to allow previous POST request to be successfull * Optimized language * Implemented draggable list with svelte-dnd-action # Conflicts: # interface/src/routes/gateway/smoke-detectors/+page.svelte # platformio.ini * Fixed overflow properties # Conflicts: # interface/src/routes/gateway/smoke-detectors/+page.svelte * Fixed Websockets implementation in frontend * Changed drag & drop styling # Conflicts: # interface/src/lib/components/DraggableList.svelte * Fixed re-ordering of Smoke detectors # Conflicts: # interface/src/routes/gateway/smoke-detectors/+page.svelte # src/GatewayDevicesService.cpp * Cleanup up obsolete comments * Show HTML in Info and Confirm dialog * Removed deprecated commands in build script * Enhanced execution of pre-build scripts # Conflicts: # scripts/generate_enums.py * Add print statements to indicate skipped execution for non-build tasks in scripts # Conflicts: # scripts/generate_enums.py * Latest Arduino --------- Co-authored-by: elims <[email protected]>
1 parent 4a1a345 commit aadc8f2

File tree

4 files changed

+58
-15
lines changed

4 files changed

+58
-15
lines changed

SleepService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void SleepService::sleepNow()
8080
ESP_LOGD(SVK_TAG, "Current level on GPIO%d: %d\n", _wakeUpPin, digitalRead(_wakeUpPin));
8181

8282
// special treatment for ESP32-C3 / C6 because of the RISC-V architecture
83-
#ifdef CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6
83+
#if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6)
8484
esp_deep_sleep_enable_gpio_wakeup(BIT(_wakeUpPin), (esp_deepsleep_gpio_wake_up_mode_t)_wakeUpSignal);
8585
#else
8686
esp_sleep_enable_ext1_wakeup(BIT(_wakeUpPin), (esp_sleep_ext1_wakeup_mode_t)_wakeUpSignal);

SystemStatus.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717

1818
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
1919
#include "esp32/rom/rtc.h"
20-
#define ESP_PLATFORM "ESP32";
20+
#define ESP_TARGET "ESP32";
2121
#elif CONFIG_IDF_TARGET_ESP32S2
2222
#include "esp32/rom/rtc.h"
23-
#define ESP_PLATFORM "ESP32-S2";
23+
#define ESP_TARGET "ESP32-S2";
2424
#elif CONFIG_IDF_TARGET_ESP32C3
2525
#include "esp32c3/rom/rtc.h"
26-
#define ESP_PLATFORM "ESP32-C3";
26+
#define ESP_TARGET "ESP32-C3";
2727
#elif CONFIG_IDF_TARGET_ESP32S3
2828
#include "esp32s3/rom/rtc.h"
29-
#define ESP_PLATFORM "ESP32-S3";
29+
#define ESP_TARGET "ESP32-S3";
3030
#elif CONFIG_IDF_TARGET_ESP32C6
3131
#include "esp32c6/rom/rtc.h"
32-
#define ESP_PLATFORM "ESP32-C6";
32+
#define ESP_TARGET "ESP32-C6";
3333
#else
3434
#error Target CONFIG_IDF_TARGET is not supported
3535
#endif
@@ -133,7 +133,7 @@ esp_err_t SystemStatus::systemStatus(PsychicRequest *request)
133133
PsychicJsonResponse response = PsychicJsonResponse(request, false);
134134
JsonObject root = response.getRoot();
135135

136-
root["esp_platform"] = ESP_PLATFORM;
136+
root["esp_platform"] = ESP_TARGET;
137137
root["firmware_version"] = APP_VERSION;
138138
root["max_alloc_heap"] = ESP.getMaxAllocHeap();
139139
if (psramFound())

WiFiSettingsService.cpp

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ WiFiSettingsService::WiFiSettingsService(PsychicHttpServer *server,
2222
_httpEndpoint(WiFiSettings::read, WiFiSettings::update, this, server, WIFI_SETTINGS_SERVICE_PATH, securityManager,
2323
AuthenticationPredicates::IS_ADMIN),
2424
_fsPersistence(WiFiSettings::read, WiFiSettings::update, this, fs, WIFI_SETTINGS_FILE), _lastConnectionAttempt(0),
25+
_delayedReconnectTime(0),
26+
_delayedReconnectPending(false),
2527
_socket(socket)
2628
{
2729
addUpdateHandler([&](const String &originId)
28-
{ reconfigureWiFiConnection(); },
30+
{ delayedReconnect(); },
2931
false);
3032
}
3133

@@ -50,10 +52,24 @@ void WiFiSettingsService::initWiFi()
5052
void WiFiSettingsService::begin()
5153
{
5254
_socket->registerEvent(EVENT_RSSI);
55+
_socket->registerEvent(EVENT_RECONNECT);
5356

5457
_httpEndpoint.begin();
5558
}
5659

60+
void WiFiSettingsService::delayedReconnect()
61+
{
62+
_delayedReconnectTime = millis() + DELAYED_RECONNECT_MS;
63+
_delayedReconnectPending = true;
64+
ESP_LOGI(SVK_TAG, "Delayed WiFi reconnection scheduled in %d ms", DELAYED_RECONNECT_MS);
65+
66+
// Emit event to notify clients of impending reconnection
67+
JsonDocument doc;
68+
doc["delay_ms"] = DELAYED_RECONNECT_MS;
69+
JsonObject jsonObject = doc.as<JsonObject>();
70+
_socket->emitEvent(EVENT_RECONNECT, jsonObject);
71+
}
72+
5773
void WiFiSettingsService::reconfigureWiFiConnection()
5874
{
5975
// reset last connection attempt to force loop to reconnect immediately
@@ -89,6 +105,15 @@ void WiFiSettingsService::reconfigureWiFiConnection()
89105
void WiFiSettingsService::loop()
90106
{
91107
unsigned long currentMillis = millis();
108+
109+
// Handle delayed reconnection
110+
if (_delayedReconnectPending && currentMillis >= _delayedReconnectTime)
111+
{
112+
_delayedReconnectPending = false;
113+
ESP_LOGI(SVK_TAG, "Executing delayed WiFi reconnection");
114+
reconfigureWiFiConnection();
115+
}
116+
92117
if (!_lastConnectionAttempt || (unsigned long)(currentMillis - _lastConnectionAttempt) >= WIFI_RECONNECTION_DELAY)
93118
{
94119
_lastConnectionAttempt = currentMillis;
@@ -195,8 +220,7 @@ void WiFiSettingsService::connectToWiFi()
195220
}
196221
}
197222

198-
// if configured to prioritize signal strength, use the best network else use the first available network
199-
// if (_state.priorityBySignalStrength == false)
223+
// Connection mode PRIORITY: connect to the first available network
200224
if (_state.staConnectionMode == (u_int8_t)STAConnectionMode::PRIORITY)
201225
{
202226
for (auto &network : _state.wifiSettings)
@@ -209,14 +233,28 @@ void WiFiSettingsService::connectToWiFi()
209233
}
210234
}
211235
}
212-
else if (_state.staConnectionMode == (u_int8_t)STAConnectionMode::STRENGTH && bestNetwork)
236+
// Connection mode STRENGTH: connect to the strongest network
237+
else if (_state.staConnectionMode == (u_int8_t)STAConnectionMode::STRENGTH)
238+
{
239+
if (bestNetwork)
240+
{
241+
ESP_LOGI(SVK_TAG, "Connecting to strongest network: %s, BSSID: " MACSTR " ", bestNetwork->ssid.c_str(), MAC2STR(bestNetwork->bssid));
242+
configureNetwork(*bestNetwork);
243+
}
244+
else
245+
{
246+
ESP_LOGI(SVK_TAG, "No suitable network found.");
247+
}
248+
}
249+
// Connection mode OFFLINE: do not connect to any network
250+
else if (_state.staConnectionMode == (u_int8_t)STAConnectionMode::OFFLINE)
213251
{
214-
ESP_LOGI(SVK_TAG, "Connecting to strongest network: %s, BSSID: " MACSTR " ", bestNetwork->ssid.c_str(), MAC2STR(bestNetwork->bssid));
215-
configureNetwork(*bestNetwork);
252+
ESP_LOGI(SVK_TAG, "WiFi connection mode is OFFLINE, not connecting to any network.");
216253
}
217-
else // no suitable network to connect
254+
// Connection mode is unknown: do not connect to any network
255+
else
218256
{
219-
ESP_LOGI(SVK_TAG, "No known networks found.");
257+
ESP_LOGE(SVK_TAG, "Unknown connection mode, not connecting to any network.");
220258
}
221259

222260
// delete scan results

WiFiSettingsService.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@
4848

4949
#define WIFI_RECONNECTION_DELAY 1000 * 30
5050
#define RSSI_EVENT_DELAY 500
51+
#define DELAYED_RECONNECT_MS 5000
5152

5253
#define EVENT_RSSI "rssi"
54+
#define EVENT_RECONNECT "reconnect"
5355

5456
// Struct defining the wifi settings
5557
typedef struct
@@ -215,6 +217,7 @@ class WiFiSettingsService : public StatefulService<WiFiSettings>
215217
void initWiFi();
216218
void begin();
217219
void loop();
220+
void delayedReconnect();
218221
String getHostname();
219222
String getIP();
220223

@@ -226,6 +229,8 @@ class WiFiSettingsService : public StatefulService<WiFiSettings>
226229
EventSocket *_socket;
227230
unsigned long _lastConnectionAttempt;
228231
unsigned long _lastRssiUpdate;
232+
unsigned long _delayedReconnectTime;
233+
bool _delayedReconnectPending;
229234

230235
bool _stopping;
231236
void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info);

0 commit comments

Comments
 (0)