Official website

Showing posts with label scheduler. Show all posts
Showing posts with label scheduler. 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!

Friday, February 10, 2017

Dropbox alternative for ARM Linux and Jubito integration

Once upon a time, when a netbook (Dell mini 9) with Ubuntu was my Jubito server, I used dropbox to sync my important files, such as camera video recordings of my security system. Then I migrated to a Banana Pi and currently to Banana Pro. Both derivatives of Raspberry Pi. Unfortunately dropbox has no support or plans for ARM Linux variants. A quick solution was to use ownCloud. All went well till ownCloud client stopped syncing for a number of reasons (incompatible updates/upgrades,etc).

I've made an effort to find out a solution that suits me and finally rclone came up.
Rclone is a command line program that sync files and directories to and from, and it comes with support of various storage systems (google drive, dropbox, Microsoft One Drive and more). My desirable choice is dropbox, so,  I started getting my hands wet.
I read of course that I would just have to perform the sync operation manually when I wanted things up to date but it didn't bother me in first place. I'll explain the reason afterwards.

Let's proceed to step by step process.

Download rclone to your home directory, unzip it and move forward to next paragraph, or go through command line.

cd
wget -c http://downloads.rclone.org/rclone-v1.35-linux-arm.zip
unzip rclone-v1.35-linux-arm.zip
Rename the directory for sake of simplicity
sudo mv /home/<user>/rclone-v1.35-linux-arm /home/<user>/rclone
cd rclone
Change file access permissions
sudo chmod 755 /home/<user>/rclone/rclone

Follow installation and configuration instructions. The guide use a generic name for the remote target, called remote. As I chose dropbox installation, I will call it dropbox instead.

After installation finishes try to synchronize your source with the destination. In this case the destination directory will be called jubito. Open a terminal and type:

./rclone sync /home/<user>/<source> dropbox:jubito

Time for Jubito integration. I will present three cases. Making a scheduled job, sync on-demand and trigger on event. Before we proceed we have to create invocation to rclone. We need a launcher that point to the action above.

Go to Settings->Instructions->Add New Launcher. On popup give as name "sync" and action like this:

./'/home/%user%/rclone/rclone' '/home/%user%/<source>
dropbox:jubito'



where <source> your current installation (in my case /home/john/bin), and press save. Dot slash (./) is a native implementation similar to Linux and Unix to execute a compiled program and %user% is a built-in function that gets the logged in username (alternatively, hard-coded your user). The result, if any, can be consumed by another Instruction Set. Learn more on (incomplete) Instruction Set anatomy.
This will create a pointer to the command inside AppConfig.xml which could be used at any case (scheduled, on-demand, etc).

Calling the method from CLI:


Physical location

Dropbox location

1) Scheduled
Go to Settings->Scheduler->Add New. Enter a name, select daily routine, time (e.g. 00:00) and finally sync action. This will create a schedule that runs daily at midnight and triggers the dropbox sync.


2) On-demand
From Settings->Instructions->Add New Instruction Set. Name it "dosync" or whatever you like, select from action list the sync command we created before and press add. It will generate a *sync pointer to the sync launcher. You can put some additional text if you wish. Expand Add to Dashboard and put some info (category, header) to populate a button to the dashboard list.


Now you'll be able from menu list to press and run the sync method...

 
3) Attach to other Instruction Set
First let's make an example based on DVR system by using an IP camera example. Scenario describe operations when security breach is detected (record a video and send email alerts). To extend it with dropbox synchronization, we're going to use the sync as the third action in the sequence. So, once again add the sync launcher.

<InstructionSet id="ip-cam">{ evalBool("%whereami%" == "absent"); rec sendmemail sync; ; }</InstructionSet>

If you want to use the UI and already have the ip-cam Instruction Set, please delete it and re-create it since there is no edit mode. Else, edit AppConfig.xml and change it with the line above.

However, you can create a new ip-cam with the same condition that calls only sync method like that:

<InstructionSet id="ip-cam">{ evalBool("%whereami%" == "absent"); sync; ; }</InstructionSet>

Instructions with the same name, run in order.

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.


Friday, July 11, 2014

Arduino light sensing

In this tutorial we'll create a simple circuit that sense light using a photoresistor.

What we need:
Follow the screenshot to wire the photocell and then upload the sketch to arduino.



Alternatively use codebender
By hitting the 'light' command in the serial monitor we will get a print out of what it interprets as the amount of light in a qualitative manner. Thus is 'Dark', 'Dim', 'Light', 'Bright', 'Very_Bright'. You can change thresholds readings with values that suits your conditions.


OK, now we are ready to take advantage of the above example and make an assistive illumination system. As we already know we can capture serial messages from Jubito and trigger corresponding events. To make it happen we need to create one event handler with the name 'Dark' that will execute the 'plug-A-on' launcher of this example.

To do so, navigate to Control Panel/Instruction Sets/Add New Event Handler and enter the name and the action. When sensor submits 'Dark', the 'plug-A-on' launcher will be executed and turn on a light that is plugged to a wireless power outlet.


Notice: The above example to take effect, we need to let the loop continuous running and print out conditions than waiting for a 'light' command to be send. The modified sketch should be...

void loop(void) {

    // Light measurement
    photocellReading = analogRead(photocellPin);
    
    // We'll have a few threshholds, qualitatively determined
    if (photocellReading < 10) {
      Serial.println("Dark");
    } else if (photocellReading < 200) {
      Serial.println("Dim");
    } else if (photocellReading < 500) {
      Serial.println("Light");
    } else if (photocellReading < 800) {
      Serial.println("Bright");
    } else {
      Serial.println("Very_Bright");
    }
  }
  delay(1000);

}

But still you can use a scheduler and evaluator that applies to original sketch. Follow this article to see how you can do that.

Update
So we come back to see how we can make a running daemon with a scheduler that evaluates the light conditions.
First we need to create a launcher that executes the 'light' command we set to arduino sketch and fetch the state. Then we need a new Instruction Set that invokes it.
From the Instruction Set menu click Add New Launcher and give a name and the judo API call to send the 'light' command to the serial port.


After that create a new Instruction Set that invoke the launcher and make the evaluation with the 'Dark' condition. Type a name of your choise and the evaluation that follows...

{ evalBool("*getlight" == "Dark"); plug-A-on; ; }


The '*getlight' pointer will invoke the 'getlight' launcher and get its returning. Then it will be replaced by the condition data ('Dark', 'Dim', 'Light', etc) and proceed to evaluation. If condition is true the 'plug-A-on' launcher will be triggered, else nothing will happen.
The last thing to do to make it a runnable daemon is to create a new schedule that call the above Instruction Set within an interval.
From Scheduler menu click Add New enter a name, <Repeat> on the period dropdown, interval in milliseconds (the example use 60000ms which is 1 minute) and finally the 'evallight' Instruction Set as the action.


Video demo

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.

Tuesday, March 5, 2013

Scheduling tasks

Another important tool is the Scheduler. It can be formed as a simple notification, a hierarchy of tasks or as a daemon.

Scheduler Parameters 
Name: a schedule handler.
Date: when an action doesn't need to be repeated and removed from schedule when completed.
Or
Periodically
    Daily - action takes place every day at specific hour
    Workdays - action takes place from Monday to Friday at specific hour
    Weekend - action takes place every Saturday and Sunday at specific hour
    Specific day {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday} - action takes place from day specified at specific hour
    Repeat - a repeated action that takes place at a specified time in milliseconds
Action: a simple sentence or an instruction set call


Let's see some examples.

A simple notifier that inform us daily at 9am to take out the trash.


A daemon that check every 5 minutes for unread e-mail messages.


Corresponding Instruction Sets.




Scheduler can fulfill a number of scenarios like, wakeup call (ask me to wake up work days at 7am, tell me weather conditions, turn on the room light), automation control (turn off garden lights daily at 11pm) or check-out after 10am when I'm living for work, etc.