Official website

Showing posts with label functions. Show all posts
Showing posts with label functions. Show all posts

Wednesday, June 14, 2017

Dynamic DNS update support for No-IP

My personal choice of a Dynamic DNS service is No-IP.

https://www.noip.com/
No-IP was one of DynDNS’s biggest competitors in the free dynamic DNS market, and now that DynDNS is gone they’re in a good position to snatch the crown for themselves. In fact, the two services are only one year apart in age (DynDNS launched 1998, No-IP launched 1999).
For a free account, you’ll get three subdomains on a single domain choice, but these subdomains will never expire as long as you confirm activity every 30 days. You also get port forwarding and URL forwarding, which can be useful depending on your use case. [ source ]
The story started when I received a new router from my ISP that didn't support No-IP. At that particular moment I decided to create a simple implementation of No-IP API into Jubito.

Now Jubito has a built-in function (%publicip%) that return the public IP address and a judo API that provides an update method for our hostname.

Let's proceed on how to configure your No-IP hostname.

In the settings menu, you will find a Dynamic DNS section. Click Setup, fill your hostname, username, password and save.


Next step is to create a new launcher that call the API for update. Expand Instructions menu and click on Add New Launcher. Give a name and type the action as follows:

judo noip update


We are now ready to create a schedule that updates the service in a given interval. Add new schedule and follow the screenshot, where interval sets the time of check (300000ms is 5 minutes) and action is the call we did in the previous step (launcher).


That was it. You are router independent!

Monday, March 16, 2015

More effective dashboard with real time data

In order to achieve a fully dynamic front end, I started working on a widget factory. The combination of two different Instruction Sets will give us the ability to view additional real time info within a dashboard item in a bubble form.

I will proceed by doing a simple example using framework functions (%greader% or %gmailreader% and %gcount% or %gmailcount%). The first will return the headers of the message(s) and the other one will be the counter.

Go to Control Panel->Add New Launcher and follow the screenshots...



Now we'll create a new dashboard item that includes both of the above.
Navigate to Control Panel->Add New Instruction Set


Scroll down to Add to Dashboard and fill Category, Header, Thumbnail (optional) and Reference field.


Save it and return to the Dashboard. You should be able to see something like that...


When you click Gmail Check you will get the response of gmail launcher.


For older Instruction Sets, edit the AppConfig.xml and add a reference attribute (ref) that points to the Instruction Set ID you want to call. For this example, gmailwidget.


You may notice temperature and humidity values as well in the screenshots. It has the same logic but first you should take a look at arduino tutorials.

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.


Saturday, July 19, 2014

Jubito android app with voice control

The new coveted feature that incorporated in the new version of jubito app (v1.2) is the speech recognition and speech synthesis. It allows us to hit the speech button and come out with a preferred command. That means that from now on your instruction set names (including launchers and events) must listed speech friendly.


Assume that we have three different Instruction Sets that give us the weather conditions. Let's say 'weather today' that consists of a set of today's conditions, 'weather tomorrow' for the day after and 'forecast' for both situations.

For the example to take effect you need to check your weather settings.

Go to Control Panel/Instruction Sets/Add New Instruction Set enter weather_today as name (id) and set the line bellow as action...

Today %todayday% in Athens, %todayconditions%, between %todaylow% and %todayhigh% degrees.


For the other two options you can use...

weather_tomorrow
Tomorrow %tomorrowday% in Athens, %tomorrowconditions%, between %tomorrowlow% and %tomorrowhigh% degrees.

forecast
Today %todayday% in Athens, %todayconditions%, between %todaylow% and %todayhigh% degrees. Tomorrow %tomorrowday% in Athens, %tomorrowconditions%, between %tomorrowlow% and %tomorrowhigh% degrees.


Optionally fill description and any other field you want in order to be accessed from the dashboard.


The % enclosures represents the built-in functions that are responsible to translate the retrieved weather data to values. Find more weather functions.

Now open the app and press speech button. The approach is very simple, we just speak the instruction set id (name) and its posted to the server. Once it acknowledged we'll be able to hear the response (from speech synthesis) or see any kind of action that use this example, for instance turn on an appliance. The only limitation we should conform is that we need to replace blank spaces with underscores. Update: Latest versions of Jubito, automatically replace blanks with underscores.


Alternatively before create an instruction set you can perform a preferable command and see how it prints out.

Enjoy!

Video demo

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!".

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

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.

Tuesday, February 19, 2013

Built-in functions and API

Please visit GitHub Wiki
From now on updates will take place on jaNET Framework GitHub Wiki.

Update applies to jaNET framework version 0.2.2+ 

Built-in functions and API commands are described below and it used for instruction set synthesis.
After you create a new InstructionSet you can debug it and see the response from terminal.



You can also debug a launcher (using judo API) before you make the call from Instruction Set. In demonstration below, I'm going to use the 'judo serial send' API to send 'temp' command to the serial port where arduino is connected. This action will automatically fetch the arduino response when it's available.




Once we have test the launcher we can proceed with a custom Instruction Set. Notice the asterisk (*) indicator in front that remarks the launcher.



See also Instruction Set anatomy.

Functions

    User and Greetings
  • %user% %whoami% - return user login
  • %daypart% %partofday% - return the current part of the day (morning, noon, evening, afternoon, night, midnight)
  • %salute% - return human greetings e.g.: good morning, good evening and good afternoon

    Check-in/Check-out
  • %usercheckin% %checkin% - change user status to true
  • %usercheckout% %checkout% - change user status to false
  • %whereami% - return the user status (absent/present)

    Weather (retrieve information from yahoo web service http://developer.yahoo.com/weather)
  • %todayday% - return current day
  • %todayconditions% - return current day conditions http://developer.yahoo.com/weather/#codes
  • %todaylow% - return current day low temperature
  • %todayhigh% - return current day high temperature
  • %tomorrowday% - return the day after
  • %tomorrowconditions% - return the day after conditions
  • %tomorrowlow% - return day after low temperature
  • %tomorrowhigh% - return day after high temperature

    Localization
  • %day% - return system day i.e. Sunday
  • %date% - return current system date i.e. November 5
  • %calendarday% - return system day i.e. 5
  • %calendarmonth% - return system month i.e. 11
  • %calendaryear% - return system year i.e. 2013
  • %calendardate% - return system date in d/m/yyyy format
  • %time% - return system time
  • %time24% - return system time in 24 format (hh:mm)
  • %hour% - return system hour i.e. 17
  • %minute% - return system minute

    Net
  • %pop3count% - pop3 unread message count
  • %gmailcount% - gmail unread message count
  • %gmailheaders% %gmailreader% %gheaders% %greader% - gmail headers, sender information and subject

    System
  • %mute% - disable speech synthesis
  • %unmute% - enable speech synthesis
  • %cls% %clear% - clearing the console
  • %quit% %exit% - terminate application
  • %about% %copyright% - return framework version and copyright information

API

(*) From the terminal tab you can type judo ? for the latest / updated help.

1. Instruction Sets & Events
    1.1 Add New Instruction Set
        + judo inset add <lock>[ID]</lock> <lock>[Action]</lock>
        + judo inset new
<lock>[ID]</lock> <lock>[Action]</lock>
        + judo inset set
<lock>[ID]</lock> <lock>[Action]</lock>
        + judo inset setup
<lock>[ID]</lock> <lock>[Action]</lock]
        + judo inset add
[ID] <lock>[Action]</lock> `[Category]` `[Header]` `[Short Description]` `[Long Description]` `[Thumbnail Url]`
        + judo inset new [ID] <lock>[Action]</lock> `[Category]` `[Header]` `[Short Description]` `[Long Description]` `[Thumbnail Url]`
        + judo inset set [ID] <lock>[Action]</lock> `[Category]` `[Header]` `[Short Description]` `[Long Description]` `
[Thumbnail Url]`
        +
judo inset setup [ID] <lock>[Action]</lock> `[Category]` `[Header]` `[Short Description]` `[Long Description]` `[Thumbnail Url]`
    1.2 Remove Instruction Set
        + judo inset remove <lock>[ID]</lock>
        + judo inset delete <lock>[ID]</lock>
        + judo inset del <lock>[ID]</lock>
        + judo inset kill <lock>[ID]</lock>

    1.3 List Items
        + judo inset list
    1.4 Add New Event Handler
        + judo event add [ID] <lock>[Action]</lock>
        + judo event new [ID] <lock>[Action]</lock>
        + judo event set [ID] <lock>[Action]</lock>
        + judo event setup [ID] <lock>[Action]</lock>

    1.5 Remove Event Handler
        + judo event remove [ID]
        + judo event delete [ID]
        + judo event del [ID]
        + judo event kill [ID]

    1.6 Delay Between Actions
        + judo sleep [timeout in ms]
        + judo timer [timeout in ms]

    1.7 List Items
        + judo event list

2. Mail
    2.1 Smtp Settings
        + judo smtp add [host] [username] [password] [port] [ssl]
        + judo smtp setup [host] [username] [password] [port] [ssl]
        + judo smtp set [host] [username] [password] [port] [ssl]
        + judo smtp settings

    2.2 Pop3 Settings
        + judo pop3 add [host] [username] [password] [port] [ssl]
        + judo pop3 setup [host] [username] [password] [port] [ssl]
        + judo pop3 set [host] [username] [password] [port] [ssl]
        + judo pop3 settings

    2.3 Gmail Settings
        + judo gmail add [username] [password]
        + judo gmail setup [username] [password]
        + judo gmail set [username] [password]
        + judo gmail settings

    2.4 Send
        + judo mail send [from address] [to address] `[subject]` `[message]`

3. SMS
    3.1 Settings
        + judo sms add [api id] [username] [password]
        + judo sms setup [api id] [username] [password]
        + judo sms set [api id] [username] [password]
        + judo sms setings

    3.2 Send
        + judo sms send [phone number] [message]

4. Scheduler
    4.1 New Schedule
        + judo schedule add [name] [{single day: e.g.Monday} {d/m/yyyy} {daily} {workdays} {weekend}] [hh:mm] [{instruction set} {verbal notification}]
        + judo schedule new [name] [{single day: e.g.Monday} {d/m/yyyy} {daily} {workdays} {weekend}] [hh:mm] [{instruction set} {verbal notification}]
        + judo schedule set [name] [{single day: e.g.Monday} {d/m/yyyy} {daily} {workdays} {weekend}] [hh:mm] [{instruction set} {verbal notification}]
        + judo schedule setup [name] [{single day: e.g.Monday} {d/m/yyyy} {daily} {workdays} {weekend}] [hh:mm] [{instruction set} {verbal notification}]
        + judo schedule add [name] [{repeat} {timer} {interval}] [interval in ms] [{instruction set} {verbal notification}]
        + judo schedule new [name] [{repeat} {timer} {interval}] [interval in ms] [instruction set} {verbal notification}]
        + judo schedule set [name] [{repeat} {timer} {interval}] [interval in ms] [instruction set} {verbal notification}]
        + judo schedule setup [name] [{repeat} {timer} {interval}] [interval in ms] [instruction set} {verbal notification}]

    4.2 Remove Schedule
        + judo schedule remove [name]
        + judo schedule delete [name]
        + judo schedule del [name]

    4.3 Disable Schedule
        + judo schedule disable [name]
        + judo schedule deactivate [name]
        + judo schedule stop [name]
        + judo schedule off [name]

    4.4 Enable Schedule
        + judo schedule enable [name]
        + judo schedule activate [name]
        + judo schedule start [name]
        + judo schedule on [name]

    4.5 Remove All Schedules
        + judo schedule remove-all
        + judo schedule delete-all
        + judo schedule del-all
        + judo schedule cleanup
        + judo schedule clear
        + judo schedule empty

    4.6 Disable All Schedules
        + judo schedule disable-all
        + judo schedule deactivate-all
        + judo schedule stop-all
        + judo schedule off-all

    4.7 Enable All Schedules
        + judo schedule enable-all
        + judo schedule activate-all
        + judo schedule start-all
        + judo schedule on-all

    4.8 List Actives [ Names ]
        + judo schedule active
        + judo schedule actives
        + judo schedule active-list
        + judo schedule active-ls
        + judo schedule list-actives
        + judo schedule ls-actives

    4.9 List Inactives [ Names ]
        + judo schedule inactive
        + judo schedule inactives
        + judo schedule inactive-list
        + judo schedule inactive-ls
        + judo schedule list-inactives
        + judo schedule ls-inactives

    4.10 List All [ Names ]
        + judo schedule names
        + judo schedule name-list
        + judo schedule name-ls
        + judo schedule list-names
        + judo schedule ls-names

    4.11 List Actives [ Details ]
        + judo schedule active-details
        + judo schedule actives-details
        + judo schedule active-list-details
        + judo schedule active-ls-details
        + judo schedule list-actives-details
        + judo schedule ls-actives-details

    4.12 List Inactives [ Details ]
        + judo schedule inactive-details
        + judo schedule inactives-details
        + judo schedule inactive-list-details
        + judo schedule inactive-ls-details
        + judo schedule list-inactives-details
        + judo schedule ls-inactives-details

    4.13 List All [ Details ]
        + judo schedule details [name (optional)]
        + judo schedule list [name (optional)]
        + judo schedule ls [name (optional)]
        + judo schedule status [name (optional)]
        + judo schedule state [name (optional)]


5. Socket Communication
    5.1 Start Service
        + judo socket start
        + judo socket enable
        + judo socket on
        + judo socket open
        + judo socket listen

    5.2 Stop Service
        + judo socket stop
        + judo socket disable
        + judo socket off
        + judo socket close

    5.3 Status
        + judo socket status
        + judo socket state


6. Web Server
    6.1 Start
        + judo server start
        + judo server enable
        + judo server on
        + judo server listen

    6.2 Stop
        + judo server stop
        + judo server disable
        + judo server off

    6.3 Create/Change Login
        + judo server login [username] [password]
        + judo server cred [username] [password]
        + judo server credentials [username] [password]

    6.4 Status
        + judo server status
        + judo server state


7. Serial Port
    7.1 Open
        + judo serial open [port (optional)]
    7.2 Close
        + judo serial close
    7.3 Send Command
        + judo serial send [command]
    7.4 Listen/Monitor
        + judo serial listen [timeout in ms (optional)]
        + judo serial monitor [timeout in ms (optional)]

8. Help
    8.1 Preview All
        + judo help
        + judo ?

    8.2 Preview Specific Category
        + judo help [help keyword]
        + judo ? [help keyword]


(*) Brackets are mandatory when place a sentence as one argument.
(**) <lock>parser protected document</lock> Lock tags used to bypass parser.
(***) Help Keywords: inset, event, mail, sms, schedule, socket, server, serial, help.