SCM Client Example
This sample application demonstrates how to create a console application that connects to the ThingWorx Platform to expose your device as a target for an SCM deployment. If you already understand the parameters to set, you can skip to Running the scm_client Appliication..
If you are building an executable on Windows (for example, this scm_client application or the scm_service sample application, you must include the following so that the CRT or PEM file can be read from disk: #include "applink.c".
Parameters to Set
Descriptions of each parameter that you need to set when running this example follow:
-h hostname — The name of the computer where your ThingWorx platform is running. The value for this parameter is not a URL. It can be a DNS name, localhost, or a numeric IP address.
-p port — The port that your ThingWorx application is using on your server. Common values are 80, 8080, or 443
-k appKey — Generate an application key using ThingWorx Composer and copy it to the value of this parameter. This key acts as the credentials that this service should use when it connects to the platform.
-w whitelist — A path to a CSV file listing the extensions and applications used to execute scripts which have this extension.
-n name — The name of the Thing that you have created in ThingWorx to represent this device. This will be the name of your device in the SCM console. The Thing should have the Thing Template, TW.RSM.Template.AssetWithTunnelsAndFileTransfer and the following Thing Shapes applied:
-l logLevel — You may reduce your log level before you start the service by setting this value. Acceptable values are:
0 TW_TRACE — Application execution tracing.
1 TW_DEBUG — Debug messages for development.
2 TW_INFO — General information messages.
3 TW_WARN — Warning messages.
4 TW_ERROR — Error messages.
Your log level will default to 0 if no value is given.
-s stagingDirectory — A working directory where files will be uploaded to this device and from which the scripts will be run. This directory must be writable from your service.
-v validationFile — This configuration file is optional and is used to enable digital signature support on the client. Here is an example of the contents of this file:

# Sample Validation File
validationEnabled — Allows you to switch on or off the validation of a package using digital signatures.
validatePublicCertificate — Requires that the public certificate come from a known provider through a valid trust chain.
pathToPublicKeyFile — The path on the local file system to the public key file in RSA pem format to use for validation. Note that this key is not protected by a password and should have restricted access on your file system. Exposure of this public key is not a security risk as it cannot be used to reverse engineer the original private key that was used to sign your package. However, alteration of the public key on the device could allow an unauthorized user to replace the public key and deploy packages in the future.
requiredCN — This parameter specifies a domain name that must match the CN field of the public certificate for it to be used for validation. If this field is not blank, your public key will be rejected, and no packages will be able to be deployed. If the requiredCN is blank, there are no CN field requirements.
Running the scm_client Application
The following procedure for running the scm_client example application provides information for both Linux and Windows users. If you need assistance with the parameters, refer to Parameters to Set above.
1. Import the XML file that contains the SCM Client ThingWorx Platform Thing; its location is./path/to/tw-edge-extensions/scm/src/test/resources/Things_SampleScmDevice.xml.
2. Configure your whitelist at /path/to/tw-edge-extensions/scm/bin/examples/scm_client/example-whitelist.txt. Make sure that .sh and .bat files are whitelisted:

# This is a sample whitelist
# please review it before using it in production
bas,c:\program files\cscript.exe
bat,cmd /c
The whitelist above allows the execution of scripts written in Linux Shell Script (sh), node.js (js), BASIC (bas), batch (bat), and Python (py).
3. Run the application and specify the proper parameters to connect to your utilities-enabled ThingWorx Platform:
Linux Users
a. Open a terminal and navigate to the same directory as the application binary, /path/to/tw-edge-extensions/scm/bin/examples/scm_client.
b. Run the application as follows:
./scm_client -h <hostname> -p <port> -k <appkey>
-w </path/to/tw-edge-extensions/scm/bin/examples/scm_client/example-whitelist.txt> -l <loglevel>
A linefeed has been inserted for formatting purposes after <appkey>. If you copy this syntax, remove the linefeed before running the command.
Windows Users (Running in Visual Studio)
a. Right-click the scm_client project in Visual Studio, and select it as your startup project.
b. Configure the properties of the project, and set the command-line arguments to
-h <hostname> -p <port> -k <appkey> -w <C:\path\to\tw-edge_extensions\examples\scm_client\example-whitelist.txt> -l <loglevel>
c. Start the project in Visual Studio.
Windows Users (Running from a Command Prompt)
a. Open a Command Prompt and navigate to the binary directory, C:\path\to\tw-edge-extensions\scm\cmake-windows-debug\examples\<Release|Debug.
b. Run the application, as follows:
scm_client.exe -h <hostname> -p <port> -k <appkey>
-w <C:\path\to\tw-edge_extensions\examples\scm_client\example-whitelist.txt> -l <loglevel>
If you try to execute from the same directory as the executable, such as C:\path\to]tw-edge-extensions\scm\cmake-windows-debug\examples\Debug, you will need to adjust the TWXLIB environment variable.
A linefeed has been inserted for formatting purposes after <appkey>. If you copy this syntax, remove the linefeed before running the command.
Was this helpful?