Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
This project will introduce more complex aspects of the ThingWorx C SDK and help you to get started with development. Following the steps in this this guide, you will be ready to develop your own IoT application with the ThingWorx C SDK. We will teach you how to use the C programming language to connect and build IoT applications to be used with the ThingWorx Platform.
NOTE: This guide's content aligns with ThingWorx 9.3. The estimated time to complete ALL 3 parts of this guide is 60 minutes.
Download the completed files for this tutorial: ThingWorx C Edge SDK Sample Files.zip. This tutorial will guide you through working with the C SDK on differing levels. Utilize this file to see a finished example and return to it as a reference if you become stuck creating your own fully fleshed out application. Keep in mind, this download uses the exact names for Entities used in this tutorial. If you would like to import this example and also create Entities on your own, change the names of the Entities you create.
In order to compile C code, you need a C compiler and the ThingWorx C Edge SDK available in the PTC Support download site. It will be helpful to have CMake installed on your system. CMake is a build tool that will generate make or project files for many different platforms and IDEs.
Operating System Notes
Windows | You will need a 3rd party compiler such as MinGW GCC, Cygwin GCC or you can follow these Microsoft instructions to download and use the Microsoft Visual C++ Build Tool. |
Mac | Download the Apple Developer Tools. |
Linux/Ubuntu | A compiler is included by default. |
NOTE: You can use CMake, version 2.6.1 or later to build projects or make files, which then are used to build the applications that you develop with the C SDK.
Before you can begin developing with the ThingWorx C SDK, you need to generate an Application Key and modify the source code file. You can use the Create an Application Key guide as a reference.
Linux/Ubuntu | gedit main.c OR vi main.c |
Mac | open –e main.c |
Windows | start main.c |
/* Server Details */
#define TW_HOST "https://pp-XXXXXXXXX.devportal.ptc.i"
#define TW_PORT 80
#define TW_APP_KEY "e1d78abf-cfd2-47a6-92b7-37ddc6dd34618"
NOTE: Using the Application Key for the default Administrator is not recommended. If administrative access is absolutely necessary, create a User and place the user as a member of Admins.
To test your connection, you will only need to update the main.c in the SteamSensor example folder.
CMake can generate Visual Studio projects, make build files or even target IDEs such as Eclipse, or XCode. CMake generates a general description into a build for your specific toolchain or IDE.
mkdir bin
cd bin
cmake ..
CMake has now produced a set of project files which should be compatible with your development environment.
Operating System Command Notes
Unix | make | A set of make files |
Windows | msbuild tw-c-sdk.sln /t:build | A visual studio solution |
NOTE: CMake does its best to determine what version of Visual Studio you have but you may wish to specify which version to use if you have more than one installed on your computer. Below is an example of forcing CMake to use a specific version of Visual Studio: cmake -G "Visual Studio 15 2017" .. If your version of Visual Studio or other IDE is unknown, use cmake -G to see a list of supported IDEs.
You also have the alternative of opening the tw-c-sdk.sln from within Visual Studio and building in this IDE.
NOTE: By default, CMake will generate a build for the creation of a release binary. If you want to generate a debug build, use the command:
cmake -DBUILD_DEBUG=ON ..
Once your build completes you will find the build products in the CMake directory (see example below). From here, open the project in your IDE of choice.
NOTE: You should receive messages confirming successful binding, authentication, and connection after the main.c file edits have been made.
Operating System Files Description
Unix | ./bin/src/libtwCSdk_static.a | Static Library |
Unix | ./bin/src/libtwCSdk.so | Shared Library |
Unix | ./bin/examples/SteamSensor/SteamSensor | Sample Application |
Windows | .\bin\src\<Debug/Release>\twCSdk_static.lib | Static Library |
Windows | .\bin\src\<Debug/Release>\twCSdk.dll | Shared Library |
Windows | .\bin\examples\<Debug/Release>\SteamSensor\SteamSensor.exe | Sample Application |
Click here to view Part 2 of this guide.