SensESP 3.3.0
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
system_info.h
Go to the documentation of this file.
1#ifndef SENSESP_SENSORS_SYSTEM_INFO_H_
2#define SENSESP_SENSORS_SYSTEM_INFO_H_
3
4#include <Arduino.h>
5#include <elapsedMillis.h>
6#include <memory>
7
9#include "sensesp_base_app.h"
10#include "sensor.h"
11
12namespace sensesp {
13
17template <typename T>
18void connect_system_info_sensor(std::shared_ptr<ValueProducer<T>>& sensor,
19 const String& prefix, const String& name) {
20 auto hostname_obs = SensESPBaseApp::get()->get_hostname_observable();
21 String hostname = hostname_obs->get();
22 String path = prefix + hostname + "." + name;
23
24 auto sk_output = std::make_shared<SKOutput<T>>(path);
25
26 // connect an observer to hostname to change the output path
27 // if the hostname is changed
28 auto update_output_sk_path = [hostname_obs, sk_output, prefix, name]() {
29 String path = prefix + hostname_obs->get() + "." + name;
30 sk_output->set_sk_path(path);
31 };
32 update_output_sk_path();
33
34 hostname_obs->attach(update_output_sk_path);
35
36 // connect the sensor to the output
37 sensor->connect_to(sk_output);
38}
39
47class SystemHz : public ValueProducer<float> {
48 public:
51 repeat_event_ = event_loop()->onRepeat(1000, [this]() { this->update(); });
52 }
53 virtual ~SystemHz() {
54 if (repeat_event_ != nullptr) {
55 repeat_event_->remove(event_loop());
56 }
57 }
58 String get_value_name() { return "systemhz"; }
59
60 protected:
61 uint32_t last_tick_count_ = 0;
62 elapsedMillis elapsed_millis_;
63 reactesp::RepeatEvent* repeat_event_ = nullptr;
64 void update();
65};
66
74class FreeMem : public ValueProducer<uint32_t> {
75 public:
77 repeat_event_ = event_loop()->onRepeat(1000, [this]() { this->update(); });
78 }
79 virtual ~FreeMem() {
80 if (repeat_event_ != nullptr) {
81 repeat_event_->remove(event_loop());
82 }
83 }
84 String get_value_name() { return "freemem"; }
85
86 protected:
87 reactesp::RepeatEvent* repeat_event_ = nullptr;
88 void update();
89};
90
99class Uptime : public ValueProducer<float> {
100 public:
102 repeat_event_ = event_loop()->onRepeat(1000, [this]() { this->update(); });
103 }
104 virtual ~Uptime() {
105 if (repeat_event_ != nullptr) {
106 repeat_event_->remove(event_loop());
107 }
108 }
109 String get_value_name() { return "uptime"; }
110
111 protected:
112 reactesp::RepeatEvent* repeat_event_ = nullptr;
113 void update();
114};
115
124class IPAddrDev : public ValueProducer<String> {
125 public:
127 repeat_event_ = event_loop()->onRepeat(10000, [this]() { this->update(); });
128 }
129 virtual ~IPAddrDev() {
130 if (repeat_event_ != nullptr) {
131 repeat_event_->remove(event_loop());
132 }
133 }
134 String get_value_name() { return "ipaddr"; }
135
136 protected:
137 reactesp::RepeatEvent* repeat_event_ = nullptr;
138 void update();
139};
140
149class WiFiSignal : public ValueProducer<int> {
150 public:
152 repeat_event_ = event_loop()->onRepeat(3000, [this]() { this->update(); });
153 }
154 virtual ~WiFiSignal() {
155 if (repeat_event_ != nullptr) {
156 repeat_event_->remove(event_loop());
157 }
158 }
159 String get_value_name() { return "wifisignal"; }
160
161 protected:
162 reactesp::RepeatEvent* repeat_event_ = nullptr;
163 void update();
164};
165
166} // namespace sensesp
167
168#endif
String get_value_name()
Definition system_info.h:84
virtual ~FreeMem()
Definition system_info.h:79
reactesp::RepeatEvent * repeat_event_
Definition system_info.h:87
reactesp::RepeatEvent * repeat_event_
String get_value_name()
static const std::shared_ptr< SensESPBaseApp > & get()
Get the singleton instance of the SensESPBaseApp.
String get_value_name()
Definition system_info.h:58
virtual ~SystemHz()
Definition system_info.h:53
uint32_t last_tick_count_
Definition system_info.h:61
elapsedMillis elapsed_millis_
Definition system_info.h:62
reactesp::RepeatEvent * repeat_event_
Definition system_info.h:63
String get_value_name()
reactesp::RepeatEvent * repeat_event_
virtual ~Uptime()
A base class for any sensor or piece of code that outputs a value for consumption elsewhere.
reactesp::RepeatEvent * repeat_event_
std::shared_ptr< reactesp::EventLoop > event_loop()
Definition sensesp.cpp:9
void connect_system_info_sensor(std::shared_ptr< ValueProducer< T > > &sensor, const String &prefix, const String &name)
Connect a system information sensor to SKOutput.
Definition system_info.h:18