SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
|
ConstantSensor is the base class for virtual sensors that periodically emit a constant value. More...
#include <sensesp/sensors/constant_sensor.h>
Public Member Functions | |
ConstantSensor (T value, int send_interval=30, String config_path="") | |
void | set (T value) |
virtual bool | to_json (JsonObject &doc) override |
virtual bool | from_json (const JsonObject &config) override |
Public Member Functions inherited from sensesp::Sensor< T > | |
Sensor (String config_path) | |
Public Member Functions inherited from sensesp::SensorConfig | |
SensorConfig (const String &config_path) | |
Public Member Functions inherited from sensesp::Observable | |
Observable () | |
Observable (Observable &&other) | |
Move constructor. | |
void | notify () |
void | attach (std::function< void()> observer) |
Public Member Functions inherited from sensesp::FileSystemSaveable | |
FileSystemSaveable (const String &config_path) | |
virtual bool | load () override |
Load and populate the object from a persistent storage. | |
virtual bool | save () override |
Save the object to a persistent storage. | |
virtual bool | clear () override |
Delete the data from a persistent storage. | |
bool | find_config_file (const String &config_path, String &filename) |
Public Member Functions inherited from sensesp::Saveable | |
Saveable (const String &config_path) | |
virtual bool | refresh () |
Refresh the object. This may or may not access the persistent storage but is not expected to overwrite the object's state. | |
const String & | get_config_path () const |
Public Member Functions inherited from sensesp::Serializable | |
Public Member Functions inherited from sensesp::ValueProducer< T > | |
ValueProducer () | |
ValueProducer (const T &initial_value) | |
virtual const T & | get () const |
template<typename VConsumer > | |
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, std::shared_ptr< VConsumer > >::type | connect_to (std::shared_ptr< VConsumer > consumer) |
Connect a producer to a transform with a different input type. | |
template<typename VConsumer > | |
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, VConsumer * >::type | connect_to (VConsumer *consumer) |
template<typename VConsumer > | |
std::enable_if< std::is_base_of< ValueConsumer< typenameVConsumer::input_type >, VConsumer >::value &&std::is_convertible< T, typenameVConsumer::input_type >::value, VConsumer * >::type | connect_to (VConsumer &consumer) |
void | emit (const T &new_value) |
Protected Member Functions | |
void | update () |
Protected Attributes | |
T | value_ |
int | send_interval_ |
Protected Attributes inherited from sensesp::Saveable | |
const String | config_path_ |
Protected Attributes inherited from sensesp::ValueProducer< T > | |
T | output_ |
ConstantSensor is the base class for virtual sensors that periodically emit a constant value.
The virtual sensors are typically used to send a constant value to SignalK. Typical example is the capacity of a tank or the length of an anchor rode;
The sensors can be connected to all the standard SKOutput consumers.
The sensor value and send delay can be configured via the web ui.
The sensor has a get_value() and a set_value() method to interact with the sensor from normal code.
Example: send the water tank capacity every 30 seconds to SignalK:
int send_delay = 30; const char* config_path = "/tanks.water_capacity"; auto *capacity = new ConstantFloatSensor(send_delay,config_path); capacity->connect_to(new SKOutputFloat(sk_path, sk_config_path, sk_metadata));
To set or get the the value of the virtual sensor for use in your code:
capacity->set_value(value);
value = capacity->get_value();
send_interval[in] | Time interval in seconds between consecutive emissions of the sensor value. | |
[in] | config_path | Configuration path for the sensor. |
Base class for constant value sensors.
Definition at line 49 of file constant_sensor.h.
|
inline |
|
inlineoverridevirtual |
Deserializes the current object data from a JsonObject.
Reimplemented from sensesp::Serializable.
Definition at line 68 of file constant_sensor.h.
|
inline |
Definition at line 62 of file constant_sensor.h.
|
inlineoverridevirtual |
Serializes the current object data into a JsonObject.
Reimplemented from sensesp::Serializable.
Definition at line 64 of file constant_sensor.h.
|
inlineprotected |
|
protected |
Definition at line 80 of file constant_sensor.h.
|
protected |
Definition at line 79 of file constant_sensor.h.