This document is a continuation of the Basic and Advanced Starter user guides. It aims to provide users with additional understanding on how to build and design their own customized Internet of Things pipeline in Reekoh.
In the Basic and Advanced Starter, we showed users how the Thing-to-App flow works, where we transmit enriched and processed device data to an application. The App-to-Thing Starter, as the name suggests, will do the opposite. It will help users understand how to send messages or commands from an application to a configured device.
To demonstrate how this works, we will use the following plugins: MQTT Gateway, Websocket Channel, and Command Relay.
Let's get started!
1. Register Device
Since this is an extension of the first two guides, the user can use the existing registered device (which is Device 1) for this procedure. But, we also need to add another device for sending commands to a device group, which we'll get into at the latter part of this guide.
To register a new device (let's name it Device 2), you may refer to the Basic Starter document.
After configuring your new device, you need to add a device group to allow you to send messages for the whole group of devices to perform. To do this, navigate to Device Groups on the navigation sidebar of the Device Management page, and then click New Device Group.
Key-in the name for your device group, and then click Create Device group. You should be able to see a message saying your device group has been added.
To add your device in a group, navigate to Devices on the navigation sidebar. For this example, select Device 1 from the list and then click Edit on the page that comes next.
Once you're directed to the Update Device page, select the device group you want to assign from the drop-down list. Click Update Device to keep the changes made.
You should be able to see a notification saying your device has been updated.
Do the same procedure for Device 2.
Once you're done configuring your devices, we can now proceed on pinning new plugins.
2. Pin Plugins
In this procedure, we'll pin the Websocket Channel plugin to be used later to demonstrate how to send real-time device data to an application, as well as allowing the application to send messages & commands to a device or group of devices.
Navigate to Marketplace on the mega menu, and then select the Channel tab. Hover over the Websocket plugin, and then click Pin on the pop-out window. You should be able to see a notification saying your plugin is pinned.
After you've pinned your plugin, we can now configure it to your Pipeline.
3. Build a Pipeline
For this demo, we will create a new pipeline to configure the plugins we'll be using.
To create a new pipeline, navigate to Pipeline Studio on the mega menu and then click Create a New Pipeline from the pop-out window.
In addition to the Websocket Channel plugin we've pinned, we will also be using the MQTT Gateway plugin. You may refer to the Basic Starter document to configure it in the App-to-Thing Pipeline. Once done, you may now proceed on configuring the Websocket plugin.
Locate the Channel category on the left pane, and then drag & drop the Websocket plugin to your work space.
To configure, double-click the plugin and then complete the wizard that comes next. Click Save.
Note: Port number for the Websocket Channel will be generated once your pipeline is deployed.
After you've configured the Websocket plugin, locate the Other category and then drag & drop the Command Relay plugin to your work space. This will broadcast the command to a specific device or group of devices. Double-click the plugin to configure, and then complete the wizard that comes next.
Once all plugins are configured, connect them by dragging the output terminal of one plugin to the input terminal of another. You may refer to the image below for sample. Select Save & Deploy from the drop-down menu.
Complete the wizard that comes next, and then click Save. You should be able to see a message saying your pipeline has been deployed.
4. Connect to the Websocket Channel
After you're done configuring the plugins in your pipeline, we can now proceed on connecting to the Websocket Channel using a tool such as Dark Websocket Terminal.
To do this, go to the Chrome Web Store and search for the Dark Websocket Terminalchrome application.
Open the app and then click Add to Chrome.
Click Add app on the pop-out window that comes next. Once installation is complete, you can now connect to the Websocket Channel.
Open the Dark Websocket Terminal chrome application.
Once you're in the application, type the command below in the command field. You may refer to the image below for sample.
/connect ws://<Generated Websocket Channel IP Address>:<Generated Websocket Channel Port>/
Note: To view the IP address and port number, go back to your pipeline and then double-click the Websocket plugin.
You should be able to see the "Connection Established" message on the terminal.
Keep this application open as we will use this to verify data coming from a device, as well as sending messages and commands to a device.
5. Connect and Send Data to the MQTT Gateway
After you've been connected to the Websocket Channel, you must now connect your device to the MQTT Gateway. For this example, we will use Device 1.
To add a new connection, open the MQTTLens chrome application and then click the Addicon.
Note: You can use any MQTT Client Simulator to connect to your gateway. Just locate and install them via Chrome Web Store.
Complete the following connection details:
- Connection name - Supply any name for your connection.
- Hostname - IP address generated upon deployment of your Reekoh pipeline.
- Port - Port number generated upon deployment of your Reekoh pipeline.
- Client ID - Device ID supplied or generated upon registration of your device.
Once all details have been completed, click Create Connection.
Since we'll be demonstrating later how to send messages or commands to a device group, you need to create a connection for Device 2. Simply follow the procedure above to do that.
After connection has been established for both devices, you need to subscribe the devices in order to view the messages coming from the Websocket Terminal. Let's start with Device 1.
Locate your connection for Device 1. On the Topic field, key-in your Device ID and then click Subscribe. You'll be able to see the incoming messages in the Subscriptions section.
Do the same procedure for Device 2.
After you've subscribed both devices, you need to send a JSON Data to the MQTT Gateway. Under the Publish section of your Device 1 connection, key-in or paste the JSON data on the Message field, and then supply a value for Topic. Click Publish to send data to the MQTT Gateway. You should be able to see the "Data Received" message along with the JSON data in the Subscription section.
Once JSON data is sent, we can now proceed on checking the device data going to the application, and commands / messages coming from the application to the device.
6. Verify Data
To check if the JSON data from the device has been received by the Dark Websocket Terminal, go back to the application. You should be able to see the "Received" message along with the JSON data sent.
Now, we'll check if Device 1 can receive a message from the Websocket Terminal. In the command bar of the application, key-in the command below.
{"type":"message","command":"UPDATE_DEVICE1","targetDevices":"<DeviceID>","targetDeviceGroups":""}
Note:
- type - Message Event you've specified upon configuration of your Websocket Channel plugin.
- command - Any message or command you want to send to the device.
- targetDevices - ID of your target device.
- targetDeviceGroups - Leave this field blank.
To check if the message was sent to the device, go back to MQTTLens and locate your connection for Device 1. You should be able to see the transmitted message under the Subscriptions section.
Lastly, we'll check if the device group can receive a message from the Websocket Terminal using the device group's ID. In the command bar of the application, key-in the command below.
{"type":"message","command":"UPDATE_DEVICEGROUP","targetDevices":"","targetDeviceGroups":"<GroupID>"}
Note:
- type - Message Event you've specified upon configuration of your Websocket Channel plugin.
- command - Any message or command you want to send to the device group.
- targetDevices - Leave this field blank.
- targetDeviceGroups - ID of your target device group. To obtain this, navigate to Device Groups on the Device Management page and then click your device group. Once you're directed to the page, copy the device group ID located at the address bar (see below image for reference).
You should be able to see the transmitted message under the Subscriptions section on both devices' connection.
Comments
0 comments
Please sign in to leave a comment.