If you do not want to manually send commands to devices, another option you can use to send commands to a device is via the Triggers plugin, which automates actions based on real-time incoming data from your connected devices.
Before you can use this option to send device commands, you must have the following:
- Registered devices
- Device group
- Device command
To send commands using Triggers plugin, perform the following steps:
- Navigate to Pipeline Studio from the navigation menu of your Platform Console then select the Create a new Pipeline option from the Create/Load Pipeline dialog that displays.
- From the Pipeline Studio page, select the Triggers plugin located under the Other category then drag and drop the plugin onto the design canvas.
- Double-click the plugin to configure it. The Configure Component dialog displays wherein you need to enter the name and select the command, devices, and device groups. Note: See Configuring Plugins in your Pipeline article for more information on how to configure plugins.
- Aside from the Triggers plugin, you also need to include a Gateway plugin and the Command Relays plugin into your pipeline as these plugins are needed to create a device connection to your gateway and broadcast the command to the target device.
- After you have configured all the plugins, connect them by dragging the output terminal of one plugin to the input terminal of another plugin.
- Click Save & Deploy then complete the pipeline information to deploy your pipeline. A confirmation message saying your pipeline has been created will be displayed.
After you have created your pipeline, create a connection for your devices using a client simulator in order to send device data to your plugins. For the purpose of this article, we will be using the MQTTBox client simulator and Device ABC and Device XYZ as examples with Device ABC being the target device for the command.
- Open the MQTTBox then click Create MQTT Client.
- Provide the following MQTT Client Settings:
- MQTT Client Name - Enter a name for the device connection.
- MQTT Client ID - Enter the device ID.
- Protocol - Select the protocol as mqtt/tcp.
- Host - Enter the IP address and port generated for the Gateway.
- Click Save to complete your connection. After connection have been established for both Device ABC and Device XYZ, you must also subscribe these devices in order to view the incoming messages.
- Open the connection for Device ABC then perform the following steps to subscribe your device:
- From the Topic to subscribe field, enter the device ID of your device.
- Click Subscribe.
Note: Do the same procedure to Device XYZ.
- After you have subscribed both of your devices, you can start sending device data by providing the following details:
- Topic to publish - Enter the Data Topic displayed from the MQTT Gateway plugin. Default value is reekoh/data.
- Payload Type - Ensure that Strings/JSON/XML/Characters option is selected.
- Payload - Enter the device data to be sent to the MQTT Gateway plugin. Note that the data must be in JSON format.
- Click Publish. A Data Received message will be displayed in the Subscription section.
- To verify if the command was received by the target device, go to Device ABC connection. The command should be displayed in the Subscription section.