HouseMon Circuits Tutorial-1.05

Lets continue extending our ‘ReadFileText’ based circuit.

Change to your housemon folder.

Now display the circuit tutorial information:

./cirget status

Please select circuit 5:

$ ./cirget circuit 5
$ ./cirget -y

So – lets take a look at what is new in this circuit.

#Read a Text file, output is sent to console line printer.
        name: "dummy"
        type: "Pipe"
        name: "rft"
        type: "ReadFileText"
        name: "p"
        type: "Printer"
        from: "rft.Out"
        to: "p.In"
        data: "setup.json"
        to: "rft.In"

        external: "In"
        internal: "dummy.In"
        external: "Out"
        internal: "dummy.Out"

Nothing much 😦 , we have added a ‘Printer’ gadget (Line 12-13). We first used this is the earlier tutorials. ‘Printer’ takes its input messages and ‘Prints’ them to the stdout (system console).

What do you think will happen when we run this circuit?

Well, first off it ‘looks’ very similar to the last tutorial, however each message that is emitted from ‘rft’ is NOT being ‘lost’ now, it is being ‘consumed’ by the ‘Printer’ gadget and sent to the screen in a purposeful manner. You won’t see the ‘Lost’ notation.
I would expect you are now tired of the ‘Printer’ gadget – this is the last time we will cover it for a while.

Notice the ‘Tag’ message at the beginning and end of the file’s output.

Here is the first one:

{Tag:<open> Msg:setup.json}

Within the current HouseMon, we have the concept of ‘Tagged’ messages. Normal messages are things like ‘strings’ and ‘integers’ being pushed around the circuit. Tagged messages have what I would call a ‘context’, its really just a little bit of information that is provided alongside the actual message data to provide some additional meaning. If using Tagged messages, its current practice to provide the tag as an angle bracketed bit of data, like <data>.

Tagged messages come into their own then a receiving gadget can derive meaning and process the Tag alongside the message.

When we started this circuit, we provided the feed ‘setup.json’ to ‘rft’ .In pin on startup.

The message we see above was produced by the ‘ReadFileText’ gadget the moment it was able to ‘successfully’ open and read the file.

What happens in the case where the file ‘setup.json’ is not present (or readable)?. Well this gadget is set to ‘panic’ which means that it will stop the entire application. In some cases this is probably the expected behaviour, on other cases its probably not what you want. There is a slightly more refined ‘ReadFileTextEx’ in my toolkit ‘flow-ext’ that can have its behaviour controlled a little more granularly.

Sidetrack: Gadgets that Panic | Circuits that panic

Lets take a little diversion.

We know that HouseMon is still experimental and has a focus on small footprint monitoring / automation specifically directed at the RF sensor network and things all things ‘Jee’ (Although – bacause it can be extended there are many more use-cases that it could help with). Most of the gadgets have been constructed with this limited ‘universe’ in mind, and more specifically they generally run in a ‘universe’ where most things are as they should be. Hence the original ‘ReadFileText’ only ever really expects that it WILL find, and be able to READ the file its given. In the wider scheme of things, especially when we start creating ‘dynamic’ circuits, this will not always be the case.

As such my advice for gadget developers is to cater for situations like this and to ‘determine’ how situations like a missing file should work (should it really cause a panic). Perhaps it would be best not to panic, and just NOT emit any messages. The gadget could emit say a simple ‘Tagged’ message like:

{Tag:<error> Msg:setup.json}

You could then include say a ‘Error’ gadget in a circuit, and when it sees a Tagged message like this, IT could descide whether to panic or not?

Likewise, circuits currently stop when they meet some conditions (like a gadget not handling an error correctly).

Expect the gadget/circuit infrastructure to be enhanced shortly so that you are able to define this rudimentary behaviour a little more granularly.

OK, back on track…

The last message the ‘ReadFileText’ emits is:

{Tag:<close> Msg:setup.json}

Again, this is simply telling us that the gadget reached the end of the file, so we should expect no more messages from it.

Tagged messages were the real point of this tutorial – please keep note of what they are and how they could be used. We will meet them again.

Posted in Uncategorized

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: