EPl Apps, Get device Name having the ID

Hello All,
what is the API call that I have to use in the EPL apps to get the device name having the ID?
Thank you and let me know.

Hey, there’s an example on how to query for Managed Objects here. See also the examples about querying data stated here: Built-in actions - Cumulocity IoT Guides

I am trying out the example, but I don’t think it is very clear to me.
In the log I get all the machines when in reality I just want to get the parent device of the child device, having the child device Id.
Also, in the log after a while I could find the exact machine I was looking for, but how can I get as a string only the device name (circled in red in the image)?


Can you show me maybe with a little snippet of code?

Can you clarify what you are actually looking for?

The original request is asking for a snipped to get the name of a specific device you already know the ID for. In which case all you have to do is something like (please ignore any typos)

monitor.subscribe(FindManagedObjectResponse.SUBSCRIBE_CHANNEL);
FindManagedObject fmo := new FindManagedObject;
fmo.reqId := Util.generateReqId();
fmo.deviceId := "device_id"; // replace this with the device id 

on FindManagedObjectResponse(reqId=fmo.reqId) as resp
and not FindManagedObjectResponseAck((reqId=fmo.reqId) {
     ManagedObject mo := resp.managedObject;
     log "Device name is : " + mo.name at INFO;
}

But if you want to get the parent device of a child device, you need to perform multiple queries, to start, see Cumulocity IoT - OpenAPI Specification

  • Get the parent Id of a child device by querying for the childDeviceId and adding ‘withParents=true’ query param
  • Once you get the list of parentId, If you want to get the parent name, then perform another query to retrieve the parent managed Object.
monitor.subscribe(FindManagedObjectResponse.SUBSCRIBE_CHANNEL);
FindManagedObject fmo := new FindManagedObject;
fmo.reqId := Util.generateReqId();
fmo.deviceId := "device_id"; // replace this with the device id 
fmo.params.add("withParents", "true");

on FindManagedObjectResponse(reqId=fmo.reqId) as resp
and not FindManagedObjectResponseAck((reqId=fmo.reqId) {
    ManagedObject mo := resp.managedObject;
    log "Device parent Ids : " + mo.deviceParentIds.toString() at INFO;
    if mo.deviceParentIds.size() > 0 {

        FindManagedObject fmo1 := new FindManagedObject;
        fmo1.reqId := Util.generateReqId();
        fmo1.deviceId := mo.deviceParentIds[0];

        on FindManagedObjectResponse(reqId=fmo1.reqId) as resp1
        and not FindManagedObjectResponseAck((reqId=fmo1.reqId) {
            ManagedObject mo1 := resp1.managedObject;
            log "Parent name is : " + mo1.name at INFO;
        }
    }
}
2 Likes

Thank you! The child device name works too.
I have another question now that I was actually able to see how it works, is it normal that to retrieve the exact name of the machine the query takes from 30 sec to a minute?
How I am doing it is like this:

// Searching for the machine name that is used for representing the object in user interfaces.
				FindManagedObject request := new FindManagedObject;
				request.reqId := measurement.source.toInteger();
				monitor.subscribe(FindManagedObjectResponse.SUBSCRIBE_CHANNEL);
				on all FindManagedObjectResponse(reqId=measurement.source.toInteger()) as response
				and not FindManagedObjectResponseAck(reqId=measurement.source.toInteger()) 
				{
					if (response.reqId = measurement.source.toInteger()) {
						//log "Received ManagedObject " + response.toString() at INFO;
						if (response.managedObject.id = measurement.source) {
							TriggerEmailAlarmMessage(measurement.source, response.managedObject.name,INDEX_ERROR_FOUND);
						}
					}
				}
				on FindManagedObjectResponseAck(reqId=measurement.source.toInteger()) 
				as requestCompleted
				{
					// Request is completed and we can unsubscribe from this channel
					monitor.unsubscribe(FindManagedObjectResponse.SUBSCRIBE_CHANNEL);
				}
				send request to FindManagedObject.SEND_CHANNEL;
  1. Please don’t try to convert the source to integer. The source id’s aren’t guaranteed to be integer and they should be treated as strings. Please use other utilities to generate an unique reqId, example: request.reqId := com.apama.cumulocity.Util.generateReqId();
  2. Please populate the ‘deviceId’ field of the request to retrieve the device directly. example: fmo.deviceId := measurement.source; . This will ensure that only the corresponding device is retrieved. The current query you are performing is attempting to retrieve all managed objects present on the platform and that’s why the request is taking a lot of time.
  3. If you are interested in just the corresponding device, you can just use a simplified listener like on FindManagedObjectResponse instead of on all FindManagedObjectResponse

Thank you so much, this fixed my issue!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.