Reputation: 69
I am a real newbie to Cumulocity and am currently on a trial version. I have been able to use the REST setup in Postman for creating devices, sending measurement, notification and alarms.
I have also tried the Hello MQTT example using MQTTBox.
What I however would like to do is to use Node-Red to send MQTT messages to a new or existing deviceId using the SmartRest API over MQTT.
I have tried our the "100,My first MQTT device,c8y_MQTTdevice", "200,myCustomTemperatureMeasurement,fahrenheit,75.2,F" and onward steps using MQTTBox and that seem to work just fine.
When I try to figure out a way to send measurement data from Node-Red I can´t seem to get my head around the Smart Rest thinking. I do not want to create a new device on connection every time but rather send messages to an existing deviceId.
From what I gather the client should somehow keep track itself, but wouldn´t that require me to automatically creating a new generated deviceId on every connection?
Simply, how do I send measurement data from Node-Red over MQTT repeatedly, entering the designated deviceId to be reached?
Upvotes: 1
Views: 429
Reputation: 2049
In MQTT with Cumulocity it is actually quite simple. The mapping of the MQTT connection to the device in Cumulocity is done via the MQTT ClientId and the c8y_Serial identity on Cumulocity side.
If a device object exists and you send the "create device" message via MQTT simply nothing will happen. So you can just send it everytime on start to ensure the device object is there.
So in the MQTT node in node-red make sure to set a fixed clientId and do not let it be generated. Otherwise you always end up with a new device.
Upvotes: 1