Example: Create Adapter for FILE Based Communication

This example helps you to create a gateway protocol of type file, which enables you to connect devices to this gateway through file. You start a gateway on the local file system, which hosts the local files to send data to sensors.

Prerequisites

You have created an adapter project as described in section Create the Adapter Project with the adapter type File.

Build the Target Folder

Procedure

  1. Right-click the adapter project.
  2. Choose Build Gateway Target Folder in the context menu.

    This action generates a folder target_test_runtime in the adapter project.

Run the Adapter Project

Procedure

  1. Navigate to the folder gateway-core-product located in the folder target_test_runtime of your adapter project.
  2. Open the file config/config_gateway_<protocol name>.xml and add the attribute gatewayAlternateId to the <cnf:gateway> tag.
  3. Remove the README.md file from the inputFiles folder.
  4. Launch the gateway.bat (Windows) or gateway.sh (macOS) in the console and not in Eclipse.
    1. Right-click the file gateway.bat.
    2. Select Show In.
    3. Choose System Explorer.
    4. A new window explorer opens, double-click the file gateway.bat.

    The new gateway has now been created and can be retrieved using one of the Gateway APIs. For details, see Access the APIs.

Test the Adapter Project

Prerequisites

Input files present as examples have some prerequisites:

Example 1

  1. A capability MyTemperature with the Alternate ID 1 and with a property temperature(float) exists.
  2. A capability MyPressure with the Alternate ID 2 and with two properties pressure(string) and unit of measure - p exists.
  3. A capability MyCommand with the Alternate ID 25 and with a property param(string) exists.
  4. A capability MyPosition with the Alternate ID 4 and with three properties, latitude(float), longitude(float), and quote(float) exists.
  5. A sensor type with Alternate ID 999 containing capabilities:
    • 1 (MyTemperature)

    • 2 (MyPressure)

    • 25 (MyCommand)

    • 4 (MyPosition)

    exists.

Example 2:

  1. A capability WindTurbineMainInfo with the Alternate ID 100 and with properties:
    1. rotation_speed (float) uom m/s
    2. wind_speed (float) uom knots
    3. operating_temperature (integer) uom C
    4. blade_angle (integer) uom rad
    5. critical_state (string)
    exists.
For more information, please refer to the tutorial Create a Device Model using API.

Send Data

Procedure

  1. Navigate to the folder gateway-<version> located in the folder target_test_runtime of your adapter project.
  2. Copy the file examples/example1.txt and paste it to inputFiles folder.

    The input file example1.txt will be processed and disappear from folder inputFiles. A backup file will available in the folder backup.

  3. Verify that all measurements present in the file examples/example1.txt are available for the device with the Alternate ID Example1, sensor with Sensortype 999 and capability 1 (MyTemperature).
  4. Verify that all measurement present in the file examples/example1.txt are available for the device with the Alternate ID Example1, sensor with Sensortype 999 and capability 2 (MyPressure).
  5. Copy the file examples/example2.txt and paste it to folder input.

    The input file example2.txt will be processed and disappear from folder input. A backup file will available in the folder backup.

  6. Verify that all the measurement present in the file examples/example2.txt are available for the device with the Alternate ID Example2, sensor with Sensortype 996 and capability 100 (WindTurbineMainInfo).

Delete a Device

Procedure

  1. Search and select the device you want to delete.
  2. In the header area of the device, choose (Delete device).
  3. Choose Confirm.

Delete an Adapter

Procedure

  1. Stop the local gateway by closing the console client.
  2. Search for and choose the gateway you want to delete.
  3. In the header area of the details page of the gateway, choose (Delete gateway).
  4. Choose Confirm.