Doxygen with github
|
A component thet implements web-based configuration portal accessible from local network. More...
#include <ksDevicePortal.h>
Public Member Functions | |
virtual const size_t | getInstanceType () const |
Retrieves type ID of the object. | |
virtual bool | isA (const size_t id) const |
Checks whether object is of given type. | |
ksDevicePortal () | |
Constructs the Device Portal component. | |
ksDevicePortal (std::string portalPassword) | |
Constructs the Device Portal component with custom password. | |
bool | init (ksApplication *app) override |
Initializes the device portal component. | |
bool | postInit (ksApplication *app) override |
Post-initializes the device portal component. | |
bool | loop (ksApplication *app) override |
Handles core logic of the device portal component. | |
virtual | ~ksDevicePortal () |
Destructs the Device Portal component. | |
Public Member Functions inherited from ksf::ksComponent | |
Public Member Functions inherited from ksf::ksRtti | |
template<typename TType > | |
TType * | as () |
Tries to cast object to the type provided as a template parameter. | |
template<typename TType > | |
const TType * | as () const |
Tries to cast object to the type provided as a template parameter (const version). | |
Static Public Member Functions | |
static const size_t | getClassType () |
Static Public Member Functions inherited from ksf::ksComponent | |
static const size_t | getClassType () |
Public Attributes | |
std::shared_ptr< ksf::evt::ksEvent<> > | onUpdateStart {std::make_shared<ksf::evt::ksEvent<>>()} |
std::shared_ptr< ksf::evt::ksEvent<> > | onUpdateEnd {std::make_shared<ksf::evt::ksEvent<>>()} |
std::shared_ptr< ksf::evt::ksEvent< const std::string_view &, bool &, std::string & > > | onHandlePortalCommand {std::make_shared<ksf::evt::ksEvent<const std::string_view&, bool&, std::string&>>()} |
Protected Member Functions | |
void | requestAppBreak () |
Causes the application exit (and ksAppRotator to spawn and process next defined application). | |
void | triggerFactoryReset () |
Triggers factory reset (erase config and reboot). | |
void | setupHttpServer () |
Starts device portal HTTP server. | |
void | setupWsServer () |
Starts device portal WebSocket server. | |
void | updateFinished (bool fromPortal) |
Implements post-OTA update actions. | |
void | rebootDevice () |
Reboots the device. | |
bool | inRequest_NeedAuthentication () |
Checks if current HTTP request requires authentication. | |
void | onRequest_notFound () const |
HTTP handler for 404 "not found" endpoint. | |
void | onRequest_index () |
HTTP handler for index endpoint. | |
void | onRequest_otaChunk () |
HTTP handler for OTA chunk endpoint. | |
void | onRequest_otaFinish () |
HTTP handler for OTA finish endpoint. | |
void | onWebsocketTextMessage (uint8_t clientNum, const std::string_view &message) |
Handles websocket text message. | |
void | handle_scanNetworks (std::string &response) |
Websocket handler for network scan endpoint. | |
void | handle_getIdentity (std::string &response) |
Websocket handler for identity endpoint (device details). | |
void | handle_getDeviceParams (std::string &response) |
Websocket handler for device parameters endpoint. | |
std::string | handle_executeCommand (const std::string_view &body) |
Websocket handler for user commands endpoint. | |
void | onAppLog (std::string &&message) |
Broadcasts application log message to all connected Websocket clients. | |
Protected Attributes | ||
ksf::ksApplication * | app {nullptr} | |
Application pointer. | ||
struct { | ||
bool breakApp: 1 | ||
Flag to break app logic. | ||
} | bitflags = {false} | |
uint32_t | logKeepAliveTimestamp {0} | |
Flag indicating whether logs are enabled. | ||
uint32_t | lastLoopExecutionTimestamp {0} | |
Time of last loop execution (us)/. | ||
uint32_t | loopExecutionTime {0} | |
Diff (loop exec time). | ||
uint32_t | scanNetworkTimestamp {0} | |
Timestamp of last scan. | ||
std::string | portalPassword | |
Portal password. | ||
std::weak_ptr< ksMqttConnector > | mqttConnectorWp | |
MQTT connector. | ||
std::unique_ptr< WebServerClass > | webServer | |
HTTP server. | ||
std::unique_ptr< misc::ksWSServer > | webSocket | |
Web socket server. | ||
std::unique_ptr< DNSServer > | dnsServer | |
DNS server. | ||
std::unique_ptr< ArduinoOTAClass > | arduinoOTA | |
Arduino OTA object. | ||
Protected Attributes inherited from ksf::ksComponent | ||
ksComponentState::TYPE | componentState { ksComponentState::NotInitialized } | |
A component thet implements web-based configuration portal accessible from local network.
The portal can be used to upload OTA update, both in access point and station mode. There's also web-based terminal which can be used to debug the device and examine realitme application logs.
In case of confiugrator application, please don't add this component directly and use ksWifiConfigurator instead. In case of "normal application", you have to add the component manually if you want to use it.
ksf::comps::ksDevicePortal::ksDevicePortal | ( | ) |
Constructs the Device Portal component.
Uses the default password "ota_ksiotframework"
ksf::comps::ksDevicePortal::ksDevicePortal | ( | std::string | portalPassword | ) |
Constructs the Device Portal component with custom password.
password | Password used to authenticate the user. |
References arduinoOTA, ksf::evt::ksEvent< Params >::broadcast(), onUpdateStart, and updateFinished().
|
inlinevirtual |
|
protected |
Websocket handler for user commands endpoint.
body | Command string from the browser. |
References ksf::evt::ksEvent< Params >::broadcast(), onHandlePortalCommand, rebootDevice(), and triggerFactoryReset().
Referenced by onWebsocketTextMessage().
|
protected |
Websocket handler for device parameters endpoint.
response | Response reference . This method will output device configuration parameters into this string. |
References app, and ksf::ksApplication::findComponents().
Referenced by onWebsocketTextMessage().
|
protected |
Websocket handler for identity endpoint (device details).
response | Response reference. This method will output device details in JSON format into this string. |
References loopExecutionTime, and mqttConnectorWp.
Referenced by onWebsocketTextMessage().
|
protected |
Websocket handler for network scan endpoint.
response | Response reference. This method will output network scan results in JSON format into this string. |
References scanNetworkTimestamp.
Referenced by onWebsocketTextMessage().
|
overridevirtual |
Initializes the device portal component.
app | Pointer to the parent ksApplication. |
Reimplemented from ksf::ksComponent.
References app, and arduinoOTA.
|
inlinevirtual |
Checks whether object is of given type.
id | Type ID to check against. |
Reimplemented from ksf::ksComponent.
|
overridevirtual |
Handles core logic of the device portal component.
app | Pointer to the parent ksApplication. |
Reimplemented from ksf::ksComponent.
References app, arduinoOTA, dnsServer, lastLoopExecutionTimestamp, logKeepAliveTimestamp, loopExecutionTime, scanNetworkTimestamp, webServer, and webSocket.
|
protected |
Broadcasts application log message to all connected Websocket clients.
message | R-value reference of the message to broadcast. |
References webSocket.
Referenced by onWebsocketTextMessage().
|
protected |
HTTP handler for index endpoint.
Called when the browser requests "/" endpoint. This is the default endpoint.
References inRequest_NeedAuthentication(), webServer, and webSocket.
Referenced by setupHttpServer().
|
protected |
HTTP handler for 404 "not found" endpoint.
Called when the browser requests an endpoint that doesn't exist.
References webServer.
Referenced by setupHttpServer().
|
protected |
HTTP handler for OTA chunk endpoint.
Called when the browser requests "/api/flash" endpoint with next firmware upload part. Used also to notify the browser about firmware uplaod progress.
References ksf::evt::ksEvent< Params >::broadcast(), inRequest_NeedAuthentication(), onUpdateStart, and webServer.
Referenced by setupHttpServer().
|
protected |
HTTP handler for OTA finish endpoint.
Called when the browser requests "/api/flash" endpoint and the upload is complete. Used also to tell the browser that the upload is complete (or failed).
References inRequest_NeedAuthentication(), rebootDevice(), updateFinished(), and webServer.
Referenced by setupHttpServer().
|
protected |
Handles websocket text message.
clientNum | Number of Websocket client (used as ID to know who's the sender). |
message | String view of the message content. |
References app, ksf::ksApplication::findComponents(), handle_executeCommand(), handle_getDeviceParams(), handle_getIdentity(), handle_scanNetworks(), logKeepAliveTimestamp, onAppLog(), requestAppBreak(), triggerFactoryReset(), and webSocket.
Referenced by setupWsServer().
|
overridevirtual |
Post-initializes the device portal component.
app | Pointer to the parent ksApplication. |
Reimplemented from ksf::ksComponent.
References app, dnsServer, ksf::ksApplication::findComponent(), mqttConnectorWp, setupHttpServer(), and setupWsServer().
std::shared_ptr<ksf::evt::ksEvent<const std::string_view&, bool&, std::string&> > ksf::comps::ksDevicePortal::onHandlePortalCommand {std::make_shared<ksf::evt::ksEvent<const std::string_view&, bool&, std::string&>>()} |
Custom command handler event.
param_1 | String view of the command coming from the browser. |
param_2 | Reference of boolean value indicating if the command was handled. Set to true to stop further processing and return response. |
param_3 | Reference of the string containing the command response. Append results here. |
Referenced by handle_executeCommand().
std::shared_ptr<ksf::evt::ksEvent<> > ksf::comps::ksDevicePortal::onUpdateEnd {std::make_shared<ksf::evt::ksEvent<>>()} |
Update end (OTA) event. No parameters.
Referenced by updateFinished().
std::shared_ptr<ksf::evt::ksEvent<> > ksf::comps::ksDevicePortal::onUpdateStart {std::make_shared<ksf::evt::ksEvent<>>()} |
Update start (OTA) event. No parameters.
Referenced by ksDevicePortal(), and onRequest_otaChunk().