ThingWorx WebSocket-based Edge MicroServer (WS EMS) and Lua Script Resource (LSR) > Using ThingWorx Asset Advisor with WS EMS and LSR > Lua Scripts and Software Content Management (SCM)
  
Lua Scripts and Software Content Management (SCM)
SCM services on the Lua Script Resource (LSR) are provided by a pair of Lua scripts
softwareupdate.lua — A script that exposes services that can be used to download and install a software package
swupdate.lua — A Thing Shape that wraps calls to softwareupdate.lua. Needs to be extended from in a Thing Template for a lua Thing to support SCM services..
REST API
This section lists and briefly definies the REST APIs that you can use for SCM with the LSR.
Trigger Update Action — Start
Description
Starts a Software Update
URI
scripts/Thingworx/[ThingName]/Services/TriggerUpdateAction
Type
POST
Headers
Content-Type: application/json
Body
{
"action" : "start",
"params" : {
"id" : 1234,
"name" : "Name",
"thing" : "Thing",
"repository" : "Repository",
"path" : "Path",
"script" : "Script",
"updateManager" : "updateManager"
},
}
Side Effects
Sets internal state to notified, which will quickly transition to waitingForDownload in the state machine.
Triggers a call to the UpdateState service on the updateManager Thing to set the State property to 'notified'.
Trigger Update Action — Abort
Description
Aborts a software update.
URI
scripts/Thingworx/[ThingName]/Services/TriggerUpdateAction
Type
POST
Headers
Content-Type: application/json
Body
{
"action" : "abort"
"params" : {
"id" : 1234
}
}
Side Effects
Sets internal state to aborted. Job metadata will be reset to nil.
Triggers a call to the CompleteDeliveryTarget service on the updateManager with failure metadata.
Trigger Update Action — Download
Description
Notifies the LSR that a file is b eing downloaded.
URI
scripts/Thingworx/[ThingName]/Services/TriggerUpdateAction
Type
POST
Headers
Content-Type: application/json
Body
{
"action" : "download"
"params" : {
"id" : 1234
}
}
Side Effects
Sets internal state to downloading.
Triggers a call to the UpdateState service on the updateManager Thing to set the State property to downloading.
Triggger Update Action — Downloaded
Description
Notifies the LSR that a file has been downloaded
URI
scripts/Thingworx/[ThingName]/Services/TriggerUpdateAction
Type
POST
Headers
Content-Type: application/json
Body
{
"action" : "downloaded"
"params" : {
"id" : 1234
}
}
Side Effects
Sets internal state to downloaded, which will quickly transition to waitForInstall in the state machine.
Triggers a call to the UpdateState service on the updateManager Thing to set the State property to downloaded.
Schedule Download
Description
Schedules a software package ffor download.
URI
scripts/Thingworx/[ThingName]/Services/ScheduleDownload
Type
POST
Headers
Content-Type: application/json
Body
{
"time" : "123456789" }
}
Side Effects
Sets the job.downloadTime property to time. While in the waitForDownload state, the state machine will check each tick to see if job.downloadTime has been reached. If it has, it will call the StartDownload service on the updateManager Thing.
Schedule Install
Description
Schedules the installation of a package.
URI
scripts/Thingworx/[ThingName]/Services/ScheduleInstall
Type
POST
Headers
Content-Type: application/json
Body
{
"time" : "123456789" }
}
Side Effects
Sets the job.installTime property to time. While in the waitForInstall state, the state machine will check each tick to see if job.installTime has been reached. If it has, it will call the UpdateState service on the updateManager Thing to set the State property to installing.
Advanced REST Client Project
You can use Advanced Rest Client (ARC) for Chrome to send pre-configured REST calls to the LSR by importing the Lua Script Resource Project. For example:
You must set the Thingname environment variable to the name of your lua Thing.
SCM State Machine
The following diagram shows the states of a Software Update Package and how the package may flow through them The red lines show the flow when an error occurs or the Abort action is called. The black lines show the flow for a package as each stage is successful, and finally the green line indicates that the package was successfully downloaded and installed.