HouseMon Circuits Tutorial-1.10

In circuit tutorial 09 we ended up with 2 duplicate sets of messages. One set of messages was specifically sent to ‘nowhere land’ which left us again with one set of messages to deal with. We chose to keep them printed onto the console via the ‘Printer’ gadget.

In this tutorial we introduce 1 new gadget ‘TimeStamp’ and a new concept of augmenting existing messages.

The ‘TimeStamp’ gadget take a message into its .In pin and emits 2 output messages.

  • The first message it emits is a formatted string containing the current date/time, with nanosecond accuracy. The string also includes the UTC specifier.

  • The second message is the original message received on the .In pin.

So, in short we have turned the original message into 2 messages, moving down our circuit.

I suppose if we use the electrical concepts, we have increased the number of electrons (current!), but I don’t like that analogy myself.

Augmenting messages.

There is no logical limit really for the number of messages a gadget produces, it could turn 1 message into 1000’s, but your circuit must be able to handle these messages, and there are limitations set for this. I won’t go into technical details here, as that is an issue for gadget designers to be aware of.

You will find that many gadgets rely on augmented messages from an upstream gadget, specifically you will see ‘tagged’ messages being used to separate and organize this information. So be aware that the gadgets you use may produce 1 or more outgoing messages for each input message, conversely they may take many inbound messages and emit only 1 output message. Also, like the ‘Sink’ gadget, they make take input and produce no message output. It will be common for you to see gadgets that interact with physical items to consume messages and never produce any direct message based output, rather the output will be a physical change to the environment, like a relay opening, or an LED flashing.

Lets look at our little circuit with its ‘TimeStamp’ and augmented messages:

$ ./cirget circuit 10
$ ./cirget -y

Here is the circuit:

#Read a Text file, output first delayed by 200ms, then sent to FanOut,
#fo.Pin1 sent to console line printer.
#fo.Pin2 sent to Pipe where its output is sent to the sink 'snk' and is eaten up
.
#fo.Pin1 is then sent to Timestamp causes a second message to flow.
---
  init:
    gadgets:
      -
        name: "dummy"
        type: "Pipe"
      -
        name: "rft"
        type: "ReadFileText"
      -
        name: "p"
        type: "Printer"
      -
        name: "d"
        type: "Delay"
      -
        name: "fo"
        type: "FanOut"
      -
        name: "pipe"
        type: "Pipe"
      -
        name: "snk"
        type: "Sink"
      -
        name: "ts"
        type: "TimeStamp"
    wires:
      -
        from: "rft.Out"
        to: "d.In"
      -
        from: "d.Out"
        to: "fo.In"
      -
        from: "fo.Out:pin1"
        to: "ts.In"
      -
        from: "ts.Out"
        to: "p.In"
      -
        from: "fo.Out:pin2"
        to: "pipe.In"
      -
        from: "pipe.Out"
        to: "snk.In"
    feeds:
      -
        data: "setup.json"
        to: "rft.In"
      -
        data: "200ms"
        to: "d.Delay"
    labels:
      -
        external: "In"
        internal: "dummy.In"
      -
        external: "Out"
        internal: "dummy.Out"

And here is a snippet of output:

Starting webserver for http://0.0.0.0:556
Lost flow.Tag: {<dispatched> init}
2014-05-19 12:54:53.7986529 +0100 BST
{Tag:<open> Msg:setup.json}
2014-05-19 12:54:53.9986643 +0100 BST
{
2014-05-19 12:54:54.1986758 +0100 BST
  "init": {
2014-05-19 12:54:54.3986872 +0100 BST
    "gadgets": [
2014-05-19 12:54:54.5986986 +0100 BST
      {
2014-05-19 12:54:54.7987101 +0100 BST
        "name": "dummy",
2014-05-19 12:54:54.9987215 +0100 BST
        "type": "Pipe"
2014-05-19 12:54:55.198733 +0100 BST
      },
2014-05-19 12:54:55.3987444 +0100 BST

As you can see, for each and every message (including lines of the file read by ‘ReadFileText’) we get two messages sent to the display, the first is the timestamp, and the second message is the original line of text output from the file, including the ‘tagged’ messages that ‘ReadFiletext’ produces.

In the next tutorial, we will expand upon the ‘tagged’ message concepts…

Advertisements
Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: