cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Axeda : Quick Model and Asset Report

No ratings

Several times in the past few months I was hit by a quick need to extract some data about Assets for a customer, and find myself continually hand-writing the code to do so.  Rather than repeat myself any more, I figure I can share my work - maybe PTC customers can benefit from the same effort. 

 

import static com.axeda.sdk.v2.dsl.Bridges.*
import com.axeda.drm.sdk.Context
import com.axeda.common.sdk.id.Identifier
import com.axeda.services.v2.*
import com.axeda.sdk.v2.exception.*

def retStr = "Device and Location Data\n" 

def modellist = [:] 

ModelCriteria mc = new ModelCriteria()
mc.modelNumber = "*"
tcount = 0
def mresults = modelBridge.find(mc)
while ( (mresults = modelBridge.find(mc)) != null  && tcount < mresults .totalCount) {
  mresults.models.each { res ->
    modellist[res.systemId] = res.modelNumber
    tcount++
  }
  mc.pageNumber = mc.pageNumber + 1
}

locationList = [:]
LocationCriteria lc = new LocationCriteria()
lc.name = "*"
tcount = 0
def lresults = locationBridge.find(lc)
while ( (lresults = locationBridge.find(lc)) != null  && tcount < lresults .totalCount) {
  lresults.locations.each { res ->
    locationList[res.systemId] = res.name
    tcount++
  }
  lc.pageNumber = lc.pageNumber + 1
}


AssetCriteria ac = new AssetCriteria()
ac.includeDetails = true 
ac.name = "*"

tcount = 0
def results = assetBridge.find(ac)
while ( (results = assetBridge.find(ac)) != null  && tcount < results .totalCount) {
  results.assets.each { res ->
    retStr += "ID: ${res.systemId}  MN: ${res.model.systemId},${modellist[res.model.systemId]} SN: ${res.serialNumber}  Name: ${res.name}  : Location  ${res.location.systemId},${locationList[res.location.systemId]}\n";
    tcount++
  }
  ac.pageNumber = ac.pageNumber + 1
}

return ["Content-Type": "application/text", "Content": retStr]

This will output data like so: 

 

ID: 31342  MN: 14682,CKGW SN: Axeda-CK-Windows10VBox  Name: Axeda-CK-Windows10VBox  : Location  1,Foxboro
ID: 26248  MN: 14682,CKGW SN: CK-CKAMINSKI0L1  Name: CK-CKAMINSKI0L1  : Location  1,Foxboro
ID: 30082  MN: 14682,CKGW SN: CK-GW1  Name: CK-GW1  : Location  1,Foxboro
ID: 26247  MN: 14681,CKGW-ManagedModel1 SN: CK-MM01  Name: CK-MM01  : Location  1,Foxboro

This let's me compare the internal systemId of the Asset, the internal systemId of the Model, and the internal systemId of the Location of the device.  This was to help me attempt to isolate an issue with orphaned devices not being returned in a report - exposing some duplicate locations and devices that needed corrections. 

 

You may find yourself needing to do similar things when building logic for Axeda, or eventually integrating or migrating to Thingworx.  Our v2 API bridges help "bridge" the gap.  

 

 

Version history
Last update:
‎Sep 11, 2018 01:58 PM
Updated by:
Labels (2)
Tags (2)