SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
sensesp::ConstantSensor< T > Class Template Reference

ConstantSensor is the base class for virtual sensors that periodically emit a constant value. More...

#include <sensesp/sensors/constant_sensor.h>

Inheritance diagram for sensesp::ConstantSensor< T >:
[legend]

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

value_
 
int send_interval_
 
- Protected Attributes inherited from sensesp::Saveable
const String config_path_
 
- Protected Attributes inherited from sensesp::ValueProducer< T >
output_
 

Detailed Description

template<class T>
class sensesp::ConstantSensor< T >

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();

Parameters
send_interval[in]Time interval in seconds between consecutive emissions of the sensor value.
[in]config_pathConfiguration path for the sensor.

Base class for constant value sensors.

Definition at line 49 of file constant_sensor.h.

Constructor & Destructor Documentation

◆ ConstantSensor()

template<class T >
sensesp::ConstantSensor< T >::ConstantSensor ( T value,
int send_interval = 30,
String config_path = "" )
inline

Definition at line 51 of file constant_sensor.h.

Here is the call graph for this function:

Member Function Documentation

◆ from_json()

template<class T >
virtual bool sensesp::ConstantSensor< T >::from_json ( const JsonObject & root)
inlineoverridevirtual

Deserializes the current object data from a JsonObject.

Reimplemented from sensesp::Serializable.

Definition at line 68 of file constant_sensor.h.

◆ set()

template<class T >
void sensesp::ConstantSensor< T >::set ( T value)
inline

Definition at line 62 of file constant_sensor.h.

◆ to_json()

template<class T >
virtual bool sensesp::ConstantSensor< T >::to_json ( JsonObject & root)
inlineoverridevirtual

Serializes the current object data into a JsonObject.

Reimplemented from sensesp::Serializable.

Definition at line 64 of file constant_sensor.h.

◆ update()

template<class T >
void sensesp::ConstantSensor< T >::update ( )
inlineprotected

Definition at line 77 of file constant_sensor.h.

Here is the call graph for this function:

Member Data Documentation

◆ send_interval_

template<class T >
int sensesp::ConstantSensor< T >::send_interval_
protected

Definition at line 80 of file constant_sensor.h.

◆ value_

template<class T >
T sensesp::ConstantSensor< T >::value_
protected

Definition at line 79 of file constant_sensor.h.


The documentation for this class was generated from the following file: