BooleanSensor
🧩 Syntax:
// Boolean sensors like switch buttons, that have similar outputs concerning to similar inputs
namespace DigitalTwins
{
public class BooleanThing // Class that represents the sensor
{
public string Thing;
public string type;
public string contact;
public string signal;
public string input;
public bool status;
public bool state;
public BooleanThing(string sensorID) // Constructor that passes the sensor ID to the thing
{
Thing = sensorID; // Sets the sensor ID to the thing
}
public void BooleanLogic(string type, bool status)
{
contact = type;
state = status;
if (contact == "NC")
{
if (state)
{
signal = "OFF";
}
else
{
signal = "ON";
}
}
else if (contact == "NO")
{
if (state)
{
signal = "ON";
}
else
{
signal = "OFF";
}
}
Curl.put($"IoT:{Thing}/features/Logical/properties/Contacts/{contact}/Output", signal);
}
public void UpdateNC()
{
status = false;
type = "NC";
input = Curl.get($"IoT:{Thing}/features/Logical/properties/Contacts/{type}/Input");
if (input == "ON")
{
status = true;
}
BooleanLogic(type, status);
}
public void UpdateNO()
{
status = false;
type = "NO";
input = Curl.get($"IoT:{Thing}/features/Logical/properties/Contacts/{type}/Input");
if (input == "ON")
{
status = true;
}
BooleanLogic(type, status);
}
}
}