|
NetBurner 3.5.7
PDF Version |
Example Path: examples/Configuration/Application/SystemParams/DisableConfigServer
A NetBurner example application that demonstrates how to enable and disable the web configuration server at runtime using the NNDK_WEB_CONFIG_TOGGLE feature. The web config server (default port 20034) provides a browser-based interface for device configuration. This example shows how to control that server programmatically and persist the setting across reboots.
By default, the NNDK_WEB_CONFIG_TOGGLE feature is disabled in the NNDK. This example uses the overload directory mechanism to enable it, which exposes three API functions for runtime control of the web config server:
DisableWebConfig() - Disables the web config serverEnableWebConfig() - Enables the web config serverIsWebConfigEnabled() - Returns the current enabled/disabled stateThese functions modify a config variable (Sys.DisableWebConfig) but do not automatically save to flash. Call SaveConfigToStorage() to persist the change across reboots.
This example uses the overload directory to enable the NNDK_WEB_CONFIG_TOGGLE feature. The file overload/nbrtos/include/predef-overload.h contains:
The NNDK build system automatically adds the project's overload/ directory to the include path before the system defaults. Since predef.h includes <predef-overload.h>, the project-local version takes precedence over the empty system default, enabling the toggle feature at compile time.
Sys.DisableWebConfig config variable
The NetBurner config server web interface (default port 20034) provides both device configuration and firmware upload capabilities. In some deployments you may want to keep the configuration web page accessible while preventing firmware uploads via /APPUPDATE.HTM.
There is no dedicated toggle for this. Instead, use the NBApproveShutdown() callback to selectively refuse upload requests while leaving the rest of the config server fully functional.
When a firmware upload is submitted through the config server, the system calls NBApproveShutdown(SHUTDOWN_CODEUPDATE) before processing the update. If the function returns false, the upload is refused. The relevant code path in config_server.cpp is:
The NNDK provides a default weak implementation of NBApproveShutdown() that returns true (allowing all shutdowns). By providing your own implementation, you override the default.
Include the shutdown notifications header and define your callback:
This function is called for several shutdown reasons, defined in ShutDownNotifications.h:
| Constant | Value | Meaning |
|---|---|---|
SHUTDOWN_CODEUPDATE | 1 | Firmware upload via config server |
SHUTDOWN_REBOOT | 2 | Device reboot request |
SHUTDOWN_FACTORYREST | 3 | Factory reset request |
By returning false only for SHUTDOWN_CODEUPDATE, you block firmware uploads while allowing all other operations.
With uploads blocked via this method, the config server web page still provides:
SHUTDOWN_REBOOT)You can also make the decision dynamic. For example, allow uploads only when a physical button is held, or only during a maintenance window:
| Approach | Config Web Page | Config Changes | Firmware Uploads |
|---|---|---|---|
DisableWebConfig() | Disabled | Disabled | Disabled |
NBApproveShutdown guard | Active | Active | Blocked |
nbrtos/include/ShutDownNotifications.h - Callback declaration and shutdown reason constantsnbrtos/source/config_server.cpp:1401 - Where NBApproveShutdown is called during uploadsnbrtos/source/config_server.cpp:1298-1300 - Upload refusal handling in AppUpdateDataSink()