Official website

Showing posts with label evaluation. Show all posts
Showing posts with label evaluation. Show all posts

Wednesday, March 18, 2015

Wi-Fi access control using ping methodology

The other day I was returning home with both my hands occupied. While I was standing at the door I realized that I spent some time before I passed the card to the reader, unlocked and got inside. It was frustrating and clear that the RFID access control wasn't an efficient way for that task and had to be replaced with a smarter solution.

I started researching the internet for a long range RFID system that would allow me to check-in till I unlocked the door and therefore "sense" my presence and perform predefined actions like, change my status to present, turn on assistive light, bypass security camera, enable some schedules, etc. Unfortunately I realized that such systems are a little bit expensive for my taste.

Then I started to imagine a different radio approach. In the past I was using methods like geo location or bluetooth discovery but that also had drawbacks, i.e. GPS and data should be enabled, Jubito app as well, range limitations and so on. The obvious way was to use the WiFi network. The acknowledgement would be made with a continuous scan of my cellphone's IP address combined with the evaluation of my status. The ping method I had suppressed and undocumented took its place at last.

So let us continue and explore how it is done:

Step 1: Create a pinger. Go to Control Panel->Add New Launcher and type:

judo ping [host], in my case judo ping 192.168.1.95


Note: (Fixed) If ping always returns one state, it's because, in order to to send ICMP packets from linux you need root privileges. So if you determine that kind of behavior, try run jubito-server as root.

You can do an optional debugging from the terminal.


Step 2: Evaluation of ping result and user status. Control Panel->Add New Evaluator and type:

{ evalBool("*pinger"=="True" && "%whereami%"=="absent"); check_me_in ;  ; }  { evalBool("*pinger"=="False"  && "%whereami%"=="present"); check_me_out ;  ; }


check_me_in, check_me_out Instruction Sets explained here.
Find out more on evaluation.

Step 3: Create a schedule that calls the evaluation every two and a half seconds (2500ms). Use with caution and experiment to find what it suits you. If you experience any problems with that time span, try to increase it.
Once again Control Panel->Scheduler->Add New.


That was it. Disable/Enable your WiFi to test.
So far it's the most convenient way of all I've tried before. Sometimes the simplest and most effective approach is what is required.

Update: While I spent some time with the ping check-in/check-out methodology, I realize that it's not a trustworthy solution to ping phones, due to its limitations, like, battery saving, etc, unless you set WiFi sleep policy to "Never". On the other hand, devices like routers or computers, which their always connected, behaves well.

Bottom line, use cases may vary. You can perform individual tasks based on specific IP's. For example, check if a router responds to ping, else send an email alert and turn off and on its power to reset.

Monday, December 8, 2014

The power of reflection

In this post we've explained a scenario that consisted by a number (3) of alternative responses. Someone might consider, what if I want to use the response or some other action, like evaluation, to another activity? Should I make duplicates or a number of responses for each one of them? The answer is no. This can be solved by creating the response or some action as a launcher. A launcher creates two instances. One that holds the action and the other the reflection. The reflection is indicated by asterisk symbol.

For example, if I create a new launcher 'demo_launcher' that holds 'Hello %user%' as action, then the system will create:

1. *demo_launcher: Hello %user%
2. demo_launcher: *demo_launcher

When 'demo_launcher' is called the response will look like this...

Hello john (where john the system login. Check Built-in functions and API for more info)

Now, from a different Instruction Set that returns for example the user status, *demo_launcher can be invoked like this..

get_user_stat: *demo_launcher. Your status is set to %whereami%.

which will return...
Hello john, your status is set to present.

I think it's a very straightforward methodology and will become a standard in the future versions.

Screenshots are from the development version which is not yet available. However the functionality remains.


Of course these actions can be applied to any system object, such the evaluator.


Chain reaction behind the scenes.


Launchers are extremely versatile. You can combine anything that supported from the framework in a single action.
So, the verdict is that if you want a complex Instruction Set it is wise first to create launcher components and then mixed in a single one.

You can review a complex AppConfig.xml configuration file.

Sunday, November 30, 2014

Set up a Gmail notifier

After setting up your gmail account, here's the post to show you how to use the %gmailcount% function to create a gmail notifier.

Go to Control Panel/Mail/Setup/Gmail


Type your username and your password and hit save.


Now we need to make a few scenarios. For instance when emails are more than one then respond with the number of them and so forth. But before we get into that, first we need to create the responses.

Go to Instruction Sets menu, hit Add New Instruction Set Add New Launcher and follow the screenshots. [ Update: For a more efficient way to create responses please read this post. ]

No new messages.
 You have, 1, unread message to your g-mail inbox.
You have, %gmailcount%, unread messages to your g-mail inbox.

Now we have to apply the logic we're talking about in a new Instruction Set.


In the action field copy/paste the following evalBool function...

{ evalBool(%gmailcount% <= 0); no-messages; ; } { evalBool(%gmailcount% == 1); gmail-one; ; } { evalBool(%gmailcount% > 1); gmail-count; ; }


One of each conditions will be evaluated and trigger the corresponding reply.

Finally we can make a daemon with the Scheduler, to perform checks every 5 minutes. From Scheduler menu hit Add New and type a name, select repeat in the period drop down, time in milliseconds e.g. 300000 for 5 minutes and action the Instruction Set that calls the evalBool function i.e. gmail. To avoid getting 'No new messages' every time, make a new Instruction Set that missing the no-messages evaluation.


Thursday, July 3, 2014

Arduino MQ-2 Smoke/LPG/CO Gas Sensor Module

In this tutorial we will make a gas leakage detecting system with MQ-2 gas sensor which is sensitive to LPG, i-butane, propane, methane, alcohol, Hydrogen and smoke.

What we need:
Wire module to arduino and upload the sketch.



Alternatively use codebender
Open serial monitor and type 'smoke', 'co' or 'lpg'. Each of these commands will return concentrations of smoke, carbon monoxide and liquefied petroleum gas. You can read more details here.

You can define your own commands by changing the lines below...


After that we will use those values to detect for any king of leakage. We will make a new schedule that will run every 60 seconds and perform evaluation.

As usual please make sure you have properly configure arduino serial port and then enable it.


Let's get dirty
First we need to make a new launcher to retrieve smoke values for this particular example. Go to Instruction Sets menu and press Add New Launcher. Enter a name (handler) and type the following command...

judo serial send smoke


Then our notification launcher using judo mail send API command.
Syntax: judo mail send <from> <to> `<subject>` `<message>`

judo mail send xxx@gmail.com yyy@gmail.com `smoke alert` `Smoke detected *getsmoke ppm`


And finally the Instruction Set that handle the evaluation function. Press Add New Instruction Set, type a name and the following command...

{ evalBool(*getsmoke > 0); sendmailonsmoke; ; }

Note: Zero value can be changed with one of your choice you consider dangerous.


The above action will call the first launcher and get a value from the sensor, then will evaluate if it's greater than zero, if the statement is true the second launcher will be triggered and send us an email notification. Read more about evaluation function.

Now we are ready to create a 60 seconds schedule for task to be repeated. Click on scheduler and press Add New. In the popup window enter a name, period <Repeat>, interval in milliseconds <60000> and the 'smokeschedule' instruction set we had create in order to call the evaluation procedure.


This is it, once we save the schedule it will be activated. You can do the same way for gas (co) and perform a test with a lighter.

Another approach is to trigger an event from the sketch like this example.
You can accomplish that by change the lines below...

void loop(void) {
 
  if (MQGetGasPercentage(MQRead(MQ_PIN)/Ro,GAS_SMOKE) > 500)
    Serial.println("HazardousSmokeDetection");



When the measurement exceeds the value we have set, the 'HazardousSmokeDetection' will be printed to serial port and cause Jubito to execute the corresponding event.

Thursday, February 20, 2014

Contains method on evalBool statement

evalBool statement is excellent when you need to apply logic. To provide some more flexibility I added a new feature in version 0.2.1 of libJanet.dll. The new method called contains and is represented by ~>. To check framework version, go to terminal tab and type %about%.
The example below will evaluate if the word "Rain" is included in the result of %todayconditions% function (more on functions and weather feed configuration).

Evaluation
Response for true part
Response for false part
Debug

You can also add some stuff on final synthesis for "You don't need your umbrella" like "Today conditions is %todayconditions%. You don't need your umbrella!" which will result "Today conditions is Sunny. You don't need your umbrella!".

Wednesday, February 20, 2013

Evaluation

Evaluation of an expression within Instruction Set allows you to add logic and extend the functionality.

Function

  evalBool: Returns one of two states, depending on the evaluation of an expression.

Parameters

  Expression
     Required. Boolean. The expression you want to evaluate.
  True Part
     Required. Type: Instruction Set. Called when expression evaluates to True.
  False Part
     Required. Type: Instruction Set. Called when expression evaluates to False.

Syntax

  { evalBool(expression); <true part>; <false part>; }

Relational & Conditional Operators

 equal to: ==
                i.e. (x == y)
                i.e. ("x" == "y")
                * String comparison require quotes
 not equal to: !=
                i.e. (x != y)
                i.e. ("x" != "y")
                * String comparison require quotes
 greater than: >
                i.e. (x > y)
 less than: <
                i.e. (x < y)
 greater than or equal to: >=
                i.e. (x >= y)
 less than or equal to: <=
                i.e. (x <= y)

 conditional AND: &&

                i.e. (x > 10 && x < 20)
 conditional OR: ||
                i.e. (x == 10 || x == 20)

 contains (Supported on ver. 0.2.1 of libJanet. To check your version, go to terminal tab and type %about%)

                i.e. (this is a test ~> is a)
                i.e. (%todayconditions% ~> Sunny)

Example

  { evalBool(*getTemp > 30);  foo1; foo2; }

The above example can be translate like...

If temperature is greater than 30 degrees then turn on a fan (foo1) else turn it off (foo2)

foo1, foo2 represents Instruction Set names. You can have more than one or none at any part.