OpenHAB: WeMo Switch

From HIO Wiki
Jump to: navigation, search

About

openHAB is an open sourced software. It lets users integrate multiple home automation and technologies into one single solution that allows over-arching automation rules and that offers uniform user interfaces.

In this tutorial, we will start from scratch and use openHAB to control WeMo Switch and let HIO-EMB-1200 core board be the host server using Sample hio-image-x11.

Goals:

  • Create sample image hio-image-x11
- Install Java JDK and JRE
- Install openHAB
  • Set up WeMo Switch
  • Set up openHAB Configuration
  • Remote control WeMo Switch through local host

Create Sample Image hio-image-x11

cd /path/to/hio-yocto-bsp/
  • Set up machine and build directory ("build-x11")
/path/to/hio-yocto-bsp/$ export MACHINE=hio-imx6dl-board
/path/to/hio-yocto-bsp/$ . ./setup-environment build-x11

Edit: bblayers.conf

  • Add these bold lines to /path/to/build-x11/conf/bblayers.conf
BBLAYERS = " \
...
 ${BSPDIR}/sources/meta-qt5 \
 ${BSPDIR}/sources/meta-openembedded/meta-ruby \
 ${BSPDIR}/sources/meta-openembedded/meta-multimedia \
 ${BSPDIR}/sources/meta-hio \
 ${BSPDIR}/sources/meta-hio-demos \
 \
 ${BSPDIR}/sources/poky/meta-yocto-bsp \
 ${BSPDIR}/sources/meta-java \
 ${BSPDIR}/sources/meta-oracle-java \
 ${BSPDIR}/sources/meta-openhab \
"

Edit: local.conf

  • Add these bold variables to /path/to/build-x11/conf/local.conf
EXTRA_IMAGE_FEATURES = "debug-tweaks ssh-server-openssh"
IMAGE_INSTALL_append = " openjdk-7-jre openhab "
...
LICENSE_FLAGS_WHITELIST += "oracle_java"
PREFERRED_VERSION_hio-image = "1.01"
PREFERRED_PROVIDER_virtual/java-initial-native = "cacao-initial-native"
PREFERRED_PROVIDER_virtual/java-native = "jamvm-native"
PREFERRED_PROVIDER_virtual/javac-native = "ecj-bootstrap-native"
PREFERRED_VERSION_openjdk-7-jre = "75b13-2.5.4"
PREFERRED_VERSION_icedtea7-native = "2.1.3"
PREFERRED_PROVIDER_openjdk-7-jre = "openjdk-7-jre"
SOURCE_MIRROR_URL ?= "http://www.hioproject.org/support/images/source_mirror/sources/"
INHERIT += "own-mirrors"
BB_GENERATE_MIRROR_TARBALLS = "1"

Edit: Sources

  • change directory to /path/to/hio-yocto-bsp/sources/
git clone git://git.yoctoproject.org/meta-oracle-java -b master
git clone git://git.yoctoproject.org/meta-java -b master
git clone https://github.com/ulfwin/meta-openhab.git -b master

Edit: Downloads

  • Because of License Issue, there is error in the do_fetch in meta-oracle-java recipe. To work around this issue:
- Download the 2 files:
ejre-7u60-fcs-b19-linux-arm-vfp-hflt-client_headless-07_may_2014.tar.gz
ejre-7u75-fcs-b13-linux-arm-vfp-hflt-client_headless-18_dec_2014.tar.gz
  • Put the 2 downloaded files into /path/to/hio-yocto-bsp/downloads/
- Note: create the downloads folder in hio-yocto-bsp if it does not exist.

Compile: Bitbake

  • Change directory to /path/to/build-x11/ and bitbake the image
bitbake hio-image-x11

Boot Up

Set Up WeMo Switch

  • First we need to connect WeMo Switch's wifi into our network.
  • Follow: WeMo Switch Set Up
  • After the setting is finished, write down the Device name (e.g. WeMoSwitch)

WemoEdit.png

Set Up OpenHAB Configuration

  • To use WeMo Switch, we need its addon binding.
- In the embedded device rootfs, change directory to /usr/share/openhab-addons/
- Copy org.openhab.binding.wemo-1.7.1.jar to /usr/share/openhab-runtime/addons

Note: only move the necessary binding to increase performance.

  • Create a default configuration file
- Change directory to /usr/share/openhab-runtime/configurations
- Make a duplicate of openhab_default.cfg and rename it to openhab.cfg
  • Create Item (in this case, a switch)
- Change directory to /usr/share/openhab-runtime/configurations/items
- Create an empty file and name it default.items
- Add this line into default.items
Switch sensor "my first sensor" {wemo="WeMoSwitch"}

Note: WeMoSwitch is the name of the device when setup in the phone. sensor is the item name for openHAB to recognize.OpenHAB Item Syntax

  • Create Sitemap
- Change directory to /usr/share/openhab-runtime/configuration/sitemaps
- Create an empty file and name it default.sitemap
- Add these lines into default.sitemap
sitemap default label= "Main Menu"
{
    Frame label="My First Sensor"{
        Switch item=sensor
    }
}

Note: OpenHAB Sitemap Syntax

  • Start OpenHAB runtime
- Change directory to /usr/share/openhab-runtime/
sh start.sh
  • Connect to the host server
- In any browser, go to this address http://localhost:8080/openhab.app?sitemap=default or <host-IP-address>:8080/openhab.app?sitemap=default
  • To turn on/off the WeMo Switch, simply click on the switch next to "My First Sensor"

OpenhabWemo.PNG

Notes and Debugs

  • DL_DIR is downloads directory
  • BSPDIR is hio-yocto-bsp directory
  • IMAGE_INSTALL_append will install the software into the rootfs
  • libstdc++ static is needed on host to compile icedtea6/7-native
  • screen is used to automatically start openHAB at boot, and needs to be added to IMAGE_ISNTALL in local.conf
IMAGE_INSTALL_append = " screen"
  • Both openhab runtime and addon files are installed. They are located in /usr/share/openhab-*
  • If there is check5sum error, edit the recipe to match. The recipe is in /path/to/hio-yocto-bsp/sources/meta-oracle-java/recipes-devtools/oracle-java/
  • If there is a do_pack error, delete the whole meta-oracle-java folder and git clone from Yocto again.
  • If there is do_compile error, wait for the tasks to finish and bitbake the image again.
  • There are some known install problems for JRE packages due to dependencies reported by RPM package manager. Switching to DEB or IPK packaging temporarily fixes this.
- i.e. In local.conf, change PACKAGE_CLASSES = "package_rpm" to
PACKAGE_CLASSES = "package_deb"

or

PACKAGE_CLASSES = "package_ipk"
  • java.net.UnknownHostException: this is cause by unresolved hostname. E.g. hio-imx6dl-board
- Check hostname in terminal
hostname
- Check hostname in etc/hosts file
- There should be something like: 127.0.0.1 localhost
- Change the name of the current hostname to localhost
hostname localhost
- Or add host into the etc/hosts file
127.0.1.1 hio-imx6dl-board
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
  • Port in use: sometime port# 8080 is in used and we might have to kill the process to turn on OpenHAB.
- i.e Address is already in use
lsof -i:<port#>
kill <pid>
  • Doing sudo /path/to/repo sync will solve some error and recipe problems.

Video

openHAB Open Source Automation Software on HIO Wallpad Touch Computer

References