Where do I get the Fragment and Series names for methods relying on the Web SDK

I am following the Web Development Tutotrial and trying to create an application that extracts two custom types of data from Cumulocity.

More specifically, I am trying to get existing as well as new incoming measurements from the backend. To do so, I created an Angular service and injected it with the InventoryService and the MeasurementsService from the Web SDK.

However, I want to create a method that uses the following 2 custom classes I modelled using the SmartRestTemplate:

Mode Usage

…and Tube Set Type

While I am confident with how I modeled my method to retrieve all records from C8Y with the instance of my InventoryService, I am less clear on how to reproduce the following method using my own MeasurementsService.

This is the method from the tutorial that I am referring to:

private async loadLatestMeasurement(
    deviceId: string,
    measurementFragment: string,
    measurementSeries: string
  ) {
    const filter = {
      source: deviceId,
      dateFrom: '1970-01-01',
      dateTo: new Date().toISOString(),
      valueFragmentType: measurementFragment,
      valueFragmentSeries: measurementSeries,
      pageSize: 1,
      revert: true,
    };

    try {
      const response = await this.measurementService.list(filter);

      if (
        !response.data ||
        response.data.length != 1 ||
        !has(response.data[0], `${measurementFragment}.${measurementSeries}`)
      ) {
        return;
      }

      const temperatureValue: number = get(
        response.data[0],
        `${measurementFragment}.${measurementSeries}.value`
      );
      const temperatureUnit: string = get(
        response.data[0],
        `${measurementFragment}.${measurementSeries}.unit`
      );

      this.temperatureMeasurement$.next({ value: temperatureValue, unit: temperatureUnit });
    } catch (error) {
      console.error('Error occurred while loading the latest measurement: ', error);
    }
  }

I suppose my main question is where do I get correct fragment and series names from my own templates to use with my own version of the loadLatestMeasurement method?

Hi Lucas,

was this template already used and you have such measurements in your tenant?

In general, measurements are following a specific structure that foresees each measurement value to be embedded within a fragment and a series (often the fragment is being used for classification purposes and the series as measurement-name).
In this example "c8y_Steam is the fragment, “Temperature” the series and “c8y_TemperatureMeasurement” the type:

{
  "source": {
    "id": "251982"
  },
  "time": "2020-03-19T12:03:27.845Z",
  "type": "c8y_TemperatureMeasurement",
  "c8y_Steam": {
    "Temperature": {
      "unit": "C",
      "value": 100
    }
  }
}

You’ll need to have 1..n fragments with 1..n series per fragment in your measurement. Each series needs to contain exactly one value attribute. See measurement-design in this domain model article for more info.

If you have produced these measurements already:
Use this API Endpoint to query your devices measurements. GET /measurement/measurements?source={your device id} should reveal the structure how your measurements are stored - including the fragments/series names. You can import the openApi spec to any REST Client (e.g. Postman) to do these queries. From your screenshot I would expect fragmentName is “mode” and series “bariatric”.

Another REST Endpoint that might be of interest is this one to retrieve all supported measurement fragments and series of a Managed Object

Hi Korbinian,

The measurements and devices were both registered using an MQTT protocol to send data to Cumulocity. In terms of the SmartTemplate, those were registered later by someone else from my team.

Regardless, I am able to visualize the structures in my browser using the Dev Tools. Here’s a snapshot of one such structure:

Based on your reply, would tubeSet be the fragment, smokeEvacuationHighFlow be the series, and tubeSet be again the type?

Cheers,

Lucas L.

Yes, correct.

1 Like

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