Doxygen with github
Loading...
Searching...
No Matches
ksDevStatMqttReporter.h
1/*
2 * Copyright (c) 2020-2026, Krzysztof Strehlau
3 *
4 * This file is a part of the ksIotFrameworkLib IoT 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 <cstdint>
13
14#include "../evt/ksEvent.h"
15#include "../ksComponent.h"
16
17#include "../misc/ksSimpleTimer.h"
18
19namespace ksf::comps
20{
21 class ksMqttConnector;
22
33 {
34 KSF_RTTI_DECLARATIONS(ksDevStatMqttReporter, ksComponent)
35
36 protected:
37 std::weak_ptr<ksMqttConnector> mqttConnWp;
38 std::unique_ptr<evt::ksEventHandle> connEventHandle;
40
48 void onConnected();
49
53 void reportDevStats() const;
54
55 public:
60 DECLARE_KS_EVENT(onReportCustomStats, std::shared_ptr<ksMqttConnector>&)
61
62
66 ksDevStatMqttReporter(uint8_t intervalInSeconds = 60);
67
76 bool postInit(ksApplication* app) override;
77
83 bool loop(ksApplication* app) override;
84 };
85}
A component that periodically reports the device state to the broker.
Definition ksDevStatMqttReporter.h:33
misc::ksSimpleTimer reporterTimer
Timer to report device stats.
Definition ksDevStatMqttReporter.h:39
void reportDevStats() const
Reports device statistics to the MQTT broker.
Definition ksDevStatMqttReporter.cpp:51
void onConnected()
Calback executed on MQTT connection.
Definition ksDevStatMqttReporter.cpp:46
bool loop(ksApplication *app) override
Handles MQTT debug connector component loop logic.
Definition ksDevStatMqttReporter.cpp:65
bool postInit(ksApplication *app) override
Handles component post-initialization.
Definition ksDevStatMqttReporter.cpp:36
std::unique_ptr< evt::ksEventHandle > connEventHandle
Event handle for connection delegate.
Definition ksDevStatMqttReporter.h:38
std::weak_ptr< ksMqttConnector > mqttConnWp
Weak pointer to MQTT connector.
Definition ksDevStatMqttReporter.h:37
ksDevStatMqttReporter(uint8_t intervalInSeconds=60)
Constructs device statistics reporter component.
Definition ksDevStatMqttReporter.cpp:32
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:60
A class that serves as the base for user-defined applications.
Definition ksApplication.h:44
Base component class.
Definition ksComponent.h:36
A simple timer class that does not rely on component architecture.
Definition ksSimpleTimer.h:27