2018

Developer Community

January 2018 Previous month Next month

Use Case: You’ve published a model from Analytics Builder to Analytics Manager, and then used service CreateOrUpdateThingTemplateForModel on resource TW.AnalysisServices.ModelManagementServicesAPI. A thing created from the resulting template will have an infotable called “data” which needs to be populated in order to trigger an Analysis Event & Job.

 

For example you might have been following the online documentation for Analytics Manager > Working with Thing Predictor > Demo: Using Thing Predictor, link here.

 

This script makes it easy to create a line of test data into field "data" on your thing to trigger the analysis event & job. Also fields causalTechnique, goalName and importantFieldCount are set programmatically, these are needed for the analysis event & job.

 

Also this script might be useful as a general example of how to write to an infotable property on a thing.

 

The JavaScript code is shown here and also attached as a text file to this post:

 

me.causalTechnique = 'FULL_RANGE'

me.goalName = 'predict_Compressor_failure'

me.importantFieldCount = 3


// ThingPredictor.test_3f1a6a31-e388-4232-9e47-284572658a4a.InputParamsdataDataShape entry object

//var newEntry = new Object();


var params = {

infoTableName : "InfoTable",

dataShapeName : "ThingPredictor.test-integer_afebaef3-b2cf-4347-824c-a39c11ddbb4a.InputParamsdataDataShape"

};


// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(ThingPredictor.test_3f1a6a31-e388-4232-9e47-284572658a4a.InputParamsdataDataShape)

var myInfoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);


// 2 - CREATE INFOTABLE ROW USING object

var newEntry = new Object();

newEntry._Pressure = 10.5; // NUMBER

newEntry._Temperature = 45.1; // NUMBER

newEntry._VibrationX = 81; // NUMBER

newEntry._VibrationY = 65; // NUMBER

//newEntry.key = 4; // STRING - isPrimaryKey = true


// 3 - ADD INFOTABLE ROW USING TO INFOTABLE

myInfoTable.AddRow(newEntry);


// 3 – PERSIST INFOTABLE TO THE THING PROPERTY ‘data’

me.data = myInfoTable;

Pushbullet is a lightweight notifications platform and can be a way to explore Alerts and Subscriptions

 

Basically create an an Alert on a property and Subscribe to that Alert

 

Adding Alert to Property Humidity

 

 

Adding Subscription

 

 

The PTC-PushBulletHelper is just a generic Thing with a service called PushNotification

 

 

 

var json = {

    "body": Message,

    "title":"Temperature fault",

    "type":"note"

};

 

var accessHeader = {

    "Access-Token": "o.Hnm2DeiABcmbwuc7FSDmfWjfadiLXx2M"

};

 

var params = {

     proxyScheme: undefined /* STRING */,

    headers: accessHeader /* JSON */,

     ignoreSSLErrors: undefined /* BOOLEAN */,

     useNTLM: undefined /* BOOLEAN */,

     workstation: undefined /* STRING */,

     useProxy: undefined /* BOOLEAN */,

     withCookies: undefined /* BOOLEAN */,

     proxyHost: undefined /* STRING */,

     url: 'https://api.pushbullet.com/v2/pushes' /* STRING */,

     content: json /* JSON */,

     timeout: undefined /* NUMBER */,

     proxyPort: undefined /* INTEGER */,

     password: undefined /* STRING */,

     domain: undefined /* STRING */,

     username: undefined /* STRING */

};

 

// result: JSON

var result = Resources["ContentLoaderFunctions"].PostJSON(params);

 

 

 

You can test the Helper PushNotification service

 

 

Next you can test the subscription

 

 

 

 

 

 

I have put together a small sample of how to get property values from a Windows Powershell command into Thingworx through an agent using the Java SDK.

 

In order to use this you need to import entities from ExampleExport.xml and then run SteamSensorClient.java passing in the parameters shown in run-configuration.txt (URL, port and AppKey must be adapted for your system). ExampleExport.xml is a sample file distributed with the Java SDK which I’ve also included in the zipfile attached to this post. You need to go in Thingworx Composer to Import/Export … Import from File … Entities … Single File … Choose File … Import.


Further instructions / details are given in this short video:


Filter Blog

By date:
By tag: