Official website

Thursday, August 18, 2016

Consuming RESTful data, create widgets and more

A common way to offer server-generated data to browsers, so that it can be used in client-side JavaScript is by formatting the data as JSON, and making it accessible through its own URL. A web server that respects itself, even a lightweight like Jubito, should conformed with these standards.

Until now, the core of Jubito was loading data from the server using a HTTP GET request over jQuery.get(). The return type was a simple html. In fact, still used and applied when mode is set to html (i.e. http://localhost:8080/www/?cmd=<commands>&mode=html). By default is text, or by setting mode to text. In case of html, the only element presented is the '<br />'. The main "disadvantage" is that there is no object to handle and each command need its own call, or a manipulation of the result in case of multiple commands (e.g. splitting the breaks '<br />').

In this post, I'm going to present native APIs for consuming data from the framework and the web. That way we'll be able to customize Jubito by creating widgets and UIs.

Before we begin, let's do some REST style examples from the browser in order to understand the behavior. Uri has a typical structure and addressed like this:
http://<host>:<port>/www/?cmd=<sequence of commands as parameters delimited by ampersand>&<mode=json> 
e.g.: http://localhost:8080/www/?cmd=judo%20serial%20state%&%judo%20server%20state&%whereami%&%whoami%&mode=json


Explaining the functionality of each command:
judo serial state is an API call that returns the state/status of the serial port.
judo server state is an API call that returns the state/status of the web server.
%whereami% is a built-in function that returns the user status.
%whoami% is a built-in function that returns the user login.

Parameters in API respond:
1. Pair name - A simplified name of the requested command
2. Key - Represents the requested command
3. Value - Result of the requested command

For more information about built-in functions and API please visit Wiki

Next step is to create a jQuery.ajax() request and see how to consume the response data. It provides a simple process of fetching and parsing JSON data through Ajax. An ideal and straightforward way to achieve our goal for tailor made widgets and UIs.

Sample HTML:
<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8" />
  <title></title>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script> 
 </head>
 <body>
  <script type="text/javascript">
   $(document).ready(function() {
    getData();
   });
   
   setTimeout (function () {
    $("#data").empty();
    getData();
   }, 10000);
   
   function getData () {
    $.ajax({
     type: 'GET',
     contentType: 'application/json; charset=utf-8',
     dataType: "json",
     // requested built-in functions: %whereami% %whoami% %todayconditions% %todaylow% %todayhigh% %about%
     // request on judo API: judo server state
     // wiki https://github.com/jambelnet/janet-framework/wiki
     // uri form: <host>:<port>/www/?cmd=<sequence of commands as parameters>&<mode=json>
     url: "http://localhost:8080/www/?cmd=%whereami%&%whoami%&%todayconditions%&%todaylow%&%todayhigh%&judo%20server%20state&%about%&mode=json",
     }).done(function (data) {
      var template = 'Status: ' + data.whereami.Value + '<br/>User: ' + data.whoami.Value + '<br />';
      template += 'Conditions: ' + data.todayconditions.Value + '<br />';
      template += 'Low: ' + data.todaylow.Value + 'C&deg;<br />';
      template += 'High: ' + data.todayhigh.Value + 'C&deg;<br />';
      template += 'Server status: ' + data.judo_server_state.Value + '<br />';
      template += 'About: ' + data.about.Value + '<br />';
      
      $("#data").append(template);
     }).fail(function() {
      alert( "Oops!" );
     });
    }
  </script>
  
  <pre id="data"></pre>
 </body>
</html>
http://hilite.me/

The sample above will serve a simple page with data displayed and refreshed every 10 seconds:


Another powerful feature which you may find interesting, is the HTTP GET request supported by the API. It provides raw data from any endpoint.
judo http get <endpoint>


An example of its use can be found here on how to send and read data from RaZberry Z-Wave controller.

So, to recap, there is a lot of new things to expect, but till then, you should probably start honing your skills and finally create your own UI or a widget to the existing.


I tried to describe this post as much as possible less technical, in order to be understood by beginners.

Friday, June 17, 2016

Open Weather Map API support

Recently, Yahoo change its API and forcing everyone to use OAuth 1.0 in order to access its data. You may experience empty weather info to Jubito's front-end, as well null responses from relational functions, such %todayconditions%, etc.

I decide to implement the new functionality with openweathermap.org API as the weather data source, which I found it more simple and clear.

So, let's see what you have to do.

1) Register and get your API key
2) Expand Settings and go to Weather->Setup
3) Paste the url you get including your APPID as a parameter, i.e.:
http://api.openweathermap.org/data/2.5/forecast/city?id=524901&units=metric&APPID={APIKEY}


You're all set. Now you can use some of the old functions, plus, the new ones for humidity and pressure. Find all the function set in GitHub wiki.

Now your dashboard should look like this:


Tuesday, January 5, 2016

Special thanks to Hackaday members! [ Part II ]

Indeed Hackaday. Jubito is and always will be, AWESOME!

In 2014 I was grateful to the hackaday members. Once more, I want to pay my respects to all of you out there who support Jubito.

It is the best gift I could get for 2016 and, as the note indicates, I'll wear it with pride!

Happy new year!



Wednesday, June 3, 2015

JubitOS-Z: Operating System for the Internet of Things

JubitOS-Z is a free Operating System (OS) for the Internet of Things (IoT). A single image that convert your Banana Pi or BPi-R1 to a inexpensive home automation hub.

The combined power of RaZberry and Jubito brings together the most cutting edge technologies like Z-Wave and Arduino. Regardless of whether you are a beginner, an experienced maker or a professional this software will let you transform your house into a self-regulating mechanism at an extremely low budget. No additional hub is required.

Furthermore you can install Kodi, ownCloud, and much more for enhanced home center experience. Unlike any other proprietary product, it is designed with open technologies. Now, privacy is in your hands. No registration, no dependency on cloud-based services.

Help JubitOS-Z to evolve.



Tuesday, May 19, 2015

Inexpensive Z-Wave gateway using a Banana Pro and a RaZberry daughter card

Lately Jubito grows its family by contributions of individuals and vendors and I thank them in public each time I make a reference. More details in social networks e.g.: facebook.

Every piece of hardware I received has an interesting aspect that opens a new challenge to the Jubito ecosystem. For example, Z-Wave integration. An interesting technology, but still, a little bit expensive.

While I'm studying the Z-Way JSON API that allows to execute commands on server side using HTTP GET/POST requests, I'd like to share some early developments for those who want to learn the basics and for the adventurous. In this post I will deal with the RaZberry module by Z-Wave.me on a Banana Pro.

Since I currently owned only one device (Fibaro wall plug) I will focus on SwitchBinary Command Class (0x25/37). The Switch Binary Command Class is used to control all actuators with simple binary (on/off) switching functions, primarily electrical switches.

Those who have experience with the module will probably have a complete understanding of what I'm talking about.

But let's take a look at some methods. The command to execute is taken from the URL. All functions are executed in form:
http://YOURIP:8083/<URL>

  • http://localhost:8083/ZWaveAPI/Run/controller.AddNodeToNetwork(1) - Start inclusion [1].
  • http://localhost:8083/ZWaveAPI/Run/controller.AddNodeToNetwork(0) - Stop inclusion.
  • http://localhost:8083/ZWaveAPI/Run/controller.RemoveNodeFromNetwork(1) - Start exclusion [1].
  • http://localhost:8083/ZWaveAPI/Run/controller.RemoveNodeFromNetwork(0) - Stop exclusion.
  • http://localhost:8083/ZWaveAPI/Run/devices[n].SendNoOperation - Refresh device list.
  • http://localhost:8083/ZWaveAPI/Run/devices[n].instances[0].SwitchBinary.Set(value) - Binary values accept 0-99 for switching off and 255 for switch on.
  • http://localhost:8083/ZWaveAPI/Run/devices[n].instances[0].SwitchBinary.data.level.value - Get the state of the device (true->on, false->off).
  • http://localhost:8083/ZWaveAPI/Run/devices[n].instances[0].Meter.data[s].val.value - Measures the amount of electrical energy in kWh that was consumed.
  • http://localhost:8083/ZWaveAPI/Run/devices[n].data.givenName.value='<A new name>' - Rename a device [2].

[1] You can include devices by pressing the 'Inclusion' button. This turns the controller into an inclusion mode that allows including a device. A led on the controller indicates this status. The inclusion of a device is typically confirmed with a triple press of a button of this particular device. However, please refer to the manual of this particular device for details how to include them into a Z-Wave network. The inclusion mode will time out after about 20 seconds or is aborted by pressing the 'Inclusion' button again.
The same applies for the 'Exclusion'.



[2] Rename a device:


Use <lock></lock> tags when you want to bypass parser and pass a URI with blank spaces as one argument.

To create an HTTP GET method as an Instruction Set for alternative use, you can move to Instructions->Add New Launcher and put your getter there. This will allow you to invoke a Z-Wave function into another Instruction Set. You can search in this blog for common actions, but I will come back later with analytical article (*).


You can review the whole object in real time to reveal all the available functions but I won't deepen on the data model -yet [ http://localhost:8083/ZWaveAPI/Data ]:


To have a human readable tree view, copy and paste the JSON object to an editor, such www.jsoneditoronline.org.


List of available devices [ http://localhost:8083/ZWaveAPI/Run/devices ]:


Let's stand here and see some examples on Jubito's side.
Jubito has a native API for HTTP GET method i.e.: judo http get <Request-URI>.

Try any of the above operations from the terminal.
Examples:
  • judo http get http://localhost:8083/ZWaveAPI/Run/devices[n].data.givenName.value - Gets device name.
  • judo http get http://localhost:8083/ZWaveAPI/Run/devices[n].instances[0].commandClass[37].Set(255) - This will switch on the plug. It is equivalent to http://localhost:8083/ZWaveAPI/Run/devices[n].instances[0].SwitchBinary.Set(255) or .Set(0) to switch off.


That was a quick introduction to the Z-Way API. Before you get confused, Jubito comes with a simple interface that implements the basics like, inclusion, exclusion and list of available devices with their actions (on/off), including some additional information.
While is still beta, I won't add a link on the menu button yet, but you can navigate to z-index.html:
http://<host>:<port>/www/z-index.html


Please make sure you have the latest version [0.2.8.299]:


(*) Let's consider this post as the first part of a Z-Wave session. In future articles I will present ways, on how to use a specific function, on a custom Instruction Set, and how these can interact and expand functionality and logic by other mechanisms, including evaluations and schedules.

Monday, April 20, 2015

Lemaker challenge

One more honor for Jubito!
Jubito passed the maker challenge for a Banana Pro by presenting JubitOS.

Winning items:
  • Banana Pro
  • 7 inch Banana Pro Touch LCD With HDMI VGA AV Screen Touch Display Module For Banana Pro 1024x600


Thanks once more for your support.

Update: Items received. Thank you LeMaker!

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.