Things & Ports

Nodes implement the Plegma API to allow communication and interaction with our cloud, but their main purpose is to expose and manage Things, the entities that actually do stuff. In this section we describe how to create them and the Ports they enclose, while in the Things management & control section we’ll talk about how to sync them with our cloud.

So without further delay..

Things


..a Thing is this:

            
public class Thing
{
    public string ThingKey;
    public string Name;
    public List<ConfigParameter> Config;
    public List<Port> Ports;
    public string Type;
    public string BlockType;      
    public bool Removable;
    public ThingUIHints UIHints;
}
            
        

It includes:

Each Thing has one or more Ports:

Ports


Each Thing is an island of functionality and Ports are the points it uses to exchange information with

A simple button Thing may have a single output Port that triggers a message whenever it is pressed or depressed.

A button has no input Ports because it is completely event based, however a Thing representing a switch may have an output port triggering a message whenever it changes state, while also providing an input port allowing its configuration or sampling of its state at any time.

More complex things can have multiple input and output ports, allowing them to be sampled -or triggered- by external entities, while also generating events of their own towards others.

Our Port representation is:

            
public class Port
{
    public string PortKey;
    public string Name;
    public string Description;
    public ioPortDirection ioDirection;
    public ePortType Type;
    public string State;
    public int RevNum;
    public ePortConf ConfFlags;
}
            
        

Its members are:

In addition to those values, if using a custom model for the Port’s parent Thing, then a Port’s state could be a custom JSON-serialized string representing a complex type

Please see Message & event passing for more information on the whys and hows of this

Examples


here are some real-world examples of Things / Ports definitions:

            
//Setup a tri-color RGB LED Thing
{
  //setup the LED thing itself
  var RgbLedThing = new Yodiwo.API.Plegma.Thing()
  {
    ThingKey = new ThingKey(NodeKey, _generateThingID()),
    Name = "Raspberry tri-color Led",
    Config = null,
    UIHints = new ThingUIHints()
    {
      IconURI = "/Content/RaspberryNode/img/icon-rgb-led.png"
    }
  };

  //setup its three boolean input ports (receiving events to 
  //turn the LED on/off), one for each LED color
  thing.Ports = new List<Yodiwo.API.Plegma.Port>()
  {
    new Yodiwo.API.Plegma.Port()
    {
      PortKey = new Yodiwo.API.Plegma.PortKey(thing, "0"),
      Name = "Red",
      ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
      Type = Yodiwo.API.Plegma.ePortType.Boolean,
      State = "0"
    },
    new Yodiwo.API.Plegma.Port()
    {
      PortKey = new Yodiwo.API.Plegma.PortKey(thing, "1"),
      Name = "Green",
      ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
      Type = Yodiwo.API.Plegma.ePortType.Boolean,
      State = "0"
    },
    new Yodiwo.API.Plegma.Port()
    {
      PortKey = new Yodiwo.API.Plegma.PortKey(thing, "2"),
      Name = "Blue",
      ioDirection = Yodiwo.API.Plegma.ioPortDirection.Input,
      Type = Yodiwo.API.Plegma.ePortType.Boolean,
      State = "0"
    }
  };
}