Official website

Showing posts with label events. Show all posts
Showing posts with label events. Show all posts

Monday, June 23, 2014

Asynchronous operations triggered by arduino serial data

Another interesting and useful thing to know about Jubito is that its continuously monitor the serial port where arduino is connected. That allows as to control any message that arduino prints out. There is two ways to use that kind of data. One is by creating a new instruction set, which explained in this post, and the other one is by firing events. The second way is very efficient for asynchronous operations such as motion detection.

Let's make an example.


The above screenshot illustrates a MotionDetected message captured from a PIR sensor. In order to trigger an event or a sequence of actions we have to create a handler with the same name.

On Control Panel select Instruction Sets/Add New Event Handler


Then give the corresponding serial message as the name of the event handler


Action's can be vary depending your needs. In this example I will create a simple email notification. In the action field type...

judo mail send me@gmail.com me@gmail.com `Motion Alert` `A motion is detected at %calendardate% %time24%`

This will produce a message that would tell...
A motion is detected at 23/6/2014 14:07

Syntax of judo mail send API call...
judo mail send <from> <to> `<subject>` `<body>`

Read more about functions & judo API

To avoid signaling you every time that motion is detected you can use %whereami% function within evaluation which is explained in this complete example of security system.

The bottom line is that we can produce a variety of asynchronous operations that would be driven by received serial data.

Tuesday, February 26, 2013

Instruction Set anatomy

An instruction set is a collection of actions that has 3 basic forms and cast as follows.

Launcher
Launchers allow modularity. A launcher is responsible to execute third party programs and making API calls against the framework. If any of the processes above has a returning output, then its associated to the final synthesis.
Third party programs are invoked with dot-slash (./) and API calls with the judo keyword.
 


IMPORTANT: Use with cause the dot-slash (./) method if you want to avoid deadlocks. It instructs the process component to wait indefinitely for the associated process to exit. In case of the example above with notepad, the process will completed when notepad will terminated. Purpose of this action is the expandability via custom scripts and programs that does a job, give an output and finally terminated.

Example in steps...

A simple shell script that returns 'john'


The launcher


The invoke method


Result of the launcher



Result of the method


In the above example we create a launcher of a program that returns a value in order to reproduce a new instruction set that also contains additional information. We can bypass this process if we just want to launch a program and not use its value for reproduction. Since everything is instruction sets, this can be achieved by a single task.


However run-calc cannot be called by another instruction set.

When you try to execute a program that takes arguments, you should use single or back quotes (' or `) to split the statement. It doesn't matter if the arguments contains double quotes (").
Syntax:
./'program.exe' '<arguments> "<arguments with quotes>"'
Example:
./'ffmpeg' '-t 00:00:20 -i "http://<cam ip>:<port>/videostream.asf?user=admin&pwd=xxx" "/home/%user%/Videos/IP-Cam/cam-%calendarday%-%calendarmonth%-%calendaryear%_%hour%-%minute%.asf"'

Event

Events are very convenient because you can make multiple calls with a single command. This could be a sequence of different instruction sets, functions or API calls delimited by semicolon and can be triggered by another instruction set container like this...

%~><event handler id>%
In this particular example %~>demohandler%


To view events, go to terminal tab and type...
judo event list

Final Synthesis
A command (demo) is a sentence consisted by plain text, function calls and/or launchers. A launcher must be invoked by asterisk (*) token which it represents a pointer to the launcher.


Tip: You can have a number of instruction sets with the same name. Thus will give us the ability to trigger a sequence of events with ascending order.
Update: Use events instead for a more convenient way.


If instead of the (dummy) notepad example we are triggering a program or a script that has a returning value, then the wildcard *test will be replaced by it and associated to the final output. For example, if we request a sensor value from the microcontroller then the result should be synthesized like...

The temperature is <value returned from *temp>. This is a demo. j.am.... has launched something that returns a value.

Check this post to see an example in action.

To view instruction sets, go to terminal tab and type...
judo inset list

Evaluation
Another feature we can include to expand functionality is the evaluation function. This allows us to evaluate one or more expressions and act accordingly.

In the next step, we create a simple notification when evaluation failed. Category and other fields are not essential since in this case we need just a notifier


Evaluate %day% function against string "Monday"


Test result


Indicators
Indicators used within an instruction set when we need to call a launcher or an event handler. Wildcards used by the framework are...

Asterisk (*) pointer to a launcher or just a reflection of another Instruction Set.

%value% represents an internal function call.

%~>value% represents an event handler.

Essential Resources

Built-in finctions and API