Doxygen with github
Loading...
Searching...
No Matches
ksf::comps::ksDevStatMqttReporter Class Reference

A component that periodocally reports device state to the broker. More...

#include <ksDevStatMqttReporter.h>

+ Inheritance diagram for ksf::comps::ksDevStatMqttReporter:

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.
 
 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.
 
- Public Member Functions inherited from ksf::ksComponent
virtual bool init (ksApplication *app)
 Initializes component.
 
- 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< 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< ksMqttConnectormqttConnWp
 Weak pointer to MQTT connector.
 
std::unique_ptr< evt::ksEventHandleconnEventHandle
 Event handle for connection delegate.
 
ksSimpleTimer reporterTimer
 Timer to report device stats.
 
- Protected Attributes inherited from ksf::ksComponent
ksComponentState::TYPE componentState { ksComponentState::NotInitialized }
 

Detailed Description

A component that periodocally reports device state to the broker.

Upon instantiated, the component will look for ksMqttConnector component. The interval between each update is defined by the construction parameter.

Each update contain values like RSSI, device uptime, connection time and IP address. The subtopic used is "dstat", so for example RSSI will be sent to the topic named "deviceprefix/dstat/rssi".

Constructor & Destructor Documentation

◆ ksDevStatMqttReporter()

ksf::comps::ksDevStatMqttReporter::ksDevStatMqttReporter ( uint8_t intervalInSeconds = 60)

Constructs device statistics reporter component.

Parameters
intervalInSecondsInterval in seconds between each report.

Member Function Documentation

◆ getInstanceType()

virtual const size_t ksf::comps::ksDevStatMqttReporter::getInstanceType ( ) const
inlinevirtual

Retrieves type ID of the object.

Returns
Object type ID.

Reimplemented from ksf::ksComponent.

◆ isA()

virtual bool ksf::comps::ksDevStatMqttReporter::isA ( const size_t id) const
inlinevirtual

Checks whether object is of given type.

Parameters
idType ID to check against.
Returns
True if object is of given type, otherwise false.

Reimplemented from ksf::ksComponent.

◆ loop()

bool ksf::comps::ksDevStatMqttReporter::loop ( ksApplication * app)
overridevirtual

Handles MQTT debug connector component loop logic.

Parameters
appPointer to the parent ksApplication.
Returns
True on success, false on fail.

Reimplemented from ksf::ksComponent.

References reportDevStats(), reporterTimer, and ksf::ksSimpleTimer::triggered().

◆ onConnected()

void ksf::comps::ksDevStatMqttReporter::onConnected ( )
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::ksSimpleTimer::restart().

Referenced by postInit().

◆ postInit()

bool ksf::comps::ksDevStatMqttReporter::postInit ( ksApplication * app)
overridevirtual

Handles component post-initialization.

This method is responsible for reference gathering (component lookup) as well as binding to the events.

Parameters
appPointer to the paren ksApplication.
Returns
True on success, false on fail.

Reimplemented from ksf::ksComponent.

References connEventHandle, ksf::ksApplication::findComponent(), mqttConnWp, onConnected(), ksf::comps::ksMqttConnector::onConnected, and ksf::evt::ksEvent< Params >::registerEvent().

Member Data Documentation

◆ onReportCustomStats

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.

Parameters
param_1Shared pointer to the MQTT connector.

Referenced by reportDevStats().


The documentation for this class was generated from the following files: