You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -283,12 +285,11 @@ The framework's source is split up by feature, for example [WiFiScanner.h](lib/f
283
285
284
286
The ['src/main.cpp'](src/main.cpp) file constructs the webserver and initializes the framework. You can add endpoints to the server here to support your IoT project. The main loop is also accessable so you can run your own code easily.
285
287
286
-
The following code creates the web server, esp8266React framework and the demo project instance:
288
+
The following code creates the web serverand esp8266React framework:
Now in the `setup()` function the initialization is performed:
@@ -308,23 +309,17 @@ void setup() {
308
309
// start the framework and demo project
309
310
esp8266React.begin();
310
311
311
-
// start the demo project
312
-
demoProject.begin();
313
-
314
312
// start the server
315
313
server.begin();
316
314
}
317
315
```
318
316
319
-
Finally the loop calls the framework's loop function to service the frameworks features. You can add your own code in here, as shown with the demo project:
317
+
Finally the loop calls the framework's loop function to service the frameworks features.
320
318
321
319
```cpp
322
320
voidloop() {
323
321
// run the framework's loop function
324
322
esp8266React.loop();
325
-
326
-
// run the demo project's loop function
327
-
demoProject.loop();
328
323
}
329
324
```
330
325
@@ -460,94 +455,17 @@ NONE_REQUIRED | No authentication is required.
460
455
IS_AUTHENTICATED | Any authenticated principal is permitted.
461
456
IS_ADMIN | The authenticated principal must be an admin.
462
457
463
-
You can use the security manager to wrap any web handler with an authentication predicate:
458
+
You can use the security manager to wrap any request handler function with an authentication predicate:
Alternatively you can extend [AdminSettingsService.h](lib/framework/AdminSettingsService.h) and optionally override `getAuthenticationPredicate()` to secure an endpoint.
472
-
473
-
## Extending the framework
474
-
475
-
It is recommend that you explore the framework code to gain a better understanding of how to use it's features. The framework provides APIs so you can add your own services or features or, if required, directly configure or observe changes to core framework features. Some of these capabilities are detailed below.
476
-
477
-
### Adding a service with persistant settings
478
-
479
-
The following code demonstrates how you might extend the framework with a feature which requires a username and password to be configured to drive an unspecified feature.
480
-
481
-
```cpp
482
-
#include<SettingsService.h>
483
-
484
-
classExampleSettings {
485
-
public:
486
-
String username;
487
-
String password;
488
-
};
489
-
490
-
class ExampleSettingsService : public SettingsService<ExampleSettings> {
There will now be a REST service exposed on "/exampleSettings" for reading and writing (GET/POST) the settings. Any modifications will be persisted in SPIFFS, in this case to "/config/exampleSettings.json"
523
-
524
-
Sometimes you need to perform an action when the settings are updated, you can achieve this by overriding the onConfigUpdated() function which gets called every time the settings are updated. You can also perform an action when the service starts by overriding the begin() function, being sure to call SettingsService::begin(). You can also provide a "loop" function in order to allow your service class continuously perform an action, calling this from the main loop.
525
-
526
-
```cpp
527
-
528
-
voidbegin() {
529
-
// make sure we call super, so the settings get read!
530
-
SettingsService::begin();
531
-
reconfigureTheService();
532
-
}
533
-
534
-
voidonConfigUpdated() {
535
-
reconfigureTheService();
536
-
}
537
-
538
-
voidreconfigureTheService() {
539
-
// do whatever is required to react to the new settings
540
-
}
541
-
542
-
voidloop() {
543
-
// execute somthing as part of the main loop
544
-
}
545
-
546
-
```
547
-
548
466
### Accessing settings and services
549
467
550
-
The framework supplies access to it's SettingsService instances and the SecurityManager via getter functions:
468
+
The framework supplies access to various features via getter functions:
@@ -557,8 +475,13 @@ getWiFiSettingsService() | Configures and manages the WiFi network connectio
557
475
getAPSettingsService() | Configures and manages the Access Point
558
476
getNTPSettingsService() | Configures and manages the network time
559
477
getOTASettingsService() | Configures and manages the Over-The-Air update feature
478
+
getMQTTSettingsService() | Configures and manages the MQTT connection
479
+
getMQTTClient() | Provides direct access to the MQTT client instance
480
+
481
+
These can be used to observe changes to settings. They can also be used to fetch or update settings.
560
482
561
-
These can be used to observe changes to settings. They can also be used to fetch or update settings directly via objects, JSON strings and JsonObjects. Here are some examples of how you may use this.
0 commit comments