Development

Step 1: Managing a SmartThings project

Creating a Tizen RT with SmartThings project

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

    git clone https://github.com/Samsung/TizenRT.git
    
  2. Open the New TizenRT project from Git wizard.

  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.

Step 2: Managing SmartThings 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 SmartThings 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

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. Go to https://smartthings.developer.samsung.com/workspace/

  2. Login or create a new account if required.

  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.

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

  5. Select the capabilities added, and go next.

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

  7. Click on Close.

Step 3: Turn an LED on/off

Inside Device/Resource Model Manager

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

  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. 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. 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.

  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. Add the below global variables and include these header files.

  2. Modify the get and set function with the following code.

  3. Add the helper functions.

Step 4: Building a SmartThings project

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

Configure (need to be done once)

  1. Select the project in the Project Explorer view.

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

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

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

Build project

  1. Select the project in the Project Explorer view.

  2. To build the selected project, use one 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.

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

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

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

  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. Now your IOT certificate is active and you can close the certificate manager.

Step 5: Flashing SmartThings project

To upload your project to the board, you need to flash it.

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

  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. Place the above file in /etc/udev/rules.d folder with sudo permission.

  3. Reboot your system.


Flashing project to Artik board

  1. Connect the Artik 053 board to your system.

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

  3. Select the project in the Project Explorer view.

  4. Right Click Project > Flash.

  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.

Step 6: Communication to target using the serial terminal

To open a terminal:

  1. Click the Open a Terminal toolbar button.

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

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

  4. Push the Soft Reset button on the board.

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

Step 7: Adding device in SmartThings application

Enable developer mode

  1. Go to Settings.

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

  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.


You're done!

Congratulations! You have successfully achieved the goal of this Code Lab activity. Now, you can control direct-connected devices in SmartThings by yourself!