Doxygen with github
Loading...
Searching...
No Matches
ksDevStatMqttReporter.h
1/*
2 * Copyright (c) 2021-2023, Krzysztof Strehlau
3 *
4 * This file is a part of the ksIotFramework library.
5 * All licensing information can be found inside LICENSE.md file.
6 *
7 * https://github.com/cziter15/ksIotFrameworkLib/blob/master/LICENSE
8 */
9
10#pragma once
11
12#include "../evt/ksEvent.h"
13#include "../ksComponent.h"
14#include "../ksSimpleTimer.h"
15
16namespace ksf::comps
17{
18 class ksMqttConnector;
19
30 {
31 KSF_RTTI_DECLARATIONS(ksDevStatMqttReporter, ksComponent)
32
33 protected:
34 std::weak_ptr<ksMqttConnector> mqttConnWp;
35 std::unique_ptr<evt::ksEventHandle> connEventHandle;
37
45 void onConnected();
46
50 void reportDevStats() const;
51
52 public:
57 DECLARE_KS_EVENT(onReportCustomStats, std::shared_ptr<ksMqttConnector>&)
58
59
63 ksDevStatMqttReporter(uint8_t intervalInSeconds = 60);
64
73 bool postInit(ksApplication* app) override;
74
80 bool loop(ksApplication* app) override;
81 };
82}
A component that periodocally reports device state to the broker.
Definition ksDevStatMqttReporter.h:30
void reportDevStats() const
Reports device statistics to the MQTT broker.
Definition ksDevStatMqttReporter.cpp:44
void onConnected()
Calback executed on MQTT connection.
Definition ksDevStatMqttReporter.cpp:39
bool loop(ksApplication *app) override
Handles MQTT debug connector component loop logic.
Definition ksDevStatMqttReporter.cpp:58
bool postInit(ksApplication *app) override
Handles component post-initialization.
Definition ksDevStatMqttReporter.cpp:29
ksSimpleTimer reporterTimer
Timer to report device stats.
Definition ksDevStatMqttReporter.h:36
std::unique_ptr< evt::ksEventHandle > connEventHandle
Event handle for connection delegate.
Definition ksDevStatMqttReporter.h:35
std::weak_ptr< ksMqttConnector > mqttConnWp
Weak pointer to MQTT connector.
Definition ksDevStatMqttReporter.h:34
ksDevStatMqttReporter(uint8_t intervalInSeconds=60)
Constructs device statistics reporter component.
Definition ksDevStatMqttReporter.cpp:25
std::shared_ptr< ksf::evt::ksEvent< std::shared_ptr< ksMqttConnector > & > > onReportCustomStats
Called when Dev Stat Reporter timer is triggered. Users can bind to this event to add their own stats...
Definition ksDevStatMqttReporter.h:57
A class that is a base for user-defined application.
Definition ksApplication.h:43
Base component class.
Definition ksComponent.h:51
Simple timer class, without using component architecture.
Definition ksSimpleTimer.h:27