SensESP 3.0.1
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 event_loop()->onRepeat(1000, [this]() { this->update(); });
52 }
53 String get_value_name() { return "systemhz"; }
54
55 protected:
56 uint32_t last_tick_count_ = 0;
57 elapsedMillis elapsed_millis_;
58 void update();
59};
60
68class FreeMem : public ValueProducer<uint32_t> {
69 public:
71 event_loop()->onRepeat(1000, [this]() { this->update(); });
72 }
73 String get_value_name() { return "freemem"; }
74
75 protected:
76 void update();
77};
78
87class Uptime : public ValueProducer<float> {
88 public:
90 event_loop()->onRepeat(1000, [this]() { this->update(); });
91 }
92 String get_value_name() { return "uptime"; }
93
94 protected:
95 void update();
96};
97
106class IPAddrDev : public ValueProducer<String> {
107 public:
109 event_loop()->onRepeat(10000, [this]() { this->update(); });
110 }
111 String get_value_name() { return "ipaddr"; }
112
113 protected:
114 void update();
115};
116
125class WiFiSignal : public ValueProducer<int> {
126 public:
128 event_loop()->onRepeat(3000, [this]() { this->update(); });
129 }
130 String get_value_name() { return "wifisignal"; }
131
132 protected:
133 void update();
134};
135
136} // namespace sensesp
137
138#endif
Reports the current amount of unused memory of the ESP.
Definition system_info.h:68
String get_value_name()
Definition system_info.h:73
Reports the IP address of the ESP once it's connected to wifi.
String get_value_name()
static const std::shared_ptr< SensESPBaseApp > & get()
Get the singleton instance of the SensESPBaseApp.
Reports the current clock speed of the ESP.
Definition system_info.h:47
String get_value_name()
Definition system_info.h:53
uint32_t last_tick_count_
Definition system_info.h:56
elapsedMillis elapsed_millis_
Definition system_info.h:57
Reports the number of seconds since the last restart of the ESP.
Definition system_info.h:87
String get_value_name()
Definition system_info.h:92
A base class for any sensor or piece of code that outputs a value for consumption elsewhere.
Reports the current strength of the wifi signal that the ESP is connected to.
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