Skip to content

Commit 449d3c9

Browse files
authored
Allow features to be disabled at build time (#143)
* Add framework for built-time feature selection * Allow MQTT, NTP, OTA features to be disabled at build time * Allow Project screens to be disabled at build time * Allow security features to be disabled at build time * Switch to std::function for StatefulService function aliases for greater flexibility * Bump various UI lib versions * Update docs
1 parent 88748ac commit 449d3c9

36 files changed

+795
-188
lines changed

README.md

+29-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build Status](https://travis-ci.org/rjwats/esp8266-react.svg?branch=master)](https://travis-ci.org/rjwats/esp8266-react)
44

5-
A simple, secure and extensible framework for IoT projects built on ESP8266/ESP32 platforms with responsive React front-end.
5+
A simple, secure and extensible framework for IoT projects built on ESP8266/ESP32 platforms with responsive [React](https://reactjs.org/) front-end built with [Material-UI](https://material-ui.com/).
66

77
Designed to work with the PlatformIO IDE with [limited setup](#getting-started). Please read below for setup, build and upload instructions.
88

@@ -19,9 +19,7 @@ Provides many of the features required for IoT projects:
1919
* Remote Firmware Updates - Enable secured OTA updates
2020
* Security - Protected RESTful endpoints and a secured user interface
2121

22-
The back end is provided by a set of RESTful endpoints and the responsive React based front end is built using [Material-UI](https://material-ui.com/).
23-
24-
The front end has the prerequisite manifest file and icon, so it can be added to the home screen of a mobile device if required.
22+
Features may be [enabled or disabled](#selecting-features) as required at compile time.
2523

2624
## Getting Started
2725

@@ -139,7 +137,7 @@ REACT_APP_HTTP_ROOT=http://192.168.0.99
139137
REACT_APP_WEB_SOCKET_ROOT=ws://192.168.0.99
140138
```
141139

142-
The `REACT_APP_HTTP_ROOT` and `REACT_APP_WEB_SOCKET_ROOT` properties can be modified to point a ESP device running the back end firmware.
140+
The `REACT_APP_HTTP_ROOT` and `REACT_APP_WEB_SOCKET_ROOT` properties can be modified to point a ESP device running the back end.
143141

144142
> **Tip**: You must restart the development server for changes to the environment file to come into effect.
145143
@@ -152,9 +150,31 @@ You can enable CORS on the back end by uncommenting the -D ENABLE_CORS build fla
152150
-D CORS_ORIGIN=\"http://localhost:3000\"
153151
```
154152

153+
## Selecting features
154+
155+
Many of the framework's built in features may be enabled or disabled as required at compile time. This can help save sketch space and memory if your project does not require the full suite of features. The access point and WiFi management features are "core features" and are always enabled. Feature selection may be controlled with the build flags defined in [features.ini](features.ini).
156+
157+
Customize the settings as you see fit. A value of 0 will disable the specified feature:
158+
159+
```ini
160+
-D FT_PROJECT=1
161+
-D FT_SECURITY=1
162+
-D FT_MQTT=1
163+
-D FT_NTP=1
164+
-D FT_OTA=1
165+
```
166+
167+
Flag | Description
168+
------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------
169+
FT_PROJECT | Controls whether the "project" section of the UI is enabled. Disable this if you don't intend to have your own screens in the UI.
170+
FT_SECURITY | Controls whether the [security features](#security-features) are enabled. Disabling this means you won't need to authenticate to access the device and all authentication predicates will be bypassed.
171+
FT_MQTT | Controls whether the MQTT features are enabled. Disable this if your project does not require MQTT support.
172+
FT_NTP | Controls whether network time protocol synchronization features are enabled. Disable this if your project does not require accurate time.
173+
FT_OTA | Controls whether OTA update support is enabled. Disable this if you won't be using the remote update feature.
174+
155175
## Factory settings
156176

157-
The firmware has built-in factory settings which act as default values for the various configurable services where settings are not saved on the file system. These settings can be overridden using the build flags defined in [factory_settings.ini](factory_settings.ini).
177+
The framework has built-in factory settings which act as default values for the various configurable services where settings are not saved on the file system. These settings can be overridden using the build flags defined in [factory_settings.ini](factory_settings.ini).
158178

159179
Customize the settings as you see fit, for example you might configure your home WiFi network as the factory default:
160180

@@ -193,7 +213,7 @@ Changing factory time zone setting is a common requirement. This requires a litt
193213

194214
### Device ID factory defaults
195215

196-
If not overridden with a build flag, the firmware will use the device ID to generate factory defaults for settings such as the JWT secret and MQTT client ID.
216+
If not overridden with a build flag, the framework will use the device ID to generate factory defaults for settings such as the JWT secret and MQTT client ID.
197217

198218
> **Tip**: Random values are generally better defaults for these settings, so it is recommended you leave these flags undefined.
199219
@@ -481,7 +501,7 @@ class LightStateService : public StatefulService<LightState> {
481501
};
482502
```
483503

484-
Endpoint security is provided by authentication predicates which are [documented below](#security-features). The SecurityManager and authentication predicate may be provided if a secure endpoint is required. The demo project shows how endpoints can be secured.
504+
Endpoint security is provided by authentication predicates which are [documented below](#security-features). The SecurityManager and authentication predicate may be provided if a secure endpoint is required. The placeholder project shows how endpoints can be secured.
485505

486506
#### Persistence
487507

@@ -519,7 +539,7 @@ class LightStateService : public StatefulService<LightState> {
519539
};
520540
```
521541

522-
WebSocket security is provided by authentication predicates which are [documented below](#security-features). The SecurityManager and authentication predicate may be provided if a secure WebSocket is required. The demo project shows how WebSockets can be secured.
542+
WebSocket security is provided by authentication predicates which are [documented below](#security-features). The SecurityManager and authentication predicate may be provided if a secure WebSocket is required. The placeholder project shows how WebSockets can be secured.
523543

524544
#### MQTT
525545

features.ini

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[features]
2+
build_flags =
3+
-D FT_PROJECT=1
4+
-D FT_SECURITY=1
5+
-D FT_MQTT=1
6+
-D FT_NTP=1
7+
-D FT_OTA=1

interface/.env.development

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Change the IP address to that of your ESP device to enable local development of the UI.
22
# Remember to also enable CORS in platformio.ini before uploading the code to the device.
3-
REACT_APP_HTTP_ROOT=http://192.168.0.99
4-
REACT_APP_WEB_SOCKET_ROOT=ws://192.168.0.99
3+
REACT_APP_HTTP_ROOT=http://192.168.0.88
4+
REACT_APP_WEB_SOCKET_ROOT=ws://192.168.0.88

interface/package-lock.json

+178-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)