Adding data from physical devices

Complete the steps to add devices to Platform Service. Use REST APIs to send events from these devices to Platform Service. Later, you create summary and device dashboards to monitor the device data.

About this task

In this tutorial, you are creating a robot device type and corresponding robot devices by using the Platform Service web user interface.

You do not need to connect physical devices to Platform Service. Instead, you can use the REST API to sends device events to Platform Service.

The following Messaging API endpoint is used to send device events:

POST /device/types/{typeId}/devices/{deviceId}/events/{eventName}

A third-party application, such as Postman, can be used to make the REST API calls. Postman is available to download here.

The device type that you create is available as a device type in Analytics Service. You define a KPI and use a built-in function to calculate the KPI.

Step 1: Add a robot device type

Before you can register and connect your devices to Platform Service, you must create a device type.

  1. From the Platform Service user interface, select: Device Types and then click Add Device Type.
  2. Assign a name to the device type and click Next.
  3. Click Finish.

Step 2: Add five robot devices

  1. Select Connect and then click Add a device.
  2. Find the robot device type.
  3. Assign a device ID to the device and click Next.
  4. Add dimensions to the device. For provider, assign either intech or martech. For color, assign either red or yellow. Enter:

    {
     "provider": "intech",
     "color": "red"
    }
    
  5. Assign an authentication token to the device. If you don't assign one, a token is autogenerated for you.
  6. Write down the unique device ID and token that you configure for the device. These parameters are used to reference your device.
  7. Click Save and finish.
  8. Repeat these steps for four more robot devices.

Step 3: Connect the devices

Connect the five devices to Platform Service. Send some events to see data flow into Platform Service.

Before you send data, go to the Recent events section of your device page to monitor recent events as they arrive.

  1. Open Postman.
  2. Click New > Request.
  3. Assign a name to the request.
  4. Select POST from the request drop-down.
  5. Enter the API endpoint URL.
    Example:
    https://{orgId}.messaging.internetofthings.ibmcloud.com/api/v0002/device/types/{typeId}/devices/{deviceId}/events/{eventName} Where:
    {orgId} Is the unique six-character organization ID that was generated when you registered the Platform Service.
  6. Select the Authorization tab.
    1. Set the type to Basic Auth.
    2. Set Username to use-token-auth.
    3. Use the token that you created when you registered the device as the password.
  7. Select the Headers tab and set Content-Type to application/json.
  8. Select the Body tab and add the following JSON payload:
{
    "load": 355,
    "torque": 8.5,
    "speed": 6.7,
    "acc": 5,
    "travel_time": 4.6
}
  1. Repeat the POST request for the four other devices. Vary the metric values slightly each time.

Keep your Postman session open. You will send some more events later after you create some sample dashboards.

Step 4: Add the event type to the physical intrface

  1. From the side menu, select Connect.
  2. Select Device Types.
  3. Find the robot device type.
  4. Click Edit.
  5. Add a new event type from received events. Find the event.
  6. Click Create.
  7. Click Save and finish.

Step 5: Create the logical interface

  1. From the side menu, select Connect and click Interfaces.
  2. Click Add new interface.
  3. Assign a name to the logical interface.
  4. Add the properties load, torque, speed, acc, and travel_time as numbers.
  5. Click Create interface.

Step 6: Add the logical interface to your device type

  1. From the side menu, select Connect and click Device type.
  2. Find your device type and open it.
  3. Click Edit.
  4. Add the logical interface you created to the robot device type.
  5. Map each property of the logical interface to a field on the physical interface. For example, for load, use $event.load in the mapping field.
  6. Click Close.
  7. Click Save and finish.
  8. Click View and activate interfaces.
  9. Click Activate all.

Step 5: Explore device metrics for your robots

Verify that a corresponding device type and entities are created in Analytics Service.

  1. On the side navigation, click Monitor.
  2. On the Device types tab, find your device type. The device type name is the same as the device type name that you configured in Platform Service.
  3. Select the Data tab and verify that you can see data for the entities. The data lake contains historical data and is populated as your devices contribute data. A time lag occurs between when you connect a device for the first time and when the data starts appearing.

Step 6: Create device type KPIs

  1. On the side menu, click Monitor.
  2. On the Device types tab, click your device type and then select the Data tab.
  3. Click Create new.
  4. Click Configure.
  5. Select the PythonExpression function.
  6. Enter the following Pandas expression:
    df["torque"]*df["load"]
  7. Click Next.
  8. Give the output metric the name: work_performed
  9. Click Create. Wait a couple of minutes for the scheduled calculations to run and then return to the Data tab and look at your new calculated metric.

Step 7: Add an alert

Add an alert to your device type.

  1. On the side menu, click Monitor.
  2. On the Device types tab, select your device type, and click View.
  3. On the Data tab, click Create new to open the catalog of functions.
  4. Select the AlertHighValue function.
  5. Select work_performed in the input_item drop-down list.
  6. In the upper_threshold field, enter 1000.
  7. Click Next.
  8. Assign the name work_performed_too_high to the alert.
  9. Click Create.
  10. Wait up to 5 minutes for the pipeline to generate data.

Next steps

You can now add dimensions for your device type.