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::BinarySensor Class Reference

mupplet-sensor, binary sensor More...

#include <mup_binary_sensor.h>

Public Member Functions

 BinarySensor (String name, uint8_t digitalPort, bool inverseLogic=false, String topicName="state")
 
bool getPhysicalState ()
 
bool getBinarySensorLogicalState ()
 
void begin (Scheduler *_pSched, uint32_t _pollRateMs=2000)
 

Detailed Description

mupplet-sensor, binary sensor

The binary_sensor mupplet measures a digital input

Messages sent by binary_sensor mupplet:

Note: this mupplet uses two topics in parallel, with sensor and binary_sensor in the topic path. So applications can chose which one to use.

Physical and logical state values of the GPIO assigned to the binary_sensor are opposite, if inverseLogic is set to true during instantiation. Only logical state values are sent automatically on state changes.

topic message body comment
<mupplet-name>/sensor/<topicName> ON or OFF state of binary sensor, topicName given at instantiation, default binary_sensor, automatically sent on state changes
<mupplet-name>/binary_sensor/<topicName> \ilinebr </td> <td class="markdownTableBodyNone">ONorOFF\ilinebr </td> <td class="markdownTableBodyNone"> state of binary sensor using binary_sensor/topicName with topicName given at object instantiation, automatically sent on state changes \ilinebr </td> </tr> <tr class="markdownTableRowOdd"> <td class="markdownTableBodyNone"><mupplet-name>/sensor/physical/<topicName>\ilinebr </td> <td class="markdownTableBodyNone">ONorOFF\ilinebr </td> <td class="markdownTableBodyNone"> state of binary sensor, topicName given at instantiation, defaultbinary_sensor, not sent automatically on state change, but only as reply to the corresponding GET message (s.b.) \ilinebr </td> </tr> <tr class="markdownTableRowEven"> <td class="markdownTableBodyNone"><mupplet-name>/binary_sensor/physical/<topicName> ON or OFF state of binary sensor using binary_sensor/topicName with topicName given at object instantiation, not set automatically on state change.

Messages received by binary_sensor mupplet:

topic message body comment
<mupplet-name>/sensor/<topicName>/get - Causes current logical state value to be sent with.
<mupplet-name>/binary_sensor/<topicName>/get - Causes current logical state value to be sent.
<mupplet-name>/sensor/physical/<topicName>/get - Causes current physical state value to be sent with.
<mupplet-name>/binary_sensor/physical/<topicName>/get - Causes current physical state value to be sent.

Hardware: BinarySensor, 10kΩ resistor

Sample code

#define __ESP__ 1
#include "scheduler.h"
#include "mup_binary_sensor.h"
ustd::Scheduler sched;
ustd::BinarySensor binarySensor("myBinarySensor",D2);
void setup() {
binarySensor.begin(&sched);
}
mupplet-sensor, binary sensor
Definition: mup_binary_sensor.h:56

Constructor & Destructor Documentation

◆ BinarySensor()

ustd::BinarySensor::BinarySensor ( String  name,
uint8_t  digitalPort,
bool  inverseLogic = false,
String  topicName = "state" 
)
inline

Instantiate an BinarySensor sensor mupplet

Parameters
nameName used for pub/sub messages
digitalPortGPIO port for binary sensor input
inverseLogicdefault false. If true, 'ON' is signaled if GPIO is low (inverse logic)
topicNameMQTT topic used to send both sensor/<topicName> and binary_sensor/<topicName> messages.

Member Function Documentation

◆ begin()

void ustd::BinarySensor::begin ( Scheduler *  _pSched,
uint32_t  _pollRateMs = 2000 
)
inline

Start processing of binary sensor input

Parameters
_pSchedpointer to muwerk scheduler object
_pollRateMsmeasurement interval in ms, default 2secs.

◆ getBinarySensorLogicalState()

bool ustd::BinarySensor::getBinarySensorLogicalState ( )
inline

get the current logical state of the binary sensor.

Note: if inverseLogic is set the true during object instantiation, true is returned, if GPIO is low (inverted logic). getPhysicalState()

Returns
bool, current logical state

◆ getPhysicalState()

bool ustd::BinarySensor::getPhysicalState ( )
inline

get the current physical state of the binary sensor

Note: this gives true for GPIO state HIGH and false for GPIO state LOW, regardless of inverseLogic setting. getBinarySensorLogicalState()

Returns
bool, current physical state of GPIO assigned to binary sensor

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