Skip to main content
Version: 2.3.x

Using Direct Methods in ThingsPro Agent

ThingsPro Agent offers the following six direct methods that can we invoked when a device is online.

NoMethod NameDescription
1thingspro-api-v1Universal direct method that invokes all Restful APIs of ThingsPro Edge
2system-rebootRestarts a Moxa device
3thingspro-applications-controlControls run-time applications on the device
4thingspro-software-upgradePerforms over-the-air (OTA) software upgrades
5message-policy-getRetrieves the D2C message policy applied to your device
6message-policy-putUpdates the D2C message policy applied to your device

Invoking ThingsPro APIs Using the ThingsPro Agent Universal Method

The universal direct method thingspro-api-v1 can be used to invoke all Restful APIs on the ThingsPro Edge device. A complete list of the ThingsPro Edge Restful APIs is available here.

  • Method Name

    thingspro-api-v1
  • Request Payload: (Example to set SSH configuration)

    {
    "path":"/system/sshserver",
    "method":"PUT",
    "headers":[],
    "requestBody": {"enable": true, "port": 22}
    }
    NoNameDescription
    1pathThingsPro Edge Restful API endpoint
    2methodThe method associated with the API endpoint
    3headersRequired by the application/JSON payload
    4requestBodyUsed to post data required by the API endpoint
  • Response

    {
    "status":200,
    "payload":{"data":{"enable":true,"port":22}}
    }
  • Example

    Note: We recommend changing the following time-out parameters to prevent system exceptions.

    • Connection Timeout: Within 30 seconds
    • Method Timeout: Within 60 seconds.

Restarting a Device

The system-reboot method can be used to trigger a device to reboot immediately.

  • Method Name

    system-reboot
  • Request Payload

    {}
  • Response

    {
    "status": 200,
    "payload": {
    "data": "rebooting"
    }
    }

Controlling Runtime Applications

The thingspro-applications-control direct method offers you a quick way to start/stop/restart applications running on ThingsPro Edge.

  • Method Name

    thingspro-applications-control
  • Request Payload

    {
    "appName": "modbusmaster-tcp",
    "command": "stop"
    }
    NoNameDescription
    1appNameThe name of the applications running on and managed by ThingsPro Edge. You can get the complete application list using the ThingsPro Restful API for the same.
    2commandSupported commands:
    - start
    - stop
    - restart
  • Response

    {
    "status": 200,
    "payload": {
    "data": ""
    }
    }

Upgrading Software

The thingspro-software-upgrade direct method allows you to download software over the air and upgrade your device remotely.

  • Method Name

    thingspro-software-upgrade
  • Example: Triggering download and installation for an upgrade job

    • Request Payload

      {
      "downloadURL": "http://xxx/edge/87/doc_0.1.0-87_armhf.yaml",
      "runInstallation": true
      }
      NoNameDescription
      1downloadURLThe URL to download the software to
      2runInstallationtrue: The installation task will auto start after the download task is completed
    • Response

      {
      "status": 200,
      "payload": {
      "data": {
      "id": 1
      }
      }
      }
  • Example: Triggering a software download job

    • Request Payload

      {
      "downloadURL": "http://xxx/edge/87/doc_0.1.0-87_armhf.yaml",
      "runInstallation": false
      }
      NoNameDescription
      1downloadURLThe URL to download the software to
      2runInstallationfalse: The installation task doesn't start by default. You can invoke the next direct method to launch it.
    • Response

      {
      "status": 200,
      "payload": {
      "data": {
      "id": 2
      }
      }
      }
  • Example: Triggering an installation for an upgrade job ID

    • Request Payload

      {
      "id": 2,
      "runInstallation": true
      }
      NoNameDescription
      1runInstallationThe value shall always be true for this case.
      2idThe ID returned by the previous direct method.
    • Response

      {
      "status": 200,
      "payload": {
      "data": {
      "id": 3
      }
      }
      }

Note:

  1. ThingsPro agent will send back the upgrade progress and status via Reported Properties.

    • Report download progress

    • Download success

  2. ThingsPro Edge allows only one active software upgrade job at a time.

Retrieving the Telemetry Message Policy

The message-policy-get direct method retrieves the telemetry (D2C) message policy applied to a device.

  • Method Name

    message-policy-get
  • Request Payload

    {}
  • Response

    {
    "status": 200,
    "payload": {
    "data": {
    "groups": [
    {
    "id": 1,
    "enable": false,
    "format": "",
    "outputTopic": "sample",
    "pollingInterval": 2,
    "properties": [
    { "key": "messageType", "value": "deviceMonitor" }
    ],
    "sendOutThreshold": { "size": 4096, "time": 5 },
    "tags": {
    "system": { "status": ["cpuUsage", "memoryUsage"] }
    }
    }
    ]
    }
    }
    }
    NoNameDescription
    1groupsThe message group; you can define multiple messages by demand
    2idThe message ID
    3enableEnable or disable this message policy
    4formatA jq script to transform a default payload to a custom payload
    5outputTopicThe output topic required by Azure IoT Edge; helps manage the message route in Azure IoT Edge
    6pollingIntervalThe interval at which to poll tag data. For example,
    - value 10 : Every 10 second
    - value 0 : when the data is pushed into the tag (almost real time)
    7propertiesApplication properties of the message. This allows cloud applications to access certain messages without deserializing the JSON payload.
    8sendOutThresholdDefine conditions to send out messages to Azure Edge Hub based on:
    - message size
    - time (value 0 : almost real time)
    9tagsThe tag data to send in the message.
    You can retrieve all available tags defined by ThingsPro Edge RESTful API.

Updating the D2C Message Policy

This direct method message-policy-put allows you to apply a telemetry (D2C) message policy to a device.

  • Method Name

    message-policy-put
  • Request Payload

    {
    "groups": [
    {
    "enable": true,
    "outputTopic": "sample",
    "format": "",
    "properties": [
    { "key": "messageType", "value": "deviceMonitor" }
    ],
    "tags": {
    "system": { "status": ["cpuUsage", "memoryUsage"] }
    },
    "pollingInterval": 2,
    "sendOutThreshold": { "size": 4096, "time": 5 }
    }
    ]
    }

Transforming a Default Payload to a Custom Payload

The D2C message policy allows you to transform a default payload to your desired payload schema via a jq filter. For additional details, visit the jq website (https://stedolan.github.io/jq/manual/).

ThingsPro Edge Web GUI offers a easy way to apply the jq filter and test the transformed result as shown in the following examples.

  • Default D2C message schema

    Select the tags that you want using the tag-selector panel on the left. The default result for the selected tags will show in the right panel.

  • Custom payload after transforming the default payload

    Enable custom payload and and input the jq Filter to display the custom payload for your selection.

  • ThingsPro Agent offers the following variables to print information to your payload:

    NoVariableDescription
    1.srcNamePrints the source of the tag data
    2.tagNamePrints the tag name
    3.dataValuePrints the tag value
    4.tsPrints the timestamp of tag value be collected
    5.dataUnitPrints data unit of tag value (e.g.: %)
    6.dataTypePrints data type of tag value (e.g.: int64)

    NOTE: If you would like to include the above variables as the key of a JSON element, use parentheses as shown here.

    (.tagName): .dataValue
  • Custom payload: Example 1

    jq Filter:

    {device:(.srcName),timestamp:(now|todateiso8601),(.tagName):.dataValue}

  • Custom payload: Example 2

    jq Filter :

    {device:(.srcName),timestamp:(now|todateiso8601),tag: [{TagName:(.tagName), Value:.dataValue}]}

  • After confirmed the jq Filter, you can include the "format" element into the D2C message policy to enable a custom payload.

    {
    "groups": [
    {
    "enable": true,
    "outputTopic": "sample",
    "format": "",
    "properties": [
    { "key": "messageType", "value": "deviceMonitor" }
    ],
    "tags": {
    "system": {
    "status": ["cpuUsage", "memoryUsage"]
    }
    },
    "pollingInterval": 2,
    "sendOutThreshold": { "size": 4096, "time": 5 },
    "format": "{device:(.srcName),timestamp:(now|todateiso8601),TagName:(.tagName), Value:.dataValue}"
    }
    ]
    }

Last updated on 2022-07-22 by Cecilia Fernandes