0

Hello I am new to cumulocity and need help for the following scenarios

  1. I am trying to create a child device with following code:
public static void main(String[] args) {

        final MqttConnectOptions connOpts = new MqttConnectOptions();
        connOpts.setUserName(TENANT + "/" + USERNAME);
        connOpts.setPassword(PASSWORD.toCharArray());

        final MqttClient client;

        try {
            client = new MqttClient(SERVERURL, CLIENTID, null);
            client.connect(connOpts);

            client.publish("s/us", ("100," + DEVICE_NAME + ",c8y_MQTTDevice").getBytes(), 2, false);

            // set device's hardware information
            client.publish("s/us", "110,101010203,MQTT test model,Rev0.1".getBytes(), 2, false);
            //create Child device
            client.publish("s/us", ("101, 9999,ivelin13, c8y_MQTTChildDevice").getBytes(), 2, false);
} catch (
        MqttException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

The above code creates child device but i want to set it- hardware information. The template for that operation is

110,serialNumber,hardwareModel,revision

But i could not find how to set hardware information on the current child device. Maybe i have to select that child device- but i don't know how?

  1. Also i want to sent temperature measurement to the current child device. How do I select a child device?

Thanks in advance

Fortran
  • 593
  • 4
  • 14

1 Answers1

1

If you want to send a command to a child device, you can just add the child device's ID to the message's topic. In both example cases (setting hardware information and adding measurements), you have to publish your message to the topic s/us/9999.

[Edit] Example code:

string registerTopic = "s/us/" + parentId; }
await mqtt.PublishAsync(registerTopic, $"101,{childId},{deviceName},{deviceType}").ConfigureAwait(false);

string configTopic = "s/us/" + childId;
await mqtt.PublishAsync(configTopic, $"114,c8y_Command").ConfigureAwait(false);
await mqtt.PublishAsync(configTopic, $"117,11").ConfigureAwait(false);
stedaho
  • 218
  • 1
  • 3
  • 10