Friday, April 15, 2016

Notify from Openhab using Cisco Spark

I'm using Openhab for my home automation for a couple years now and am very happy with it. One of the things it can do it notify you on various events around the house. I had XMPP configured to send messages to my Google account, but the last months this has been failing. Some error about pinning certificates. There's some information on the internet about how to solve this, but I'm using a Google account with a custom DNS name which seems to complicate matters a bit.

Since Cisco added APIs to the Cisco Spark service (try it!!), I wanted to use Spark instead for my notifications. The proper way of integration with Openhab is to develop an Openhab plugin, but I wanted something more versatile. So I started the development of a CLI interface for Spark: sparkcli. Let's get going!

Install and configure sparkcli

First download a copy of sparkcli here: . Make sure the binary is on the PATH for the OS user that's running Openhab. Typically /usr/local/bin will do just fine.

Wednesday, December 2, 2015

Architect: I need this algorithm for my big plansPM: Did you get that?Developer: Say what?Architect: I need this algorithm for my big plansPM: Did you get that?Developer: Say what?Architect: I need this algorithm for my big plansPM: Did you get that?Developer: Is this what you need?Architect: No!PM: Completed 80%Developer: Is this what you need?Architect: No!PM: Completed 90%Developer: Is this what you need?Architect: No!PM: Completed 95%Developer: Is this what you need?Architect: Yes.

Alternative:

Engineer: Let me start a Git repo to collaboratively build this algorithm, so I can move on with the rest of my big plans.

Tuesday, March 3, 2015

This took me a while to figure out, but I finally got the missing piece figured out. I'm using Telenet as an ISP to provide access from my home network. I have a linux box acting as a gateway router for the home network with some basic services that I use in my home.
The ISP has IPv6 enabled on their cable modems for a while, and I've been trying to extend that IPv6 network into my home network. After all, they're handing out a /64 to all end users. Here's how I got it to work.

The situation looks like this. The Telenet router is the ISP provided cable modem. After that I have my Ubuntu linux gateway. For the examples later, eth0 is the home network, eth1 is towards the internet.

The address range for the home network can be found on the admin pages from the ISP (warning - dutch content)

To turn on IP forwarding, configure in /etc/ufw/sysctl.conf:net/ipv4/ip_forward=1net/ipv6/conf/all/forwarding=1net/ipv6/conf/all/proxy_ndp=1

I'll focus on the IPv6 specific settings in the remainder of the post.
In /etc/network/interfaces:iface eth0 inet6 static address 2a02:1810:2088:5b00::100 netmask 64 up ip route add 2a02:1810:xxxx:xxxx::/64 dev eth0 metric 100 down ip route del 2a02:1810:xxxx:xxxx::/64 dev eth0 metric 100
Note that I added an explicit metric. If I didn't do this, the default route that is assigned to eth1 would get the upperhand, and I wouldn't be able to properly communicate within my home network since the gateway would send all traffic out the door.

Install radvd to autoconfigure devices on the home network:sudo apt-get install radvd

And configure it:

interface eth0

{

AdvSendAdvert on;

MinRtrAdvInterval 30;

MaxRtrAdvInterval 100;

# There's no DHCPv6

AdvManagedFlag off;

AdvOtherConfigFlag off;

prefix 2a02:1810:xxxx:xxxx::/64

{

AdvOnLink on;

AdvAutonomous on;

AdvRouterAddr on;

};

};

Now before we add the last piece, make sure you have proper firewall rules in place. I suggest configuring /etc/default/ufw to have disable forwarding by default (and potentially the other chains too):

DEFAULT_FORWARD_POLICY="DROP"

Then specifically add firewall rules as required for your network. Two things to know about:

There's no need for NAT with IPv6, so you can allow access directly to internal hosts

Ensure to configure the firewall on the "Mijn Telenet" ISP admin page in addition to the firewall on the linux gateway.

Now the last piece, which I couldn't figure out for the longest time: when requests come in from the internet (or responses from outgoing packets) the telenet router relies on IPv6 neighbor discovery to figure out who's behind it. The linux gateway router doesn't proxy such requests by default.

You can compare this with ARP in IPv4. The Telenet gateway is trying to figure out who has got a certain IPv6 address, and sends out neighbor solicitations. The linux gateway will respond only when it hears its own address. We can tell it to respond on behalf of the hosts on the home network by installing ndppd.

wget http://priv.nu/projects/ndppd/files/ndppd_0.2.3-1_amd64.deb

sudo dpkg -i ./ndppd_0.2.3-1_amd64.deb

Then configure it (/etc/ndppd.conf):

proxy eth1 {

rule 2a02:1810:xxxx:xxxx::/64 {

}

}

Now start ndppd:

sudo service ndppd start

And that's it.. now the gateway will respond to IPv6 neighbor solications on eth1 for the entire /64 network.

You should not be able to get to IPv6 enabled websites from within your home network. Most modern Windows computers will automatically configure themselves after the setup above. Give it a try and navigate to http://test-ipv6.vyncke.org/ and you should see a confirmation.

Saturday, October 4, 2014

Many robust and scalable solutions exist for monitoring docker containers and publish their IP addresses into some service discovery solution. SkyDNS or consul.io are such examples. However I wanted a simpler solution for the few containers I run on my home network server, so I put together the simplest service discovery mechanism possible.

Thursday, September 18, 2014

Intro

I have a strong Java background and have messed around with various other languages but never become fluent in any of them. I guess because I didn't have to. Perl crossed my path early in my career, then Ruby became popular and later python.
Now I'm looking at Go. Actually it's the third time or so I'm doing that, and this time there seems to be a click. What attracts me most is that it's fairly easy to pick up, and... it generates a single executable that can exist on its own without having to install a run-time environment. I assume that's one of the reasons why it's so popular in the cloud community these days (yes, next to python of course).
Anyway, just a quick write-up so I don't forget how to quickly get started with Go after my next PC refresh. There's nothing new here... just summarizing few key steps in one place.

Syntax highlighting and autocomplete in vi

Once there's good information on various tooling integration in /usr/local/go/misc. I'm interested in vi. Based on what's there in /usr/local/go/misc/readme.txt, here is the content of my /etc/vim/vimrc.local file.

Assuming you have docker installed on your machine, these are the few steps to take to get openhab up and running.

Create a config directory and store your openhab configuration files there. This is the content of [OPENHAB_HOME]/configurations and will be injected into the container. Let's assume you chose /tmp/config.

Add a file called addons.cfg into that same config directory. This file is used to determine which plugins to enable for your deployment. Each line in the config file should have the name of the addon jar file to load. My file looks like this:

Tuesday, March 18, 2014

I have my house wired up pretty nicely with all kinds of automation - I'll post details on this later. Today, I wanted to hook up the alarm clock on my phone. Basic scenario: when the alarm goes off, turn on the lights and open the shutters. Let's get to it.

I have a KNX-based home automation system, but most of the advanced scenarios are configured in OpenHAB. The basic flow for automating this alarm clock scenario is documented here:

Let's go wild and start with the middle part here. We configure an item in OpenHAB that we can use to trigger the alarm. Look here for details on adding items in OpenHAB. We'll add this line:

Switch pWekkerTom"Wekker Tom"{autoupdate="false"}

If you're not familiar with this 'autoupdate' parameter, don't worry about it. It just makes this switch act as a trigger without changing its state. The scenario would work even without it.

Next we create a rule that catches commands for the pWekkerTom item, and performs whatever actions we want when our alarm goes off.

Now all is left is a way to have our mobile phone trigger all of the above. For this purpose, we use the swiss army knife of Android automation: Tasker. (Apologies iPhone users - you're out of luck here. I'm sure Tasker equivalents exist, I just don't have any experience with them).

We'll use the OpenHAB REST API, so we'll also install the RESTask for Tasker plugin. This provides a bit more features than the native Tasker HTTP actions.

Once both are installed from the Google Play Store, first go to the Tasks tab in Tasker and create a new Task. in this Task, create an Action by clicking the + sign at the bottom of the screen. For action category, select Plugin -> RESTask.

In the configuration of the RESTask, fill in these fields:

Request Type: POST

Host: https://link.to.your.openhab:7443/rest/items/pWekkerTom

Basic Auth: <your credetials>

Enable custom body: check!

Custom body: ON

You can leave most other settings to their defaults, but it depends on your setup.

Save all this goodness. The last step is to create a profile that ties the alarm clock to the task.

Go to the Profiles tab in Tasker and create a new Profile by clicking the + sign at the bottom of the screen. In event category select Date/Time -> Alarm Clock.

Save this, and then associate this profile with the Task you have created earlier. Done!