SmartThings with TizenRT

Overview

Tizen has commercialized in smart TV, smartphone, wearable devices (Gear S, Gear Fit), and smart home appliances. However, low-end and low-cost IoT devices, such as home appliances without display and wearable bands with a small LCD, have received less attention. The objective of Tizen RT (Real Time) is to extend the Tizen platform device coverage to these kinds of low-end devices.

Now, in one line, Tizen RT is an RTOS-based (Real Time OS) lightweight platform.

Objective

If the instructions in the document below are followed appropriately, one should be able to flash a Smart Things application, which supports a switch on/off capability to control an LED, in Artik 053 board using Tizen Studio for RT.

Setup

Hardware targets
  1. 1. ARTIK 053

  2. 2. USB-B Cable

Development environment
  1. 1. Check the following prerequisites before installing the Tizen Studio for RT:

    • Ubuntu 16.04/14.04 64/32 bit

    • JDK 8/9

    • Docker (Appendix)

  2. 2. Tizen RT Studio version 2.0 (or later), supporting SmartThings functionality. Please refer to Appendix “TizenRT Installation”.

Application Development

1. Managing a SmartThingsTM Project

Creating a Tizen RT with SmartThings project

  1. 1. Clone the latest TizenRT source code from GitHub using the following command:

    git clone https://github.com/Samsung/TizenRT.git

  2. 2. Open the New TizenRT project from Git wizard.

  3. 3. In the New TizenRT Project from Git Wizard, you can select one of the two methods:

    • If you want to import from a new repository, clone its URI (https://github.com/Samsung/TizenRT.git).

    • If you have already cloned the above repository, select an existing local repository option. This local repository is where you have to clone the project using above command.

    • Finally it will take you to the last page where Finish button is enabled. On this page, there is a checkbox. Check if you want SmartThings functionality. Check this box and it will take you to the Device/Resource Model Manager. You can also finish project creation without selecting it and you will see the project in the project explorer. Right click on the project and select Manage ST-Things resource and it will take you to the Device/Resource Model Manager.

2. Managing SmartThingsTM Certificates

To ensure that only trusted developers and manufacturers can develop devices that communicate with the SmartThings Cloud, you must get certificates for devices to use the SmartThingsTM service.

If no certificate is set as active when you try to flash a project, then it will ask to create an IOT Cloud Service certificate. Creation of the certificate in Tizen Studio will be shown before building the project.

Adding device in Developer Workspace Website

The process of creating a new certificate requires you to generate a Certificate Signing Request (CSR) and submit it to the Developer Workspace Web site.

  1. 1. Go to https://devworkspace.developer.samsung.com

  2. 2. Login or create a new account if required.

  3. 3. In the left tab panel of the home screen, you'll find Cloud-connected under SmartThings Device. Click and open the link. Alternatively, you'll find Cloud-connected in the centre of the home screen as well. Click on ‘+’ icon to create a new device.

    Figure 1 Connecting a device to Developer Workspace

    Figure 1 Connecting a device to Developer Workspace

  4. 4. Fill the required fields such as Device Name, Vendor ID (VID), Device Type (Switch, in our case), and Capabilities (x.com.st.powerswitch).

    Figure 2 Device information page

    Figure 2 Device information page

  5. 5. Select the capabilities added, and go next.

    Figure 3 Adding device capabilities

    Figure 3 Adding device capabilities

  6. 6. Fill the Display Name and Device On-boarding ID (Setup ID), and press Confirm

    Figure 4 Self-publishing a device

    Figure 4 Self-publishing a device

  7. 7. Click on Close.

    Figure 5 Closing My cloud-connected devices page

    Figure 5 Closing My cloud-connected devices page

3. Turn an LED on/off

Inside Device/Resource Model Manager

  1. 1. You can use the Device/Resource Model Manager to select a device model for interworking with the SmartThingsTM service.

  2. 2. With the Model Manager, you can:

    • Check device, resource, and property information

    • Select, add, and restore resources

    • Import, export, save, and delete device models

    • Generate stub code

  3. 3. Select a device model in the Default or Custom tabs of the Device/Platform section to see device, platform, and resource information. For demo purpose you can select any device from default tab. We would recommend Samsung Lamp.

  4. 4. Once you select basic device, on the right hand side you will see the device information. Fill proper values in Setup ID, Vendor ID and Manufacturer ID (more Info covered later in this document).

    Figure 6 Selecting a device model

    Figure 6 Selecting a device model

  5. 5. When you click Finish in the Model Manager, the code for processing the resource is automatically created for the selected device.

Code Snippets (resource_capability_switch_main_0.c)

Let’s begin with a sample application present in the TizenRT source code. Open file TizenRT > apps > examples > st_things > resource_capability_switch_main_0.c

  1. 1. Add the below global variables and include these header files.

    Figure 6 Selecting a device model
  2. 2. Modify the get and set function with the following code.

    Figure 6 Selecting a device model
    Figure 6 Selecting a device model
  3. 3. Add the helper functions.

    Figure 6 Selecting a device model

4. Building a SmartThingsTM Project

Before debugging or flashing your project, you must first configure and build it.

Configure (need to be done once)
  1. 1. Select the project in the Project Explorer view.

  2. 2. In the Tizen Studio for RT toolbar, click the Build TizenRT Project icon()

    Figure 7 Selecting board for TizenRT Project

    Figure 7 Selecting board for TizenRT Project

  3. 3. Click on Select Board. In the window, select appropriate Board and Build Options.

    Figure 8 Boards and Build Options window

    Figure 8 Boards and Build Options window

  4. 4. Click Ok. You can see the logs of successful configuration in the console.

Build Project
  1. 1. Select the project in the Project Explorer view.

  2. 2. To build the selected project, use 1 of the following:

    • In the Tizen Studio for RT menu, select Project > Batch Build Project.

    • In the Tizen Studio for RT toolbar, click the Build TizenRT Project icon ()

Creating Certificate

To launch the Certificate Manager, go to Tools > Certificate Manager in the Tizen Studio for RT menu. In Certificate Manager, click IOT Cloud Service tab and click ‘+’ icon.

Figure 9 Tizen Certificate Manager window

Figure 9 Tizen Certificate Manager window

  1. 1. A dialog page will open which will ask to input certificate information. Fill all the required information and click OK.

    Figure 10 Certificate information window

    Figure 10 Certificate information window

  2. 2. Again a dialog will open asking to input Samsung Cloud data. Fill the required data and click OK.

    Figure 11 Samsung Cloud Data window

    Figure 11 Samsung Cloud Data window

  3. 3. After that a page will open where you need to sign-in to the Samsung Account to generate certificate.

  4. 4. Your certificate is successfully generated. Mark one of the certificate present under the IOT Cloud Service tab as active by selecting one of them and clicking tick “” option.

  5. 5. Now your IOT certificate is active and you can close the certificate manager.

    Figure 12 IoT Cloud Service Tab – Certificate Profile

    Figure 12 IoT Cloud Service Tab – Certificate Profile

5. Flashing SmartThingsTM Project

To upload your project to the board, you need to flash it. If Artik 053 configuration is not present in the system, please refer to Appendix “Add USB device rules” before proceeding.

Flashing Project to Artik board
  1. 1. Connect the Artik 053 board to your system.

  2. 2. Before proceeding, ensure that the project is built and you have an active certificate. (Last 2 steps were successful).

  3. 3. Select the project in the Project Explorer view.

  4. 4. Right Click Project > Flash.

  5. 5. In the Tizen Studio for RT toolbar, click the Flash icon ()

    • In the Flash TizenRT Project Wizard, select the Flash option, you should choose ALL options since we are flashing for the first time. Click OK.

    • If the flashing is successful, the SUCCESS log is shown in the console.

      Figure 13 Flashing project to Artik board

      Figure 13 Flashing project to Artik board

6. Communication to Target Using the Serial Terminal

To open a terminal:

  1. 1. Click the Open a Terminal toolbar button.

    Figure 14 Opening a terminal

    Figure 14 Opening a terminal

  2. 2. In the Terminal Dialog, set the information to connect the board, and click OK.

    Figure 15 Confirming Terminal Dialog information

    Figure 15 Confirming Terminal Dialog information

  3. 3. You can see the opened terminal with a serial connection in the Terminal view.

    Figure 16 Serial connection in Terminal view

    Figure 16 Serial connection in Terminal view

  4. 4. Push the Soft Reset button on the board.

    Figure 17 Location of Soft Reset button on the board

    Figure 17 Location of Soft Reset button on the board

  5. 5. You can see the boot logs on the Terminal view with the TASH prompt.

    Figure 18 Terminal view boot logs

    Figure 18 Terminal view boot logs

7. Adding device in SmartThingsTM application
Enable Developer Mode
  1. 1. Go to Settings.

  2. 2. Tap on ‘About SmartThings’ for 5 seconds to enable developer mode.

  3. 3. Enable the Developer mode by flipping the switch.

Adding device to the app

** You will need Wi-Fi connection for the Artik 053 to connect to.

Figure 19 Connecting Artik 053 using Wi-Fi

Figure 19 Connecting Artik 053 using Wi-Fi

Appendix

TizenRT Installation
  1. 1. Install latest Tizen Studio from the link given below:
    https://developer.tizen.org/development/tizen-studio/download

  2. 2. After successful installation launch the Package Manager.

  3. 3. In the Package Manager, install RT SDK tools. This will install the required IDE and toolchain.

  4. 4. After the installation is complete, close the Package Manager.

  5. 5. Launch Tizen Studio for RT.

Docker Setup in Ubuntu 14.04

MANAGE DOCKER AS A NON-ROOT USER

  $ sudo groupadd docker
  $ sudo usermod -aG docker $USER
  Log out and log back in so that your group membership is re-evaluated
  &docker run hello-word

SET UP THE REPOSITORY

  $ sudo atp-get remove docker docker-engine docker.io
  $ sudo atp-get update
  $ sudo atp-get install  \
      apt-transport-https  \
	  ca-certificates  \
	  curl  \
	  software-properties-common
  $curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  $sudo add-apt-repository  \
     "deb [arch=amd64] https://download.docker.com/linux/ubuntu  \
	 $(lsb_release -cs)  \
	 stable"

INSTALL DOCKER CE

  $ sudo atp-get update
  $ sudo atp-get install docker-ce
  $ sudo docker run hello-word

Artik 053 Board Diagram
Figure 20 Artik 053 Board Diagram

Figure 20 Artik 053 Board Diagram

Add USB device Rules

This is optional. But as ARTIK is connected through USB, some operation like programming of binary may not work without this configuration.

  1. 1. Make a file named 99- .rules with the following content.

    SUBSYSTEMS=="usb",ATTRS{idVendor}=="0403",ATTRS{idProduct}=="6010",MODE="0666" RUN+="/sbin/modprobe ftdi_sio" RUN+="/bin/sh -c 'echo 0403 6010 > /sys/bus/usb-serial/drivers/ftdi_sio/new_id'"
  2. 2. Place the above file in /etc/udev/rules.d folder with sudo permission.

  3. 3. Reboot your system.