Filter results by

ThingWorx

ThingWorx is an application development platform for IoT. It provides a drag-and-drop GUI development environment, along with a control and monitoring portal that runs either from the cloud or on your own server. Review the ThingWorx overview for more information.

The ThingWorx agent is a powerful component of the ThingWorx architecture. The agent allows for the rapid deployment of connections between the ThingWorx platform and an associated data reporting device, with minimal design requirements on the part of the user.

This article provides instructions for installing and using the ThingWorx agent on any ARTIK05X module. Once installed, you can use the solution with the Shoreline iCast 2 hardware.

Prerequisites

Download agent files

Download the needed ThingWorx files as a .zip file to your development PC, and unzip the two files (code archive and .xml) to any convenient location.

Download 05X files

Get Started with ThingWorx

Go to the ThingWorx developer portal to sign up. The quickest way is to use their hosted service for a free 30-day trial.

  1. Once you have your account, log in, and click on the Trials icon (upper right corner of the screen). Wait for the server instance to be provisioned. You may have to refresh your browser if this takes more than a minute, and on subsequent restarts.

  2. You will get a Launch button. Click it to bring up the ThingWorx Composer in a separate tab. Then take care of a couple of preliminary items.

  3. Click » SECURITY at the bottom left, and look for Application Keys. Click on it and go to admin_key. Find the keyId value at the bottom; copy it to a text file for use later.

  4. Look towards the right at the bar on top for Import/Export. Click it, and import the .xml file you downloaded. It tells ThingWorx about your target board features.

  5. Go back to your ThingWorx developer portal tab. Spend some time getting familiar with ThingWorx by looking at Getting Started » Hello World.

Building ThingWorx Agent

To build a ThingWorx agent and the example application for the ARTIK 05X, you will be using the advanced development option to compile from source code.

Preparation

  1. Follow the usual procedure to clone the latest version of Tizen RT from GitHub. All our examples below show it being cloned to ~/TizenRT so adjust the command lines if you clone it elsewhere.

  2. Follow the usual procedure to configure and compile Tizen RT. Use the /nettest configuration and ensure that you can build without errors.

  3. Extract the code files from the archive you downloaded earlier.
    tar xvfz thingworx-agent-artik05x.tar.gz

    There will be two folders:

    • thingworx-agent – contains the entire set of ThingWorx libraries. The source code is taken from ThingWorx C SDK src folder, with TizenRT Makefile.

    • thingworx-sample – contains the ThingWorx example application. Based on the SimpleThing example code provided as part of ThingWorx C SDK, with TizenRT Makefile.

  4. Move the extracted packages to the right locations in the TizenRT tree, and change their directory names to thingworx.
    cd ~/thingworx-agent-artik05x (or to wherever you have extracted the files)
    mv thingworx-agent ~/TizenRT/external/thingworx
    mv thingworx-sample ~/TizenRT/apps/examples/thingworx

Extend Tizen RT to support ThingWorx

This procedure makes the ThingWorx agent and example application available for building into the Tizen RT image.

  1. Disable error messages. By default, certain warnings (defined in Werror compiler options) are treated as error messages. Disable these options for compilation. Look for these lines in ~/TizenRT/os/Make.defs, and change –Werror to –Wno-error.
    
    ARCHCFLAGS = -fno-builtin -mcpu=cortex-r4 -mfpu=vfpv3
    ARCHCXXFLAGS = -fno-builtin -fexceptions -mcpu=cortex-r4 -mfpu=vfpv3
    ifeq ($(QUICKBUILD),y)
    ARCHWARNINGS = -Wall -Wno-error -Wstrict-prototypes -Wshadow -Wundef -Wno-implicit-function-declaration -Wno-unused-function -Wno-unused-but-set-variable
    ARCHWARNINGSXX = -Wall -Wno-error -Wshadow -Wundef
    else
    ARCHWARNINGS = -Wall -Wno-error -Wstrict-prototypes -Wshadow -Wundef -Wno-implicit-function-declaration -Wno-unused-function -Wno-unused-but-set-variable
    ARCHWARNINGSXX = -Wall -Wno-error -Wshadow -Wundef
    # only version 4.9 supports color diagnostics
    ifeq "$(ARCHMAJOR)" "4"
    ifeq "$(ARCHMINOR)" "9"
      ARCHWARNINGS += -fdiagnostics-color=auto
      ARCHWARNINGSCC += -fdiagnostics-color=auto
    endif
    endif
    
    
  2. Add the ThingWorx libraries. In ~/TizenRT/os/FlatLibs.mk, add the bolded code block where indicated.
    
    # Add library for external support.
    TINYARALIBS += $(LIBRARIES_DIR)$(DELIM)libexternal$(LIBEXT)
    
    # Add library for ThingWorx SDK
    ifeq ($(CONFIG_THINGWORX_SDK), y)
    TINYARALIBS += $(LIBRARIES_DIR)$(DELIM)libTw$(LIBEXT)
    endif
    
    
    
  3. Add make clean instructions. In ~/TizenRT/external/Makefile, add the bolded code block below for removing ThingWorx agent intermediate files when running make clean .
    
    artiksdk_clean:
    ifeq ($(CONFIG_ARTIK_SDK),y)
            $(Q) $(MAKE) -C artik-sdk clean
    endif
    
    thingworx_clean:
    ifeq ($(CONFIG_THINGWORX_SDK), y)
    {tab}$(Q) $(MAKE) -C thingworx clean
    endif
    
    
    Note: {Tab} here indicates a TAB character, not eight spaces!
    Makefile formatting is stringent in this regard. If you are making the edits using vi, you can create a tab character like this:
    -- Go to INSERT mode
    -- Hit Ctrl-V (forces a literal insertion of the next key you hit)
    -- Hit the Tab key
    The make you do later will fail if you do not enter this Tab correctly.

  4. Enable the SDK. In ~/TizenRT/external/Kconfig, add the bolded config option below for enabling the ThingWorx SDK. Add the code block where indicated.
    
     select LWM2M_WAKAAMA_CLIENT
            ---help---
                    include the ARTIK SDK
    
    config THINGWORX_SDK
            bool "ThingWorx SDK"
            default n
            select NETUTILS_WEBSOCKET
            ---help---
                    include ThingWorx C SDK
    
    config IOTBUS
            bool "IoTBUS api"
            default n
            ---help---
    
    
  5. Add ThingWorx to the configuration using the Kconfig tool.
    1. Navigate to the os folder, and execute:
      make menuconfig
    2. In External Functions, enable ThingWorx SDK.


    3. In Application Configuration >> Examples, enable ThingWorx demo application

    4. Save and exit.
  6. Compile the ThingWorx agent.
    cd ~/TizenRT/external/thingworx
    make
    This will generate the libTw.a static library and copy the generated library to the appropriate location in the TizenRT tree.

If you do a make clean in the os directory, you need to repeat the above make to re-copy the library.

Configuring ThingWorx

Up to this point, you've been setting up Tizen RT to incorporate the ThingWorx agent. That's complete now. All you have left to do is:

  • Specify the server name and the app instance
    (hard-coded in the example ..._main.c file)

  • Recompile the code

  • Flash the image to the ARTIK module.

The server name and app instance would change if, for example, you decided to download and set up your own instance of the server.

Change Hostname, App Key

By default, the example application uses an instance of ThingWorx on port 8080 over HTTP. Change the ThingWorx host and application key in order to make the example application connect to your own instance. To make these changes:

  1. Edit the file noted.
    vi ~/TizenRT/apps/examples/thingworx/thingworx_example_main.c
  2. Find the section near the top of the file that looks like this:
      /* Server Details */
      #define TW_HOST "localhost"
      #define TW_PORT 8080
      #define TW_APP_KEY "ce22e9e4-2834-419c-9656-ef9f844c784c"
    and replace localhost with the hostname of your server (for the online hosted trial, it will be something like pp-180207193531.devportal.ptc.io).
  3. Change the App Key to a key that exists on your server. If running the hosted trial, this is the Application Keys keyId value you saved earlier. For this example, choose or create an app key that has Administrator privileges.

Re-compile and flash

Compile TizenRT again and flash the ARTIK 05X module after compilation. Connect your ARTIK 05X device to the USB port of your host machine as always. Then enter these commands.

cd ~/TizenRT/os
make
make download ALL (if using VirtualBox, don't forget to switch the USB ports first)

If you later do a make clean in the os directory, repeat Step 6 here.

Running ThingWorx

Every time you reset the ARTIK 05X board, you'll need to start Wi-Fi® and run the example application that calls the ThingWorx agent. In your end-user solution, you would provide a means of doing these steps autonomously (such as using on-boarding to select and preconfigure Wi-Fi).

Configure Wi-Fi

The TASH commands available to start Wi-Fi operation vary between early Tizen RT releases and later ones. If the instructions below do not seem to correspond, just use TASH 'help' to determine the correct syntax.

  1. Start wpa_supplicant in station (Wi-Fi client) mode.
    TASH>>wifi startsta
    *****************************************************************
    * Samsung System LSI wifi application for t20                   *
    *****************************************************************
    Link call back handles registered - per default!
    Starting supplicant in foreground...
    STA mode started successfully
    
    
  2. Configure your SSID and Password.
    TASH>>wifi join  _your_SSID_ _your_password_ 
    *****************************************************************
    * Samsung System LSI wifi application for t20                   *
    *****************************************************************
    Link call back handles registered - per default!
    Joining network SSID
    Security: wpa2_aes
    Passphrase: < password >
    Connected to network: bssid: d0:03:4b:d8:cd:08, ssid: < SSID >
    Successfully joined the network with SSID < SSID >
    
    
  3. Obtain an IP address on your device:
    TASH>>ifconfig wl1 dhcp
    IP address 10.0.1.31
    Netmask 255.255.255.0
    Gateway 10.0.1.1
    
    
  4. Do a ping test from your console and make sure you have an Internet connection.
    TASH>> ping www.google.com
    PING www.google.com (www.google.com) 32 bytes of data.count(10)
    40 bytes from 216.58.217.68: icmp_seq=1 ttl=255 time=90ms
    40 bytes from 216.58.217.68: icmp_seq=2 ttl=255 time=160ms
    40 bytes from 216.58.217.68: icmp_seq=3 ttl=255 time=120ms

Run the ThingWorx agent and app

On your ARTIK 05X console, launch the ThingWorx demo application.

TASH>>thingworx_example
TASH>>[FORCE] 2010-01-01 00:02:44,980: Starting up
[FORCE] 2010-01-01 00:02:46,60: twWs_Connect: Websocket connected!
[FORCE] 2010-01-01 00:02:46,520: BindEventHandler: Entity SimpleThing_1 was Bound
[FORCE] 2010-01-01 00:02:46,760: AuthEventHandler: Authenticated using appKey = ce22e9e4-2834-419c-9656-ef9f844c784c.  Userdata = 0x0

The console messages indicate whether a successful connection has been made with the server.

View streamed data from the ThingWorx Portal

Having created SimpleThing_1 on your ThingWorx server by importing the entity file ThingWorxEntities.xml, you should be able to see SimpleThing_1 in your Composer.

  • Click on SimpleThing_1 in the column to the left.

  • Select the Properties tab. Here you should see the 'isConnected' property set to 'true', indicating that the connection is successful.

SimpleThing_1 is bound for the duration of the application run time. To verify:

  • Go the Monitoring dropdown at the top right of the Composer
  • Select Remote Things.

The monitoring page of Remote Things should show a green check with information about SimpleThing_1.

From the SimpleThing_1 Properties tab, you can see the streamed properties data, including 'count' and 'location' from your ARTIK05X.

You've created a ThingWorx agent and application that sends data to the ThingWorx server. The 'count' and 'location' values coming back are not meaningful at this point since there are no inputs to the ARTIK board. The Shoreline – Modbus article shows how to provide that input.

Last updated on: