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.

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.

Thursday, March 5, 2015

Extracting data from JSON and XML

Web API connector is released and supports both JSON and XML response parsing. This feature opens up the possibility of connecting to a huge range of potential APIs and therefore reducing the cost for additional equipment. For example, if you want to create some tasks based on weather conditions, you can achieve that without a weather station, but by gathering information from the cloud.

In addition to this post let's do some JSON examples from Yahoo Weather API. I will also use the Code Beautify online code editor for a good human-readable representation of the response.

Step 1: Copy and Paste the endpoint URI from yahoo developer website and paste it to the editor.



Step 2: Go to Control Panel->Instructions->Add New Web Service. Address the node you want to retrieve and fill the form items (Name, Endpoint, Node Path). Notice that if the response have a tree structure, you should point the position index of your target in Node Path as seen below. By default will get the first element [index: 0].


By default some editors starts the tree viewer with root/array and then with the absolute tree structure. So, at the "Node Path" field of Jubito, ignore the above of starting path.

Step 3: Go to terminal tab and debug the new Instruction Set. If you get the value then everything went well.


Step 4: Now, let's make an interface and a scenario. Again from Control Panel->Instructions->Add New Instruction Set. Unfold the Add Action(s) and Add to Dashboard and follow the screenshot.


Save and return. Now you're able to make a call from the Dashboard screen.


Step 5: Some other things you can do, is to make a schedule to evaluate the weather and send an email notification when a specified weather acknowledgement applies. Let's take a look to the Evaluator. Once again Control Panel->Instructions->Add New Evaluator. Select the yahoo-test Instruction Set and add some additional text if you wish. As I always remind, the asterisk in front of the Instruction Set is the reflector of a value.


'Then' condition corresponds to another Instruction Set that is responsible to send mail. You can search this blog with 'send mail' keyword to see how to make one.

Step 6: Finally there all set to create the Schedule. Go to Control Panel->Scheduler->Add New. Type a name, repeat, interval at your choice (3600000ms is one hour) and select the Evaluator's Instruction Set.


This schedule will run every hour and evaluate the condition.

All of the above steps are described as a proof of concept. The use-cases may vary depending your needs.

The same logic applies also to XML. You can be advised by this post. If you find any difficulties or discover a bug, please do not hesitate to drop me a message.

Changes applied to jaNET Framework 0.2.6.555+. To check version go to terminal tab and type %about%.

Monday, February 9, 2015

JubitOS for Banana Pi

JubitOS (Jubito Operating System) is a Lubuntu based distribution for Banana Pi and is available for download. It is an out of the box compilation and it contains all the ingredients for a home automation server/hub. A native system that comes with all the dependencies required, plus some extra features that could be useful, like festival speech synthesis system and cmu_us_slt_arctic female voice package. The image is approximately 3.7GB, so, a 4GB SD card and higher is recommended.

Release Notes
JubitOS for Banana Pi (Linux kernel 3.4.103; 2015-02-09)
Default username: jubito (Caution: The user have administrative privileges)
Default password: jubitopi
  • jubito
  • mono-complete
  • festival
  • cmu_us_slt_arctic-0.95-release


Check this post for installation and extra tweaks.
To update Jubito to the latest version, download and replace extracted files to /usr/share/jubito. You can keep your configuration files AppConfig.xml, .htaccess, .scheduler, etc.


Monday, February 2, 2015

Setting up Banana Pi/Lubuntu, running and tweaking

In this post I will describe some things I did to the Banana Pi/Lubuntu in order to match my requirements for a smooth operational Jubito server, as well, fixes on some issues I've been faced.

I'll bypass the installation process on SD card because it's pretty easy.

Step 1:
Resize and expand the partition.
I'm using a 16GB SD card so when I flash the image, which is approximately 3.7GB I end up with an unmanaged partition. To make it available I did the steps that follow...
(*) Do this only right after flashing the image on the SD-Card, so if anything goes wrong you do not lose any data.

sudo fdisk /dev/mmcblk0
  • Press ‘p’ to print the partition table
  • Press 'd' to delete a partition
  • Enter '2' to choose the second partition
  • Press 'n' to create a new partition
  • Enter 'p' to select primary as partition type
  • Partition number: enter to accept 2 as default partition number
  • First sector: enter to accept default
  • Last sector: enter to accept default
  • Press 'w' to write the new partition table
Reboot to force the kernel to recognize the new partition table.

sudo reboot

After the system has come back up you still have to resize the partition.

sudo resize2fs /dev/mmcblk0p2

[ Source: http://gleenders.blogspot.gr/2014/08/banana-pi-resizing-sd-card-root.html ]

Step 2:
Use sudo apt-get update && sudo apt-get upgrade or Menu->System Tools->Software Updater to download the latest patches and updates that fix issues, like Firefox crash.

Step 3:
Change the default username (I), password (II), hostname (III) [ Source: http://banoffeepiserver.com with minor changes ]

(I) Many Linux images have a default username and password. The default username and password for the Raspbian image are 'pi' and 'bananapi' (in many of the Banana Pi Linux distributions, the default username is bananapi). It's best to change these login details so that no one else can log into your Pi.

You need to configure your Pi to boot to a command line - the following procedure won't work if you're logged into a desktop session. Once you've booted to a command line, you need to change the shell session to the root user. This is necessary because you can't modify a user account while you're logged in as that user.

exec sudo -s

Now all commands are executed as the root user. Change to a different directory than /home/bananapi:

cd /

Use the usermod command to change username of the default account.

usermod -l <newname> -d /home/<newname> -m <oldname>

When you reboot, you'll need to log in using the new username. Optionally you can change the group name.

groupmod -n <newgroup> <oldgroup>

Instructions above may damage or cause dis-behaviors. For your convenience, I suggest you to make same actions or create a new user from a controlled environment. That can be easily managed from User Settings under Menu->System Tools->Users and Groups.


(II) One of the most important things to change is the password.  Using the default password is a monumental security risk.  The default password for most Banana Pi Linux distributions is simply bananapi. Change it using the passwd command:

passwd
Changing password for john.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:


You will be prompted to enter your current password, followed by your new password twice.

(III) The hostname is the name of your server as it appears on your local network.  You may need to change the hostname if you have more than one Banana Pi on your network. You'll need to change it in two places:

/etc/hostname
/etc/hosts


The hostname is set in /etc/hostname.  This file only contains the hostname. Open it as root, and change the name.  I've change it from 'lemaker' to 'jubito'.
In /etc/hosts, there's a list of IP addresses and their host names. This file contains a table mapping IP addresses to host names.  Open it with this command:

sudo leafpad /etc/hosts

Look for an entry with IP address 127.0.1.1 lemaker, and change the host name as required.
Reboot your Banana Pi, and you should see that its host name has changed.

Step 4:
I've tried the Banana Pi in various monitors and I noticed that screen resolution doesn't fit automatically. I decided to set it up manually, by disabling the EDID auto-detection. To do so, edit the uEnv.txt file located in a small partition and mounted in Desktop and remove the EDID like this:

disp.screen0_output_mode=EDID:1280x720p50
to
disp.screen0_output_mode=1280x1024p60 (example for a non wide 15" monitor)


Step 5:
Auto login feature is necessary, if you're using Banana Pi as a standalone server with no peripherals (monitor, keyboard, mouse). When its rebooted or reset we need to restore Jubito and x11vnc server (described at Step 6) at startup without user interference. I tried the "Don't ask for password on login" from System Tools->Users and Groups->User Settings without luck. The workaround came with a lightdm hack.

Edit or create a file -if not exists /etc/lightdm/lightdm.conf and add the following content:

[SeatDefaults]
autologin-user=<YOUR USER>
autologin-user-timeout=0
user-session=ubuntu
greeter-session=unity-greeter


Step 6:
Remote desktop using the lightweight x11vnc server.

Install
sudo apt-get install x11vnc

Set password protection

mkdir ~/.x11vnc
x11vnc -storepasswd <YOUR PASSWORD> ~/.x11vnc/passwd

Create a shell script in any directory, for example in /home/<YOUR USER> and call it start-vnc.sh. This will used as x11vnc launcher.
Run leafpad leafpad ~/start-vnc.sh and paste the code below.

#!/bin/sh
x11vnc -forever -display :0 -rfbauth ~/.x11vnc/passwd


Now save and close the file.

Finally add it to LXSession configuration under Autostart tab.
Go to Menu->Preferences->Default applications for LXSession and add the line below...

lxterminal -e bash /home/<YOUR USER>/start-vnc.sh


or do the same by edit the local ~/.config/lxsession/<profile>/autostart file.
At next reboot the x11vnc server will be run.

Step 7:
Since there’s currently no build of the Dropbox sync client that runs on ARM devices and at this time I don't want to spend my time seeking for a solution, I'm going to use  the ownCloud alternative for syncing security breach videos.

Create an account to blaucloud.de and get the free plan that gives 2GB of space and then install the ownCloud client:

sudo apt-get install owncloud-client


Open the program and set your preferences. It's very easy.

I chose this service, because it does its job well. I get set up my own independent cloud-space instance on basis of ownCloud within a few minutes. They are also providing an android app that makes it more comprehensive solution, much like Dropbox.

Step 8:
With most Linux distributions special configuration for USB devices like Arduino are mostly needed, to workaround or fix common issues, when run as a normal non-root user.

First thing is to apply udev rules. To proceed you need to know vendor ID and device ID. Open a terminal and type lsusb to locate your Arduino and keep values in mind (i.e. 2341:0001).


Now create a file /etc/udev/rules.d/99-arduino.rules and paste the lines below where idProduct and idVendor values from the previous step:

SUBSYSTEMS=="usb", ATTRS{idProduct}=="2341", ATTRS{idVendor}=="0001", SYMLINK+="ttyACM%n", MODE="0666", GROUP="dialout"
SUBSYSTEMS=="tty", ATTRS{idProduct}=="2341", ATTRS{idVendor}=="0001", SYMLINK+="ttyACM%n", MODE="0666", GROUP="dialout"


Next you'll need to reload udev's rules so that they are properly applied.  You can restart your machine, or run a command like the following:

sudo reload udev

If the command above fails, try instead running:

sudo udevadm control --reload-rules
sudo udevadm trigger



You can also add yourself to the dialout group (which requires re-login to enable) with...

sudo usermod -a -G dialout $USER

In addition, change the owner of the port.

sudo chown <user>:<group> <file>
e.g.: sudo chown john:john /dev/ttyACM0

Another effective way that worked for me in the past was to change the access permissions.

sudo chmod a+rw /dev/ttyACM0

To take effect in each reboot, you have to edit /etc/rc.local and add the line that works for you (except dialout). Don't forget to follow by exit 0.


I document all the steps I've tried. Probably, not all of them are needed. Try it with your own configuration to ensure what suits you.
That's all for now. I hope to find some of these useful for your setup.
More close to a JubitOS image (?)

Wednesday, January 28, 2015

Testing Jubito in multiple environments

Since the latest version of Jubito, based on jaNET Framework 0.2.5 [ rev. r550 ], was released, I spent some time, by doing tests in multiple environments. I focused on single board computers, such as Raspberry Pi and Banana Pi, both with Rasbian and Lubuntu flavors. To my surprise, the installation and migration was flawless! Actually, it was expected, but I didn't have the chance to give a try till I bought them.

So, the evolution came with a new Jubito Home Server, passing from my old netbook Dell mini 9, to a Raspberry Pi and finally to a Banana Pi.

Let's take a look at some pictures from various tests.

Dell mini 9 (Ubuntu)


Hosted on upper kitchen cabinets

Asus eee (Linux Lite)


Mac (OS X Yosemite)


Raspberry Pi (Raspbian)



Banana Pi (Lubuntu)


Migration process...


Banana Pi + Arduino Uno + Various modules
Stress tests, power consumption tests (*), cpu and memory load tests.
(*) Arduino needs external supply 9V. If not, then with some open tabs on Firefox or other load Banana turns off.


The outcome!
Playing with Banana Pi for three weeks, I believe is a good deal and I recommend it.
Current compilation is consisted with the Banana Pi as my Jubito Home Server and the Arduino, plus various sensor modules for environment control.
Now, it's time to become invisible and be placed in its natural location, the upper kitchen cabinets.


The release of the updated version comes with Mac OS X support, including TTS. In most cases, you probably have noticed that I used the command-line interface, because it's more straightforward to me and also it runs natively, with no extra dependencies that wouldn’t already be available on each platform. [ Download page ]

What's next?
Hopefully to find the time for myself to build and provide Raspbian and Lubuntu images with Jubito Server installed and ready to run out of the box [Update: http://jubitoblog.blogspot.gr/2015/02/jubitos-for-banana-pi.html].

There's more to come but in time.