Need help in Realtime configuration for measurement API

Hi Saif,

you can also use the Realtime service from the @c8y/client package to subscribe for notifications on new measurements for a specific device. It’s the same principle as described in this thread.

For measurements a subscription could look like this:

private subscribeForMeasurements(
    deviceId: string,
    measurementFragment: string,
    measurementSeries: string
  ) {
    this.realtime.subscribe(`/measurements/${deviceId}`, measurementNotification => {
      const measurement: IMeasurement = measurementNotification.data.data;
      if (!measurement || !has(measurement, `${measurementFragment}.${measurementSeries}`)) {
        return;
      }

      const measurementValue: number = get(
        measurement,
        `${measurementFragment}.${measurementSeries}.value`
      );
    });
  }

The channel to subscribe to is called /measurements/. If you want to subscribe to a specific device, you need to provide the device id for the channel. To receive all measurements you can also the wildcard character *. For a device you will receive all measurements it sends. If you want to filter for a specific data point you need provide the fragment and series in the callback (see example above).

In your case, you would first load the historic measurements to draw the initial graph and then subscribe for real-time measurements to get also new measurements for your device.

Best regards
Christian