HouseMon Circuits Tutorial-1.12

Here we are at circuit 12. Its going to build upon what we did in circuit 11.

A word of caution: don’t go racing ahead, this is the first tutorial where you will be required to do something other that get a circuit I provided and run housemon.

Lets just outline our objectives:

  • We are going to drive the circuit from an environment variable that you can tweak.
  • We are going to use another gadget ‘Clock’.

Lets get the circuit:

$ ./cirget circuit 12
$ ./cirget -y

And here is the circuit:

#Read environment variable and make a Tagged message from it.
#warning: using env.In from a feed will close the pin - used only as a demonstra
#export DURATION="2s" from your shell
        name: "dummy"
        type: "Pipe"
        name: "env"
        type: "EnvVar"
        name: "clock"
        type: "Clock"
        name: "at"
        type: "AddTag"
        from: "env.Out"
        to: "clock.In"
        from: "clock.Out"
        to: "at.In"
        data: "DURATION"
        to: "env.In"
        data: "TICK"
        to: "at.Tag"
        external: "In"
        internal: "dummy.In"
        external: "Out"
        internal: "dummy.Out"

Here is another quick teardown:

‘EnvVar’ looks for an environment variable ‘DURATION’. It passes this data into ‘Clock’. Clock does not take in messages like a traditional gadget.

The ‘Clock’ .In pin is simply for a parameter that defines a ‘Duration’ like the Timer gadget we used. We could have had this defined in the ‘feeds:’ section of the circuit like this:

        data: "2s"
        to: "clock.In"

…but then you would not get to control it without editing the circuit data. So, instead we allow the environment variable ‘DURATION’ to contain this parameter, and we use the ‘EnvVar’ to pass the parameter into ‘Clock’.

Next ‘Clock’ passes its output to ‘AddTag’ which is supplied with an initialisation parameter ‘TICK’ in the ‘feeds:’ section.

A Clock emits its output message (the current time) every ‘Duration’ period that is supplied to its .In pin.

So, if we supplied “2s” to the ‘Clock’ .In pin, then the ‘Clock’ will output the time every 2 seconds on its .Out pin. We then send this time into the ‘AddTag’ gadget that turns the time message into a ‘tagged’ message using ‘TICK’ as the tag.

Before we run this circuit, we need to setup an environment variable, and this is different depending upon your operating system:

Windows (assumes your running powershell):

PS > $env:DURATION = "2s"

Linux / osx

$ export DURATION="2s"

Now lets run housemon:

$ ./housemon

With any luck, you’ll see something like this:

Starting webserver for
Lost flow.Tag: {<dispatched> init}
Lost flow.Tag: {TICK 2014-05-19 14:21:53.8669255 +0100 BST}
Lost flow.Tag: {TICK 2014-05-19 14:21:55.8670399 +0100 BST}
Lost flow.Tag: {TICK 2014-05-19 14:21:57.8671543 +0100 BST}

Notice that the messages are ‘tagged’ “TICK” messages, and contain the time approx every 2 seconds apart.

The next post will see us complete the basic tutorial series for housemon circuits.

Posted in cirget, housemon, housemon tutorials, soft-circuits

Leave a Reply

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

You are commenting using your 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: