Skip to content

Commit

Permalink
Adds option to enable/disable WebGui
Browse files Browse the repository at this point in the history
Adds option to manage WebGUI availability independent from the WebSocket
server. It should prevent issues like #4 by clarifying that filesystem
image is required both in appropriate macros and in readme
  • Loading branch information
Abász committed Sep 1, 2023
1 parent ca9a4ea commit 8d30459
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
4 changes: 4 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ enum class BleServiceFlag : unsigned char

Enables or disables WebSocket monitor. For more details please refer to the [Wi-Fi](#wi-fi-and-websocket-monitor) section. Default is true.

### ENABLE_WEBGUI

Enables or disables the WebGUI. ESP Rowing Monitor is capable os serving a WebGUI that communicates to the monitor via WebSocket. It requires `ENABLE_WEBSOCKET_MONITOR` to be true. Furthermore a filesystem image with the static resources is required. The WebGUI can be found under a separate repository [ESP Rowing Monitor WEbGUI](https://github.com/Abasz/ESPRowingMonitor-WebGUI), please refer to the [Build/Install](https://github.com/Abasz/ESPRowingMonitor-WebGUI#buildinstall) section. Default is false.

### ENABLE_BLE_SERVICE

Enables or disables the BLE service to broadcast data. Default is true.
Expand Down
19 changes: 11 additions & 8 deletions src/peripherals/network.service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ void NetworkService::update()

server.addHandler(&webSocket);

if (LittleFS.begin())
if constexpr (Configurations::isWebGUIEnabled)
{
Log.traceln("Serving up static Web GUI page");
auto const lastModified = LittleFS.open("/www/index.html").getLastWrite();
string formattedDate = "Thu, 01 Jan 1970 00:00:00 GMT";
std::strftime(formattedDate.data(), 29, "%a, %d %b %Y %H:%M:%S GMT", std::localtime(&lastModified));
server.serveStatic("/", LittleFS, "/www/")
.setLastModified(formattedDate.c_str())
.setDefaultFile("index.html");
if (LittleFS.begin())
{
Log.traceln("Serving up static Web GUI page");
auto const lastModified = LittleFS.open("/www/index.html").getLastWrite();
string formattedDate = "Thu, 01 Jan 1970 00:00:00 GMT";
std::strftime(formattedDate.data(), 29, "%a, %d %b %Y %H:%M:%S GMT", std::localtime(&lastModified));
server.serveStatic("/", LittleFS, "/www/")
.setLastModified(formattedDate.c_str())
.setDefaultFile("index.html");
}
}
server.begin();
isWifiConnected = true;
Expand Down
1 change: 1 addition & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define DEFAULT_CPS_LOGGING_LEVEL ArduinoLogLevel::LogLevelTrace
#define DEFAULT_BLE_SERVICE BleServiceFlag::CpsService
#define ENABLE_WEBSOCKET_MONITOR true
#define ENABLE_WEBGUI false
#define ENABLE_BLE_SERVICE true
#define DEVICE_NAME Concept2

Expand Down
1 change: 1 addition & 0 deletions src/utils/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Configurations
static inline string const passphrase = TOSTRING(PASSPHRASE);
static unsigned char const port = PORT;
static bool const isWebsocketEnabled = ENABLE_WEBSOCKET_MONITOR;
static bool const isWebGUIEnabled = ENABLE_WEBGUI;

// Device power management settings
static gpio_num_t const batteryPinNumber = BATTERY_PIN_NUMBER;
Expand Down
15 changes: 13 additions & 2 deletions src/utils/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,21 @@
#if IMPULSE_DATA_ARRAY_LENGTH >= 18
#error "Using too many data points will increase loop execution time. It should not be more than 17"
#endif
#if (!defined(LOCAL_SSID) || !defined(PASSPHRASE))

#if (ENABLE_WEBGUI == true && ENABLE_WEBSOCKET_MONITOR == false)
#undef ENABLE_WEBSOCKET_MONITOR
#define ENABLE_WEBSOCKET_MONITOR true
#warning "WebGui requires WebSocket, so enabling it"
#endif
#if ((!defined(LOCAL_SSID) || !defined(PASSPHRASE)) && (ENABLE_WEBGUI == true || ENABLE_WEBSOCKET_MONITOR == true))
#undef ENABLE_WEBSOCKET_MONITOR
#define ENABLE_WEBSOCKET_MONITOR false
#warning "Not provided SSID and/or Passphrase, disabling WebSocket monitor"
#undef ENABLE_WEBGUI
#define ENABLE_WEBGUI false
#warning "Not provided SSID and/or Passphrase, disabling WebSocket monitor and WebGUI"
#endif
#if (ENABLE_WEBGUI == true)
#warning "WebGUI is enabled, so a filesystem image needs to be uploaded, please refer to the docs: https://github.com/Abasz/ESPRowingMonitor/blob/master/docs/settings.md#enable_webgui"
#endif

#if IMPULSE_DATA_ARRAY_LENGTH < 12
Expand Down
1 change: 1 addition & 0 deletions test/unit/test-settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define DEFAULT_CPS_LOGGING_LEVEL ArduinoLogLevel::LogLevelTrace
#define DEFAULT_BLE_SERVICE BleServiceFlag::CpsService
#define ENABLE_WEBSOCKET_MONITOR true
#define ENABLE_WEBGUI false
#define ENABLE_BLE_SERVICE true

// Hardware settings
Expand Down

0 comments on commit 8d30459

Please sign in to comment.