Notification v2 API

What product/components do you use and which version/fix level?

Cumulocity IoT Platform with version 10.13

Are you using a free trial or a product with a customer license?

Free trial

What are trying to achieve? Please describe in detail.

Using Notification V2 API to obtain the real-time data from the cloud

Do you get any error messages? Please provide a full error message screenshot and log file.

No


Hi all,

I tried this time on the eu.latest tenant and I do have got some response from the server side. But I still have one questions:

  1. I have first created a subscription named as testSubscription with filter type “c8y_Acceleration” and fragmentsToCopy is “AccelerationY”. I also created a token associated to this subscription whose subscriber is “testSubscriber”. Here is the response I got from serve:
{"self":"https://env779703.eu- latest.cumulocity.com/measurement/measurements/22850","time":"2022-07- 27T10:49:14.000+02:00","id":"22850","source":{"self":"https://env779703.eu latest.cumulocity.com/inventory/managedObjects/1825","id":"1825"},"type":"c8y_Acceleration"}
CNKyBBC7EyAAMAE=
/env779703/measurements/1825
CREATE

I didn’t get the desired fragment “AccelerationY” nor it’s value. Does it have something to do with the binary identifier “CNKyBBC7EyAAMAE=” used for acknowledgement? If I need to send the identifier back to the server, what is the HTTP header format that I should follow?

It would be quite appreciated if you can help me!

Hi Yingzhe,

OK, so we are making progress, you are at least getting something over the WS connection now!

I have a couple of follow-up questions:

  1. To keep things simple until we get it working, what happens if you don’t use the typeFilter or fragmentsToCopy on the subscription? You should receive all the notifications for whatever set of APIs you subscribe to - let’s see if that happens before trying to filter things.
  2. Are you sure you copied the right output there? I ask because the actual notification text should come after the 3 header lines (encoded ACK string, source description, action)

The encoded acknowledgement string (first header line) should be returned to the server as a text message over the WS connection exactly as it is - no headers required. The sample code in cumulocity-examples/hello-world-notification-microservice/src/main/java/c8y/example/notification/helloworld/websocket at develop · SoftwareAG/cumulocity-examples (github.com) shows how to do this for a couple of different Java-based WS libraries, the one you’re using might have a different API but the general approach should be the same.

Best regards,

Scott

Hi Scott,

I tries as you proposed and I got the following response:

{"self":"https://env779703.eu-latest.cumulocity.com/measurement/measurements/76607","time":"2022-07-28T13:19:24.000+02:00","id":"76607","source":{"self":"https://env779703.eu-latest.cumulocity.com/inventory/managedObjects/1825","id":"1825"},"type":"c8y_Acceleration"}
CLG0BBDSCCAAMAE=
/env779703/measurements/1825
CREATE

{"self":"https://env779703.eu-latest.cumulocity.com/measurement/measurements/75941","time":"2022-07-28T13:19:24.000+02:00","id":"75941","source":{"self":"https://env779703.eu-latest.cumulocity.com/inventory/managedObjects/1825","id":"1825"},"type":"c8y_SignalStrengthWifi"}
CLG0BBDTCCAAMAI=
/env779703/measurements/1825
CREATE

However, I used a script provided by my colleague and I got the response as following:

2022-07-28 13:25:23,655 - INFO - New message: CJi0BBC7ByAAMAE=
2022-07-28 13:25:23,655 - INFO - Channel: /env779703/measurements/1825
2022-07-28 13:25:23,655 - INFO - Action: CREATE
2022-07-28 13:25:23,655 - INFO - Body: {"self":"https://env779703.eu-latest.cumulocity.com/measurement/measurements/71197","time":"2022-07-28T10:34:32.500+02:00","id":"71197","source":{"self":"https://env779703.eu-latest.cumulocity.com/inventory/managedObjects/1825","id":"1825"},"type":"c8y_Acceleration","c8y_Acceleration":{"accelerationY":{"unit":"G","value":-0.017913087071136077},"accelerationX":{"unit":"G","value":-0.006463867280624413},"accelerationZ":{"unit":"G","value":0.9992235907268004}}}
2022-07-28 13:25:23,656 - INFO - New message: CJi0BBC8ByAAMAE=
2022-07-28 13:25:23,657 - INFO - Channel: /env779703/measurements/1825
2022-07-28 13:25:23,657 - INFO - Action: CREATE
2022-07-28 13:25:23,658 - INFO - Body: {"self":"https://env779703.eu-latest.cumulocity.com/measurement/measurements/72755","time":"2022-07-28T10:34:32.000+02:00","id":"72755","source":{"self":"https://env779703.eu-latest.cumulocity.com/inventory/managedObjects/1825","id":"1825"},"type":"c8y_SignalStrengthWifi","c8y_SignalStrengthWifi":{"rssi":{"unit":"dBm","value":-65.0}}}

This worked pretty well and I now think it is the library that I am currently using might have some problem.

Hi Yingzhe,

Yes, the second set of output there look more like what I would expect. I suspect you’re right that the issue is likely to be with the Websocket library. Honestly though I’m surprised it’s having any trouble - the protocol is deliberately very simple and you really should just be able to read text messages from the websocket and parse them line by line. At this point the product seems to be working correctly, so I can only suggest trying to add/enable some debugging in that library, or alternatively just use a different one.

Best regards,

Scott

1 Like