Client Development on Linux

As Linux is not only supported on the service side but on the client side, too (so on devices/things) this page contains the description how to build the Linux client components.

The following installation steps are based on a fresh Ubuntu 14.04.2 LTS Server installation which means that no extra programs have been installed to the system apart from the base system. Besides Ubuntu Thriot client components are  tested on ARM-based Banana Pi running Raspbian. Although it was not carefully tested but it means that Thriot client can run on other ARM based card-sized computers e.g. Raspberry Pi and Raspberry Pi 2.

Preparing the environment

Ensure that you have git installed:

ubuntu:~$ sudo apt-get install git

Ensure the programs that are required to build the system:

ubuntu:~$ sudo apt-get install make
ubuntu:~$ sudo apt-get install g++
ubuntu:~$ sudo apt-get install cmake
ubuntu:~$ sudo apt-get install zlib1g-dev
ubuntu:~$ sudo apt-get install libssl-dev
ubuntu:~$ sudo apt-get install libcurl4-openssl-dev

These programs are either needed to build the system (make, g++, cmake) either are used by the Linux client library called libthriotclient.so directly (curl) or by the libwebsockets (zlib, ssl).

Of course on a production Linux machine you won’t need all of these tools if you don’t want to build the client there just use it.

After git is installed you can clone the Thriot source code repository. This guide will show how to clone the original Thriot repository, in case of a fork or branch you may choose other options.

This guide supposes that you work in the src folder of your $HOME:

ubuntu:~$ mkdir –p src && cd src
ubuntu:~/src$ git clone http://github.com/kpocza/thriot.git

Navigate to the Linux client folder and run make

ubuntu:~/src$ cd thriot/Client/Linux
ubuntu:~/src/thriot/Client/Linux$ make

In this case make will run the target called all that will run the following targets:

  • preparedeps
  • lib
  • test
  • app

The preparedeps target will download and build the libraries needed to build the Thriot library. The lib target is responsible for building the libthriotclient.so shared library. The test target will build the integration test project while app is a demo app that shows some of the API calls that libthriotclient supports. Of course you need to download and build the third-party libraries only once (to be more precise when they change and want the new version).

The build output of just the library (binary and header files needed for development) will go to the output folder called libout, while the test and app project with all necessary dependencies (libwebsockets) will go to the out folder.

image1

To do development work for your application you will need the content of libout while in production environment the out/lib* will be needed.

Testing the environment

The test project and the application called app by default want to connect to server called thriothost and suppose that the server is configured for the local Azure Storage emulator.

image2

You can easily change either the hostname or can either uncomment the SQL based environment and comment the local Azure based environment to run SQL-based tests.

The recommended way to make the host configurable is to put the host-IP association in the /etc/hosts file. It look like the following in my case:

image3

The integration test project (test) uses gtest, Google’s C++ test framework.

To ensure that everything is configured correctly you should run the out/test program with the following expected output (all tests green). Before running the tests ensure that all server components are started on the host.

image4

The out/app application demonstrates some messaging and the main concepts how to create a simple Thriot app for Linux.

image5

As mentioned above all Linux-based libraries and applications are supported on ARM-based card-sized computers like Raspberry Pi and Banana Pi.

Using the library in your custom app

Do the following steps:

  • Install the necessary components on your system described in the Preparing the environment section of this page
  • Ensure that you can build the library
  • You can have the application under the app folder as a reference app. For compilation and link parameters and methods please check the Makefile.

 

Advertisements