muwerk mupplet Sensor Library
muwerk applets; mupplets: functional units that support specific hardware or reusable applications for sensors
Loading...
Searching...
No Matches
Public Member Functions | List of all members
ustd::AnalogSensor Class Reference

mupplet-sensor analog sensor sensor More...

#include <mup_analog_sensor.h>

Public Member Functions

 AnalogSensor (String name, uint8_t analogPort, FilterMode filterMode=FilterMode::MEDIUM, String topicName="")
 
double getUnitAnalogSensor ()
 
void begin (Scheduler *_pSched, uint32_t _pollRateMs=2000, double _linTransA=1.0, double _linTransB=0.0)
 

Detailed Description

mupplet-sensor analog sensor sensor

The analog_sensor mupplet measures analog sensor using a simple analog sensor sensor

Messages sent by analog_sensor mupplet:

topic message body comment
<mupplet-name>/sensor/unitanalogsensor normalized analog sensor [0.0..1.0] or [b..a+b] Float value encoded as string, rescaled if a non-default linear transformation is given at begin()
<mupplet-name>/sensor/<topicName> normalized analog sensor [0.0..1.0] or [b..a+b] Float value encoded as string, topicName is an optional parameter of the object initialization
<mupplet-name>/sensor/mode FAST, MEDIUM, or LONGTERM Integration time for analog sensor values

Messages received by analog_sensor mupplet:

topic message body comment
<mupplet-name>/sensor/unitanalogsensor/get - Causes current value to be sent.
<mupplet-name>/sensor/<topicName>/get - Causes current value to be sent, if an additional topicName was given at object creation.
<mupplet-name>/sensor/mode/get - Returns filterMode: FAST, MEDIUM, or LONGTERM
<mupplet-name>/sensor/mode/set FAST, MEDIUM, or LONGTERM Set integration time for analog sensor values

Hardware: AnalogSensor, 10kΩ resistor

Sample code

#define __ESP__ 1
#include "scheduler.h"
#include "mup_analog_sensor.h"
ustd::Scheduler sched;
ustd::AnalogSensor analogSensor("myAnalogSensor",A0);
void setup() {
analogSensor.begin(&sched);
}
mupplet-sensor analog sensor sensor
Definition: mup_analog_sensor.h:51

Note: For ESP32 make sure to use a port connected to ADC #1, since ADC #2 conflicts with Wifi and ports connected to ADC #2 cannot be used concurrently with Wifi!

Constructor & Destructor Documentation

◆ AnalogSensor()

ustd::AnalogSensor::AnalogSensor ( String  name,
uint8_t  analogPort,
FilterMode  filterMode = FilterMode::MEDIUM,
String  topicName = "" 
)
inline

Instantiate an AnalogSensor sensor mupplet

Parameters
nameName used for pub/sub messages
analogPortGPIO port with A/D converter capabilities.
filterModeFAST, MEDIUM or LONGTERM filtering of sensor values of analog port
topicNameoptional additional mqtt topic name, generating additional mqtt messages

Member Function Documentation

◆ begin()

void ustd::AnalogSensor::begin ( Scheduler *  _pSched,
uint32_t  _pollRateMs = 2000,
double  _linTransA = 1.0,
double  _linTransB = 0.0 
)
inline

Start processing of A/D input from AnalogSensor

The analog sensor mupplet by default measures the analog port, and maps values always into the range [0..1]. Optionally, a linear transformation can be applied to map the range value into a different range: if a value v is measured, v is by default [0..1] and now a * v + b is applied. With the defaults of a=1, b=0, no change is made by the transformation, since 1*v+0 = v. By changing _linTransA (for a) and/or _linTransB (for b), the output range can be rescaled linearily.

Note: if you are not using the linear transformation feature, make sure that _linTransA is set to 1.0 and _linTransB is set to 0.0!

Parameters
_pSchedpointer to muwerk scheduler object
_pollRateMsOptional measurement pollrate in ms, default 2000, a measurement every 2 secs.
_linTransAOptional transformation factor a, default 1.0, values v read from analog sensor are transformed with a*v+b.
_linTransBOptional transformation factor b, default 0.0, values v read from analog sensor are transformed with a*v+b.

◆ getUnitAnalogSensor()

double ustd::AnalogSensor::getUnitAnalogSensor ( )
inline

Get current analog sensor value

Returns
Unit-analogsensor [0.0 - 1.0], if a linear transformation is used, the range is [b - a+b]

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