This guide provides instructions and resources to help developers set up the development environment, build the IoTivity stack and build sample applications on Ubuntu for an Arduino target.
Needed for Arduino only:
- Arduino ATMega 2560
- Arduino Due
- The Arduino Ethernet Shield w/o POE (link) is used for the Networking Shield.
Tools and libraries
The following tools and libraries are necessary to build IoTivity code for Arduino. The commands and instructions provided in this section are specifically for Ubuntu LTS 12.04.
Open the terminal window and use the following instructions to install all the necessary tools and libraries to build an IoTivity project.
Ubuntu LTS 12.04
Ubuntu LTS version 12.04 is the supported OS for building the IoTivity stack. Instructions may be different for other versions of Ubuntu and Linux.
Git is a source code management software, and is necessary to gain access to the IoTivity source code.
Use the following command to download and install git:
$ sudo apt-get install git-core
Secure Shell is required to connect to the git repository to check out the IoTivity source code. Secure Shell is typically part of the base operating system and should be included. If for any reason it is not available, it can be installed by running the following command in your terminal window:
$ sudo apt-get install ssh
Doxygen is a documentation generation tool used to generate API documentation for the IoTivity project. Download and install Doxygen by running the following command in your terminal window:
$ sudo apt-get install doxygen
Arduino Framework and AVR-GCC compiler
For Arduino ATMega 2560, Arduino version 1.0.5 and AVR-GCC version 4.5.3 is needed.
For Arduino Due: Arduino Version 1.5.7 and AVR-GCC version 4.8.3 is needed
Note: Arduino framework obtained using $ apt-get will come with different AVR-GCC compiler version. Please use the link provided above
The installation directory for the Arduino framework is referred to as <ARDUINO_DIR> in this document. This is typically located in /usr/share/arduino/. Arduino tools directory is referred to as <ARDUINO_TOOLS_DIR> in this document. This is typically located in <ARDUINO_DIR>/hardware/tools/avr/bin
Arduino Time Library
Download the Arduino Time Library and unzip it in the Arduino directory at <ARDUINO_DIR>/libraries/TIME.
For Arduino ATMega 2560, download the Time library from here.
For Arduino Due, download the Time library from here.
Cutecom is a graphical serial terminal used in this project for debugging purpose. Cutecom is only used for viewing logs from the Arduino platform. Use the following command in the terminal window to download and install cutecom:
$ sudo apt-get install cutecom
There are 2 methods to get the source code.
- Downloading most stable source from here.
- Getting source directly from gerrit.
Gerrit is a web-based code review tool built on top of the git version control system. Gerrit's main features are side-by-side difference viewing and inline commenting, which streamline code review. Gerrit allows authorized contributors to submit changes to the git repository after reviews are done. Contributors can have code reviewed with little effort, and get their changes quickly through the system.
The following five steps describe how to check out the source code on the development machine.
Note: skip Step 1 to use existing ssh keys.
Create ssh keys.
- On the terminal, type the following (replace "your name <your_email_address>" with your name and email address):
$ ssh-keygen -t rsa -C "your name"
$ ssh-keygen -t rsa -C "John Doe email@example.com"
- After pressing the Enter key at several [LS6] prompts, an ssh key-pair will be created at ~/.ssh/id_rsa.pub.
Upload and register an ssh public key.
- Log in to IoTivity Gerrit.
- Click on Settings on the top right side as shown here:
- Click on SSH Public Keys and add key.
- Open ~/.ssh/id_rsa.pub, copy the content, and paste the content in the "Add SSH Public Key" window.
- Click Add.
Setting up ssh.
- Open ~/.ssh/config in a text editor.
- Add the following line:
Host iotivity gerrit.iotivity.org Hostname gerrit.iotivity.org IdentityFile ~/.ssh/id_rsa User [username] Port 29418
- To connect behind the proxy, add the following line after IdentityFile ~/.ssh/id_rsa with the appropriate proxy address and port:
ProxyCommand nc -X5 -x <proxy-address>:<port> %h %p
Verify your ssh connection.
- Execute the following command in the terminal window:
$ ssh gerrit.iotivity.org
- Upon successful connection, the following message should appear indicating proper ssh and configuration connection.
**** Welcome to Gerrit Code Review ****
- If the connection is not established, check for the proxy and use the proxy settings described in Step 3.
Cloning the project source.
To build the IoTivity resource stack:
- Using your terminal window, browse to the directory where code will be checked out.
- Execute the following command in the terminal window to clone the iotivity repository:
$ git clone iotivity:iotivity
git clone ssh://gerrit.iotivity.org/iotivity
This command clones the repository in your current working directory.
Build the IoTivity project for Arduino
Step 1: Apply arduino patch
Using the terminal window, navigate to <ARDUINO_DIR>, and run the following command.
For Arduino ATMega 2560:
$ patch -p5 < <iotivity>/tools/arduino/patches/arduino-1.0.5_linux.patch
For Arduino Due:
$ patch -p5 < <iotivity>/tools/arduino/patches/arduino-1.5.7_linux.patch
Step 2: Setup local.properties
Create a file named "local.properties" under <iotivity>/resource/csdk/ and paste the following in the file.
ifeq ($(PLATFORM), arduinomega) #Location of arduino sdk for Arduino Mega ARDUINO_DIR := <arduino-1.0.5> ARDUINO_TOOLS_DIR := $(ARDUINO_DIR)/hardware/tools/avr/bin else #Location of arduino sdk for Arduino Due ARDUINO_DIR := <arduino-1.5.7> ARDUINO_TOOLS_DIR := $(ARDUINO_DIR)/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin endif
Note: make sure to update <arduino-1.0.5> and <arduino-1.5.7> with appropriate arduino installation directory location.
Step 3: Build
Using the terminal window, navigate to <iotivity> directory and execute following command
For Arduino ATMega 2560:
$ make arduinomega
For Arduino Due:
$ make arduinodue
This command builds the core and the C SDK for the IoTivity project with Arduino target along with the sample apps.
Build the Arduino Sample
The output of the compiled samples will be located at <iotivity>/resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/
When an Arduino SimpleClientServer application is running, it outputs logs to serial port. This requires the current user to be a part of the "dialout" user group permissions on Ubuntu. If your Arduino device is NOT installed at location "/dev/ttyACM0", you must define ARDUINO_PORT to the location it is installed at. This location will be referred to as <DEV_PORT>.
navigate to <iotivity>/resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/ and run the following command, where <DEV_APP> is "occlient" or "ocserver"
$ make install APP_INSTALL=<DEV_APP> ARDUINO_PORT=<DEV_PORT>
Use cutecom to connect to the dev_port for the Arduino with following settings:
Baud Rate : 115200 Data bigs: 8 Stop bits: 1 Open for: Reading
Apply settings and select open device.