Latest Version: 1.0.0
This library allows your agent code to work with the ThingWorx platform via the ThingWorx REST API.
This version of the library supports the following functionality:
You can view the library’s source code on GitHub. Click here to see information on the available versions of this library.
To include this library in your project, add
#require "ThingWorx.agent.lib.nut:1.0.0"
at the top of your agent code
Before using the library you need to have:
https://PP-1802281448E8.Devportal.Ptc.Io
All requests that are made to the ThingWorx platform occur asynchronously. Every method that sends a request has an optional parameter which takes a callback function that will be executed when the operation is completed, whether successfully or not. The callback’s parameters are listed in the corresponding method description, but every callback has at least one parameter, error. If error is null
, the operation has been executed successfully. Otherwise, error is an instance of the ThingWorx.Error class and contains the details of the error.
Some methods require callbacks to be specified, others need only be passed a callback if you wish.
This method returns a new ThingWorx instance.
Parameter | Data Type | Required? | Description |
---|---|---|---|
endpoint | String | Yes | ThingWorx platform endpoint. Must include the scheme, eg. "https://PP-1802281448E8.Devportal.Ptc.Io" |
appKey | String | Yes | ThingWorx Application Key. For more information, please see the ThingWorx documentation |
#require "ThingWorx.agent.lib.nut:1.0.0"
const MY_PLATFORM_ENDPOINT = "<YOUR_PLATFORM_ENDPOINT>";
const MY_APP_KEY = "<YOUR_THINGWORX_APP_KEY>";
tw <- ThingWorx(MY_PLATFORM_ENDPOINT, MY_APP_KEY);
This method creates a new Thing, enables and restarts it. For more information, please see the ThingWorx documentation.
Parameter | Data Type | Required? | Description |
---|---|---|---|
thingName | String | Yes | Name of the new Thing. Must be unique across the ThingWorx platform instance |
thingTemplateName | String | Optional | A Thing Template which may be used for the Thing creation. If not specified, the standard ThingWorx "GenericThing" template is used. For more information, please see the ThingWorx documentation |
callback | Function | Optional | Executed once the operation is completed |
This method returns nothing. The result of the operation may be obtained via the callback function, which has the following parameter:
Parameter | Data Type | Description |
---|---|---|
error | ThingWorx.Error | Error details, or null if the operation succeeds |
This method checks if Thing with the specified name exists.
Parameter | Data Type | Required? | Description |
---|---|---|---|
thingName | String | Yes | Name of the Thing |
callback | Function | Yes | Executed once the operation is completed |
This method returns nothing. The result of the operation may be obtained via the callback function, which has the following parameters:
Parameter | Data Type | Description |
---|---|---|
error | ThingWorx.Error | Error details, or null if the operation succeeds |
exist | Boolean | true if the Thing exists, or false if the Thing does not exist or the operation fails |
This method deletes Thing with the specified name.
Parameter | Data Type | Required? | Description |
---|---|---|---|
thingName | String | Yes | Name of the Thing |
callback | Function | Optional | Executed once the operation is completed |
This method returns nothing. The result of the operation may be obtained via the callback function, which has the following parameter:
Parameter | Data Type | Description |
---|---|---|
error | ThingWorx.Error | Error details, or null if the operation succeeds |
This method creates a new Property of the specified Thing and restarts the Thing. For more information, please see the ThingWorx documentation.
Parameter | Data Type | Required? | Description |
---|---|---|---|
thingName | String | Yes | Name of the Thing |
propertyName | String | Yes | Name of the new Property. Must be unique across the specified Thing |
propertyType | String | Yes | Type of the new Property. Must be one of the types described in the ThingWorx documentation |
callback | Function | Optional | Executed once the operation is completed |
This method returns nothing. The result of the operation may be obtained via the callback function, which has the following parameter:
Parameter | Data Type | Description |
---|---|---|
error | ThingWorx.Error | Error details, or null if the operation succeeds |
This method sets a new value of the specified Property. For more information, please see the ThingWorx documentation.
Parameter | Data Type | Required? | Description |
---|---|---|---|
thingName | String | Yes | Name of the Thing |
propertyName | String | Yes | Name of the Property |
propertyValue | Boolean, Integer, Float, String, Key-Value Table, Blob, Null |
Yes | New value of the Property |
callback | Function | Optional | Executed once the operation is completed |
This method returns nothing. The result of the operation may be obtained via the callback function, which has the following parameter:
Parameter | Data Type | Description |
---|---|---|
error | ThingWorx.Error | Error details, or null if the operation succeeds |
This method enables (value is true
) or disables (value is false
) the library debug output (including error logging). It is disabled by default. The method returns nothing.
This class represents an error returned by the library and has the following public properties:
null
if the type property is LIBRARY_ERRORnull
if the type property is LIBRARY_ERROR.The Electric Imp Dev Center documents the latest version of the library. For past versions, please see the Electric Imp public GitHub repos listed below.
Version | Source Code | Notes |
---|---|---|
1.0.0 | GitHub | Initial release |
The ThingWorx class is licensed under MIT License.