Doxygen with github
|
A component that periodically reports the device state to the broker. More...
#include <ksDevStatMqttReporter.h>
Public Member Functions | |
virtual const std::size_t | getInstanceType () const |
Retrieves type ID of the object. | |
virtual bool | isA (const std::size_t id) const |
Checks whether object is of given type. | |
ksDevStatMqttReporter (uint8_t intervalInSeconds=60) | |
Constructs device statistics reporter component. | |
bool | postInit (ksApplication *app) override |
Handles component post-initialization. | |
bool | loop (ksApplication *app) override |
Handles MQTT debug connector component loop logic. | |
![]() | |
virtual bool | init (ksApplication *app) |
Initializes component. | |
![]() | |
virtual | ~ksRtti ()=default |
Destructor. | |
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 std::size_t | getClassType () |
![]() | |
static const std::size_t | getClassType () |
Public Attributes | |
std::shared_ptr< ksf::evt::ksEvent< std::shared_ptr< ksMqttConnector > & > > | onReportCustomStats {std::make_shared<ksf::evt::ksEvent<std::shared_ptr<ksMqttConnector>&>>()} |
Called when Dev Stat Reporter timer is triggered. Users can bind to this event to add their own stats. | |
Protected Member Functions | |
void | onConnected () |
Calback executed on MQTT connection. | |
void | reportDevStats () const |
Reports device statistics to the MQTT broker. | |
Protected Attributes | |
std::weak_ptr< ksMqttConnector > | mqttConnWp |
Weak pointer to MQTT connector. | |
std::unique_ptr< evt::ksEventHandle > | connEventHandle |
Event handle for connection delegate. | |
misc::ksSimpleTimer | reporterTimer |
Timer to report device stats. | |
![]() | |
ksComponentState::TYPE | componentState { ksComponentState::NotInitialized } |
Holds current state of the component. | |
A component that periodically reports the device state to the broker.
Upon instantiation, the component searches for the ksMqttConnector component. The update interval is specified as a construction parameter.
Each update includes values such as RSSI, device uptime, connection time, and IP address. The subtopic used is "dstat," so, for example, RSSI is published to the topic "deviceprefix/dstat/rssi".
ksf::comps::ksDevStatMqttReporter::ksDevStatMqttReporter | ( | uint8_t | intervalInSeconds = 60 | ) |
Constructs device statistics reporter component.
intervalInSeconds | Interval in seconds between each report. |
|
inlinevirtual |
|
inlinevirtual |
Checks whether object is of given type.
id | Type ID to check against. |
Reimplemented from ksf::ksComponent.
|
overridevirtual |
Handles MQTT debug connector component loop logic.
app | Pointer to the parent ksApplication. |
Reimplemented from ksf::ksComponent.
References reportDevStats(), reporterTimer, and ksf::misc::ksSimpleTimer::triggered().
|
protected |
Calback executed on MQTT connection.
This callback is used to restart reporter timer to match the intervals between individual reports. The timer will be processed even if the MQTT is not connected, but reportDevStats will quickly return.
References reporterTimer, and ksf::misc::ksSimpleTimer::restart().
Referenced by postInit().
|
overridevirtual |
Handles component post-initialization.
This method is responsible for reference gathering (component lookup) as well as binding to the events.
app | Pointer to the paren ksApplication. |
Reimplemented from ksf::ksComponent.
References connEventHandle, ksf::ksApplication::findComponent(), mqttConnWp, onConnected(), ksf::comps::ksMqttConnector::onConnected, and ksf::evt::ksEvent< Params >::registerEvent().
std::shared_ptr<ksf::evt::ksEvent<std::shared_ptr<ksMqttConnector>&> > ksf::comps::ksDevStatMqttReporter::onReportCustomStats {std::make_shared<ksf::evt::ksEvent<std::shared_ptr<ksMqttConnector>&>>()} |
Called when Dev Stat Reporter timer is triggered. Users can bind to this event to add their own stats.
param_1 | Shared pointer to the MQTT connector. |
Referenced by reportDevStats().