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.
-
Create the asset type with sensor and control attributes.
We create an asset type,
Env_Sensor
with one sensor attribute and one control attribute. The sensor attributeTemp
measures the temperature. The control attributeOverheat
is used to set the high temperature flag from your IoT application. -
Create an asset for the asset type, and set the data source for the sensor and control attributes to Direct.
We create an asset,
Env_Sensor1
for the asset type, and set the Data Source value for the sensor attributeTemp
and control attributeOverheat
to Direct. -
Set the Direct Data Source Options for the asset from the Asset Editor menu.
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. -
Generate a sample schema for the asset from the Asset Inventory page.
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.
-
Send data for the device using an MQTT client.
-
Configure the 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.
-
Add a topic to be able to pass control attributes back to the device.
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
-
Connect to the IoT server from the MQTT client, and publish device data to the server.
We use the topic and payload information copied from the Sample Schema dialog. We edit the payload values as necessary, and publish.
-
-
Verify that the published sensor data appears in Operations Center.
-
Send control data using a rule, or by manually editing the control attribute in Operations Center.
-
Use a rule to set the control attribute for a device.
The preceding rule sets the
Overheat
control attribute totrue
if the temperature sensor value received from the IoT device is greater than 25. -
Alternatively, manually edit the control attribute in Operations Center, and send the data to the device.
You can check the control data received in your MQTT client.
-