Wednesday, June 1, 2016

Iotivity on the Intel IoT Gateway

Iotivity is "an open source software framework enabling seamless device-to-device connectivity to address the emerging needs of the Internet of Things."  It has the backing (as in paid programmers) of some of the major players, including Intel and Samsung, to name just two.

You probably wouldn't want to build Iotivity on an IoT gateway machine; it is designed as embedded software, after all, so you'd cross-compile it on a more powerful machine and then install it.  Or rather, you'd build a platform image in the proper way, but that is beyond the scope of this article (I'll blog about it later).  But if you're working on Iotivity itself, and if you're pulling changes on the bleeding edge, you need to build it by hand. Here's how.

The instructions for Linux on the Iotivity website are for Ubuntu LTS 12.04.  They assume that apt-get is installed, which is not the case with WindRiver Linux on a gateway.  WRLinux does have rpm, but I'm not yet familiar that so let's do it by hand.

WARNING: this is a little bit messy at the moment, as I'm composing it as my build proceeds, but it should be of some use.  I'll clean it up a bit later.

Note that the build scripts are supposed to do some of this stuff automatically (e.g. download and compile some of the deps).  Which they do, on Ubuntu.  I had some trouble getting them to work on WRLinux (also OS X), plus the build scripts make some assumptions that only work on Ubuntu. So I decided to pull out most (all?) of the dependency stuff and handle it separately, manually.  Once you have that stuff installed the build seems to proceed smoothly.

Dependencies:
  • tinycbor - see below
  • gtest-1.7.0
    • the build scripts use https://googletest.googlecode.com/files/gtest-1.7.0.zip, but google has switched to github: https://github.com/google/googletest
  • bzip2 - only need for downloading other deps?
  • uuid
  • libicu
  • gio - BLE uses gdbus.  deps:
    • glib - low-level C routines etc. from the Gnome project http://ftp.gnome.org/pub/gnome/sources/glib/2.48/glib-2.48.1.tar.xz
      • libffi - Foreign Function Interface
        • https://github.com/libffi/libffi - download zipfile, ./autogen.sh, .configure...
      • libpcre - Perl Compatible Regular Expressions
        •  ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
  • python 2.7.*
  • scons
  1. Python 2.7.* - should be already installed.  Needed for scons
  2. Install bzip2
    1. $ wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
    2. verify md5 checksum:  $ md5sum ...
    3. $ tar -zxvf bzip2-1.0.6.tar.gz
    4. $ cd bzip2-1.0.6
    5. $ sudo make install
  3. Install libuuid
    1. $ wget http://downloads.sourceforge.net/project/libuuid/libuuid-1.0.3.tar.gz
      1. Do NOT use OSSP uuid, it seems to be missing some fns
    2. verify integrity - on Sourceforge you can find the checksums in the file browser; see Verifying Downloaded Files.
    3. $ tar -zxvf libuuid-1.0.3.tar.gz
    4. $ cd libuuid-1.0.3
    5. $ ./configure
    6. $ make
    7. $ sudo make install
  4. Install libicu
    1. e.g. $ wget http://download.icu-project.org/files/icu4c/57.1/icu4c-57_1-src.tgz
    2. build it
  5. Install libpcre (ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/)
    1. $ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.bz2
    2. $ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.bz2.sig
    3. $ gpg --verify pcre-8.38.tar.bz2.sig
    4. $ gpg --recv-keys FB0F43D8 (or whatever key is shown by the --verify op)
    5. $ tar -jxvf pcre-8.38.tar.bz2
    6. $ ./configure --enable-utf --enable-unicode-properties
    7.  $make && sudo make install - puts libs in /usr/local/lib
  6. Install libffi
  7. Install glib - this may be a pain, see Notes on glib below.
    1. blah....
    2. $ ./configure
      1. Unfortunately the system pcre lib in /usr/lib64 is apparently not compiled with unicode support so ./configure will not finish.  I linked /usr/lib65/libprc.so.1 to /usr/local/lib.  I dunno if that's a good idea, but it got me thru ./configure
  8. Install boost
    1. $ wget https://sourceforge.net/projects/boost/files/boost/1.61.0/boost_1_61_0.tar.bz2
    2. verify sha256 hash:  $ sha256sum ...
    3. $ tar -jzvf boost_1_61_0.tar.bz2
    4. $ cd boost_1_61_0
    5. $ ./bootstrap.sh --with-libraries=system,filesystem,date_time,thread,regex,log,iostreams,program_options --prefix=/usr/local
    6. $ ./b2
    7. go make a cup of coffee, the build takes a long time
    8. $ sudo ./b2 install
  9. Install scons
    1. $ wget http://downloads.sourceforge.net/project/scons/scons/2.5.0/scons-2.5.0.tar.gz
    2. see  Building and Installing SCons on Any System
  10. Build Iotivity
    1. Download:  $ http://mirrors.kernel.org/iotivity/1.1.0/iotivity-1.1.0.zip
      1. NOTE: download the zip file and check the sha256 sum.  As of the time of writing, the tar.gz file does NOT match its checksum!
      2. $ unzip iotivity-1.1.0.zip
      3. $ cd iotivity-1.1.0
      4. $ scons
The build takes quite a while.

tinycbor

At the very beginning you will see a message like this:

*********************************** Error: *************************************
* Please download cbor using the following command:                               *
*     $ git clone https://github.com/01org/tinycbor.git extlibs/tinycbor/tinycbor *
******************************************************************************

But when you try to do this you will get an error:

fatal: unable to access 'https://github.com/01org/tinycbor.git/': Problem with the SSL CA cert (path? access rights?)

Gateways running WRLinux come with lots of certificates (see /etc/ssl/certs) but apparently not the one we need for git cloning.  The workaround is to use wget.  Go to the tinycbor git repo in your browser, click on the "Clone or download" button, then right click on the "Download zip" link to copy the link address.  On the gateway, cd to iotivity-1.1.0/extlibs/tinycbor, wget the zip file, and unzip it.  You'll get a directory called tinycbor-master.  Rename this to tinycbor, and then return to the iotivity-1.1.0 dir and rerun scons.

Other notes:

$ scons -c  seems to hang when it gets to "scons: Cleaning targets ..."  ???

Notes on glib:


The bluetooth le stuff for linux depends on the Bluez stack, which
depends on gdbus, which depends on gio, then glib, etc.

So we install glib-2.0, and then the trouble starts.  The pkg-config
files go in /usr/local/lib/pkgconfig, but when scons runs pkg-config
it only uses the default dir, namely /usr/lib64/pkgconfig.  I don't
know how to get it to also look in /usr/local, you can't pass stuff
via env vars.  So the quick-n-dirty is to copy the relevant *.pc
files.  Ditto for the headers; copy /usr/local/include/gio-unix-2.0 to
/usr/include.



No comments:

Post a Comment