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 C Edge SDK is a powerful component of the ThingWorx architecture. The C Edge SDK 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 installation and usage instructions for setting up the ThingWorx C Edge SDK with the Samsung ARTIK 710 or 530 device.

Preparation

Make sure you have set up Wi-Fi® and updated your image as noted .

Step 1. Upgrade your OS. ARTIK modules come pre-loaded with a specific Linux operating system (OS), depending on module type:

  • Ubuntu only (ARTIK 530s and 710s modules)
  • Fedora upgradable to Ubuntu (ARTIK 530 and 710 standard modules)
  • Fedora 24 only (ARTIK 520)
  • Fedora 22 only (ARTIK 1020).

Fedora is more compact than Ubuntu, but its support lifetime is limited compared to Ubuntu (5 yrs). Move to Ubuntu now to avoid reloading all your software and tools later. Click to install the latest ARTIK image and choose the newest image for your module.

Step 2. Connect to a Network. To load software, you'll need to either connect an Ethernet cable or set up your Wi-Fi® network and password.

Try out "on-boarding." If you like, jump ahead to the Connect to the World article to set your network connection using a simple smart phone app.

Step 3. Upgrade installed packages. Start by reading a primer on package management systems. Now you're ready for the latest software updates.

In the version of Ubuntu we use, apt-get and apt are nearly interchangeable. We use apt but you can feel free to use either.

Ubuntu

apt update

apt upgrade

apt install build-essential

Fedora

Verify your repository first as noted below, then type
dnf upgrade

Note: A patch is available in the repositories for the KRACK vulnerability of wpa_supplicant. Simply run the normal update/upgrade process to implement the fix. You can also patch just the affected package as follows.

Ubuntu

apt update

apt install --only-upgrade wpasupplicant

Fedora

dnf upgrade wpa_supplicant

Step 4. Install a development environment on your PC. If you loaded the ARTIK IDE earlier, you're nearly done – go to the Update SDK article to check for updates. If not, go to Software Tools to get an overview of what's available.

Step 5. Update SDK. ARTIK API support is included automatically when you install the ARTIK IDE. For the latest Ubuntu images (os_18.05.00 or newer), just update the SDK version on the board.

apt install libartik-sdk

For Fedora or older Ubuntu images, you need to enable repository access on your ARTIK board first and then install the SDK as directed in that article.

Step 6. Add additional packages. You'll eventually want to add other software, typically using a package installer. We've included instructions throughout the articles about what packages you'd need for a specific feature (like adding Node-RED as we describe in the Tutorials).

Verifying Fedora repository

At the conclusion of active development for a given Fedora release, Fedora repositories may be phased out and moved to a permanent archive. If you are having any problems with dnf update or package downloads, make sure the repository URLs point to the right locations.

You'll find the information in /etc/yum.repos.d/ in various files. You can either change them manually or use a command like the one below to make the substitution.

sed -i 's|archive\.fedoraproject\.org\/pub|archives\.fedoraproject\.org\/pub\/archive|g' /etc/yum.repos.d/*

You'll also need to install utilities to uncompress the SDK, generate make files, and provide OpenSSL headers.

Ubuntu:
apt install unzip cmake libssl-dev

Installation of ThingWorx C Edge SDK and Sample Files

  1. Download the ThingWorx C Edge SDK to your host machine.
     » ThingWorx Quickstart Tutorial
    You'll find the download link under "Required Setup".

  2. Use scp to transfer the downloaded zip file to your ARTIK module. A suggested location is the /home directory. If using Mac or Linux on your host machine, you can run the command below to copy the file to your target ARTIK board.
    scp 220-C-SDK-2-0-2-386.zip root@_board_IP_address_:/home/

  3. On your ARTIK board, unzip the SDK.
    cd /home
    unzip 220-C-SDK*

  4. Change to your newly created directory.
    cd c-sdk-2.0.2.386-master

  5. For the ARTIK 710 only, download the CMakeLists.txt file and replace the original file in the directory (for reasons below).

  6. Create a /bin directory under C-SDK to build in.
    mkdir bin
    cd bin

  7. Run cmake to generate Makefiles.
    cmake ..

    CMake will produce a set of project files that are compatible with your development environment.

  8. Run make to compile the SDK and sample files. Executables will be generated under the bin directory.

    make

On the ARTIK 710, the default CMake configurations will not work out-of-the-box due to the platform setting. If you do a diff between the new CMakeLists.txt file and its original version, you can . ARTIK 710 is running on an aarch64 based microprocessor; when {PLATFORM} is detected as aarch64, all environment variables and compiler flags must be defined accordingly.

71,75d70
<         elseif (${PLATFORM} MATCH "aarch64")
<                 set(OS "linux")
<                 set(ARCHITECTURE "arm-aarch64")
<                 set(CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../TOOLS/gcc-linux-arm-aarch64-cross/arm-unknown-linux-gnueabi)
<                 set(CMAKE_C_COMPILER ${CMAKE_CURRENT_SOURCE_DIR}/../TOOLS/gcc-linux-arm-aarch64-cross/bin/arm-unknown-linux-gnueabi-gcc)
129,131d123
<                 elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
<                         set(ARCHITECTURE "arm-aarch64")
<                         set(PLATFORM "linux-arm-aarch64")
269,270d260
<         elseif (${PLATFORM} MATCHES "aarch64")
<                 set(OPENSSL_PLATFORM_DIR ${OPENSSL_INTERNAL_ROOT}/gcc-linux-arm-aarch64-cross)
423,439d412
<         elseif (${PLATFORM} MATCHES "aarch64")
<                 # set linker flags
<                 set(
<                         CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread -fPIC -Wl,--gc-sections"
<                         CACHE INTERNAL "" FORCE
<                 # set defines and compiler flags
<                 add_definitions(
<                         -DLTC_NO_ROLC
<                         -D_GNU_SOURCE
<                         -D_FILE_OFFSET_BITS=64
<                         -DCC_GNU
<                         -pthread
<                         -fPIC
<                         -ffunction-sections
<                         -fdata-sections
<                 )

SteamSensor Example

To understand the process of exposing data to ThingWorx, lets start with an example that comes with the SDK sample file SteamSensor. The SteamSensor example exposes a few simple, simulated properties to the server.

  1. Start by looking in the c-sdk-2.0.2.386-master/examples/SteamSensor/src directory.
    cd ../examples/SteamSensor/src
    ls
    SteamThing.c SteamThing.h gps-route.h main.c

  2. The main.c file contains the program to create and update properties on the ThingWorx server. You can view the file by typing the command
    vi main.c

Configuring and Running the SteamSensor Example Application

In preparation, bring up the ThingWorx Developer Portal and ThingWorx Composer. You'll need it during setup to obtain the keyId and during operation to monitor devices and set properties.

Step 1. Import the SteamSensor entities

In the _sdk_/examples/SteamSensor/import folder, there is an Entities_SteamSensor.xml file. You can import it to your ThingWorx Composer by selecting Import » From File » Choose Entities_SteamSensor.xml. You should be able to see newly added entities like SteamSensor Thing, SteamSensorValueStream Thing, StreamSensor Mashup, SteamSensorKey Application Key, etc.

Click on SteamSensorKey Application Key and make a note of the keyId, that is the application key that will be used in the local application.

Step 2. Change the Hostname, App Key

This guide assumes you are running an instance of ThingWorx on port 443 over HTTPS, but the default for the SteamSensor example is to run on localhost. Make changes to these settings by editing main.c as follows.

  1. cd /home/c-sdk-2.0.2.386-master/examples/SteamSensor/src/

  2. vi main.c

  3. Find the section near the top of the file that looks like this:

    /* Server Details */
    #define TW_HOST "localhost"
    #define TW_APP_KEY "e1d78abf-cfd2-47a6-92b7-37dc6dd34618"

and replace localhost with the hostname of your server (for the online hosted trial, it will be something like pp-180207193531.devportal.ptc.io).

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

Step 3. Disable command line parameters parsing

The sample application enforces command line parameters parsing, entry of hostname, port, application key, etc. every time the application is started. Disable this by commenting out the lines below in the main.c main() function.

/* Parse command line parameters */
/* if (argc == 1){
     printf("Syntax: %s < hostname > < port > < appKey > < thingname >\n",argv[0]);
     exit(0);
} */

Step 4. Compile the SteamSensor example

To incorporate the changes made, recompile the program. Go back to the _sdk_/bin directory to run make.

cd ../../../bin
make

Step 5. Run the SteamSensor example

Run the finished program, which can be found in the ./bin/examples/SteamSensor directory. Sample output can be seen .

[root@artik bin]# ./examples/SteamSensor/SteamSensor 
[FORCE] 2017-12-28 06:13:28,598: Starting up...
[WARN ] 2017-12-28 06:13:28,599: SDK Version: 2.0.2
[WARN ] 2017-12-28 06:13:28,599: TLS Library: OpenSSL
[WARN ] 2017-12-28 06:13:28,599: TLS Library Version: 1.0.2l
[DEBUG] 2017-12-28 06:13:28,599: twWs_Create: Initializing Websocket Client for PP-1712280444BL.devportal.ptc.io:443//Thingworx/WS
[DEBUG] 2017-12-28 06:13:28,599: twTlsClient_Create: Initializing TLS Client
[DEBUG] 2017-12-28 06:13:28,622: twApi_Initialize: Websocket Established after 0 tries
[DEBUG] 2017-12-28 06:13:28,623: subscribedPropsMgr_Initialize: Initializing subscribed properties manager
[TRACE] 2017-12-28 06:13:28,624: twFileManager_AddVirtualDir: Adding __staging__ to vdir list
[TRACE] 2017-12-28 06:13:28,625: twFileManager_AddVirtualDir: Adding logs to vdir list
[TRACE] 2017-12-28 06:13:28,625: twSubscribedPropsMgr_SetPropertyVTQ: Property TemperatureLimit pushType is ALWAYS
[TRACE] 2017-12-28 06:13:28,625: twSubscribedPropsMgr_QueueValueForSending: Updating saved property value. Property: TemperatureLimit. Folding is OFF
[TRACE] 2017-12-28 06:13:28,625: twSubscribedPropsMgr_QueueValueForSending: Creating property list for entity SteamSensor
[TRACE] 2017-12-28 06:13:28,625: twSubscribedPropsMgr_QueueValueForSending: Adding property TemperatureLimit to entity SteamSensor list. Source: RAM
[TRACE] 2017-12-28 06:13:28,625: twSubscribedProps_Write: Property TemperatureLimit being queued to be sent to server
[TRACE] 2017-12-28 06:13:28,625: twSubscribedPropsMgr_SetPropertyVTQ: Property Logfile pushType is ALWAYS
[TRACE] 2017-12-28 06:13:28,625: twSubscribedPropsMgr_QueueValueForSending: Updating saved property value. Property: Logfile. Folding is OFF
[TRACE] 2017-12-28 06:13:28,626: twSubscribedPropsMgr_QueueValueForSending: Adding property Logfile to entity SteamSensor list. Source: RAM
[TRACE] 2017-12-28 06:13:28,626: twSubscribedProps_Write: Property Logfile being queued to be sent to server
[DEBUG] 2017-12-28 06:13:28,626: added SteamSensor to boundList
[DEBUG] 2017-12-28 06:13:28,626: twApi_BindThings: not currently connected, only binding things to api
[DEBUG] 2017-12-28 06:13:28,626: twMessage_Delete:  Deleting BIND Message: 1
[TRACE] 2017-12-28 06:13:28,626: twApi_Connect: Delaying 1 milliseconds before connecting
[DEBUG] 2017-12-28 06:13:28,627: twTlsClient_Reconnect: Re-establishing SSL context
[DEBUG] 2017-12-28 06:13:28,632: twTlsClient_Connect: Connecting to server
[DEBUG] 2017-12-28 06:13:28,932: twTlsClient_Connect: TLS connection established
[TRACE] 2017-12-28 06:13:28,933: twWs_Connect: Connected to PP-1712280444BL.devportal.ptc.io:443
[TRACE] 2017-12-28 06:13:28,933: twWs_Connect: Sent request:
GET /Thingworx/WS HTTP/1.1
User-Agent: ThingWorx C SDK
Upgrade: websocket
Connection: Upgrade
Host: PP-1712280444BL.devportal.ptc.io
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: AcSnChI/N/h07tk7IWzpnQ==
Max-Frame-Size: 8192
appKey: 9b5b577e-2379-4ca1-ba0c-d5cd4c8da7ad

Viewing the streamed data from ThingWorx Portal

From your ThingWorx Composer, click on SteamSensor Thing and select the Properties tab. Here you should see the isConnected property set to true, indicating that the connection is successful. SteamSensor is bound for the duration of the application run time. To verify, go the Monitoring dropdown at the top right of the Composer, then select Remote Things. The monitoring page of Remote Things should show a green check with information about SteamSensor.

Also, From SteamSensor Properties tab, you can see the streamed properties data, including temperature, pressure etc. telemetry data from your ARTIK530.

For additional guidance and examples, refer to the C SDK tutorial at https://developer.thingworx.com/

Last updated on: