As reported in the documentation at the following link SmartREST 2.0 - Cumulocity IoT Guides I tried to subscribe to the devicecontrol/notifications topic (using Eclipse Path for java) but I always get an error. I can subscribe to other topics (example error) but not devicecontrol/notifications. I found on the forum that it is deprecated and that it should be replaced with /notification/operations but the result does not change, I get the same error.
What I would like to know is how to receive a message like the one below on the device, via MQTT, as reported in the documentation. Thank you very much
Please note that if you want to receive operations you need to make sure that the device you are subscribing to is flagged as agent. Also the owner of the device should match with the device user of you your client otherwise you have permissions problems.
Best way would be to create the device via the MQTT client and directly subscribing on the topics.
Do you have any reasons using JSON over MQTT instead of SmarREST 2.0 via MQTT?
Exception in thread “main” MqttException (128)
at org.eclipse.paho.client.mqttv3.MqttClient.subscribe(MqttClient.java:438)
at org.eclipse.paho.client.mqttv3.MqttClient.subscribe(MqttClient.java:469)
at org.eclipse.paho.client.mqttv3.MqttClient.subscribe(MqttClient.java:464)
at tests.AppPureMQTT.main(AppPureMQTT.java:73)
Yes my device is flagged as Agent. Using JSON over MQTT is a customer requirement.
I tried to create the MO via MQTT and immediately after subscribing to /notification/operations but the result does not change. Same error: MqttException (128)
The MQTT topic is devicecontrol/notifications not /devicecontrol/notifications…so that might be causing the main issue.
Check that the credentials you are using have access to the device. If you manually created the device managed object, then it might cause a problem if you are using device credentials from within the Java MQTT client.
Hi, I also tried /devicecontrol/notifications but the error is the same.
Yes, the credentials are the same. I can subscribe to the error topic without errors.
Just checking, you are using the MQTT topic devicecontrol/notifications correct? (Your response was a bit ambiguous) .
Being able to subscribe to the error topic (s/e) does not prove that your user has permissions to the device managed object. Typically if you are using device credentials, then the device managed object will have a owner property which will be of the format device_<userid>.
Though posting your Java code would be helpful for other Java people to review it (I’m not a Java person, so I won’t be able to help here).
You are using the incorrect devicecontrol topic. It should be devicecontrol/notifications
Device’s should be registered first using the SmartREST 2.0 template - 100. This is important as it will create a device in Cumulocity and give it an External ID with the type c8y_Serial. This is critical for device communication.
You should be connecting the MQTT client using a client id which matches the External ID used in the previous step (see mqtt-clientid)
Though I just checked some docs, and I think this example will be closer to what you want, as the example includes the initial device registration using the SmartREST template 100 message, and then you will just have to change it to subscribe to JSON over MQTT operation topic, devicecontrol/notifications:
You might need use object parsing to create json objects
You can use a combination of SmartREST 2.0 and JSON (over REST or MQTT) like Reuben mentioned with the 100 static template. I would use SmartREST 2.0 wherever it is possible as it is much more efficient.
Hello,
I am now able to receive commands subscribing the topic “devicecontrol/notifications” . But I didn’t find how to change the command state using MQTT with JSON Payload? . Is there a way to do this?
Marco
I don’t know of a way using JSON via MQTT (see also the note here, it is more meant as an addition to Smart Rest and does not have the goal to fully replace it).
Thanks for the reply. Since the client also wants to use JSON via MQTT I was wondering if there is a way to change the state with a JSON message. I get a message like this:
No there is not a way to update the operation using JSON via MQTT.
I would really question the customer requirement here, as “using MQTT payloads” is not really a requirement it is more a solution to a requirement.
In the end the requirement is to update an operation using the API provided by the platform, and in this case it is SmartREST API. You can still use JSON via MQTT for other API calls (e.g. update managed object fragments, create alarms, create events etc.).