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 asset type with sensor and control attributes.


    Asset Type Editor with Sensor and Control Attributes

    We create an asset type, Env_Sensor with one sensor attribute and one control attribute. The sensor attribute Temp measures the temperature. The control attribute Overheat is used to set the high temperature flag from your IoT application.

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


    Asset Editor

    We create an asset, Env_Sensor1 for the asset type, and set the Data Source value for the sensor attribute Temp and control attribute Overheat to Direct.

  3. Set the Direct Data Source Options for the asset from the Asset Editor menu.


    Menu: Data Source Options


    Sensor1 Data Source Options

    As this is a directly connected device, we choose Direct under Data Source. We specify an external ID, sensor1. The External ID is used as the Client ID when the device sends temperature 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 asset from the Asset Inventory page.


    Asset Inventory Page: Generate Sample Schema


    Sample payload schema for sensor 1

    We choose a JSON schema and the MQTTS (PUB) protocol. We select the asset and choose to generate a sample payload for the sensor attribute. The entity ID 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 (4GXB88FM2MA0) that appears in the payload can be traced to its respective sensor name (Temp) in the asset 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 asset 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.


    Sample 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 temperature sensor value received from the IoT device is greater than 25.

    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