Demonstration: Send Back Control Data to a Directly Connected Device

We demonstrate two-way communication with your IoT device using MQTT direct ingestion. Control attributes are used to send back control signals to the IoT device.

  1. Create the machine type with sensor and control attributes.


    Machine Type Editor with Sensor and Control Attributes

    We create a machine type, Motor_Type with one sensor attribute and one control attribute. The sensor attribute RPM measures the motor RPM. The control attribute Overheat is used to send the overheat signal from your IoT application.

  2. Create a machine for the machine type, and set the data source for the sensor and control attributes to Direct.


    Machine Editor

    We create a machine, Motor1 for the machine type, and set the Data Source value for the sensor attribute RPM and control attribute Overheat to Direct.

  3. Set the Direct Data Source Options for the machine from the Machine Editor menu.


    Menu: Data Source Options


    Sensor Data Source Options

    As this is a directly connected device, we choose Direct under Data Source. We specify an external ID, sensor. The External ID is used as the Client ID when the device sends RPM data to the IoT server. We set the authentication method to use Client ID/Secret and specify a secure secret password. As we do not need a custom schema, we leave the payload set to the default schema.

  4. Generate a sample schema for the machine from the Machine Inventory page.


    Machine Inventory Page: Generate Sample Schema


    Sample payload schema for sensor

    We choose a JSON schema and the MQTTS (PUB) protocol. We select the machine and choose to generate a sample payload for the sensor attribute. The entity ID (sensor) is included in the endpoint topic here, but you could also choose to include it as part of payload. We generate a sample schema for a single measurement.

    The payload contains a sample value for the sensor attribute. Note that the sensor attribute ID (4KGBM7VR2MA0) that appears in the payload can be traced to its respective sensor name (RPM) in the machine editor.

    Note:

    The sample schema includes sensor attributes, and not control attributes. While sensor attribute values are generated in the device and passed to your IoT application, control attribute values can be passed back from your digital twin to the actual device.

    When sending data, say using MQTT Explorer, copy the host, topic, and payload information from the Sample Schema dialog. Use the client ID as the user name and the secret, set earlier, to authenticate. Edit the payload, as required.

  5. Send data for the device using an MQTT client.

    1. Configure the MQTT connection information.


      MQTT Connection Information

      We use the host info that we copied from the sample schema dialog. Make sure that the encryption switch is ON, and use the secure port 8883. Use the external ID of the machine as the user name and the secret, set earlier, to authenticate.

    2. Add a topic to be able to pass control attributes back to the device.


      Topic for Control Attribute

      You can add the topic using one of the following formats:
      • direct/v1/schema/#
      • direct/v1/schema/entities/+/attributes/+
      • direct/v1/schema/entities/+/attributes/attributeID
      • direct/v1/schema/entities/externalID/attributes/attributeID
    3. Connect to the IoT server from the MQTT client, and publish device data to the server.


      Ingest data from the MQTT client

      We use the topic and payload information copied from the Sample Schema dialog. We edit the payload values as necessary, and publish.

  6. Verify that the published sensor data appears in Operations Center.


    Machine data in Operations Center

  7. Send control data using a rule, or by manually editing the control attribute in Operations Center.

    1. Use a rule to set the control attribute for a device.


      Rule to set control attribute value

      The preceding rule sets the Overheat control attribute to true if the RPM sensor value received from the IoT device is greater than 3000.

    2. Alternatively, manually edit the control attribute in Operations Center, and send the data to the device.


      Setting Control Attribute in Operations Center

    You can check the control data received in your MQTT client.


    Control Data Received in MQTT Client