Device: Connect Trigger Node

The Device: Connect Trigger fires a workflow whenever one or more devices connect to the Losant Platform, via the MQTT broker or whenever the connection status is changed to “connected” using the REST API.

Device Connect Trigger

Node Properties

The behavior of the Device: Connect Trigger varies depending on the type of workflow it is utilized in.

Application Workflows

The Device: Connect Trigger can be configured with one or more specific devices, or a selection of tags (or both). When a device that matches anything in the selection connects to Losant, the workflow will trigger. See the device query documentation for more info about how ID and tag matching works.

In the above example, the workflow will be triggered when any device that has a location tag connects to Losant.

Edge Workflows

For Edge Workflows, you cannot use device queries. Instead, it will trigger when the Edge Compute Device running the Edge Workflow connects to Losant.

Payload

The payloads associated with the Device: Connect Trigger depend on the type of workflow the trigger is used in.

Application Workflow Payload

The trigger’s initial payload includes information about the device that caused the workflow to fire. Additionally, it includes a data object with the following property:

  • address: The client IP address.
  • method: The method used to connect to Losant (either “mqtt” or “rest”).
  • secure: Indicates whether the connection is secure (true) or insecure (false).

In the general case, a Device: Connect workflow payload in an Application Workflow looks like the following:

{
  "applicationId": "555555555555eeeeeeeeeeee",
  "applicationName": "My Great Application",
  "data": {
    "address": "192.168.0.1",
    "method": "<mqtt|rest>",
    "secure": true
  },
  "device": {
    "_etag": "\"567-SY26IHrVRzUBMUwxnY59Fn6vOvo\"",
    "applicationId": "555555555555eeeeeeeeeeee",
    "attributes": {
      "exampleNumber": {
        "attributeTags": {
          "attrTagKey": "tagValue1"
        },
        "dataType": "number",
        "description": "",
        "name": "exampleNumber"
      },
      "exampleString": {
        "attributeTags": {
          "attrTagKey": "tagValue2"
        },
        "dataType": "string",
        "description": "",
        "name": "exampleString"
      }
    },
    "creationDate": "2018-03-16T18:19:03.376Z",
    "description": "",
    "deviceClass": "standalone",
    "deviceId": "222222222222bbbbbbbbbbbb",
    "id": "222222222222bbbbbbbbbbbb",
    "lastUpdated": "2020-08-26T13:09:11.814Z",
    "name": "My Great Device",
    "tags": {
      "aTagKey": [
        "exampleTagValue"
      ],
      "tagWithMultipleValues": [
        "tagValue",
        "anotherTagValue"
      ]
    }
  },
  "deviceName": "My Great Device",
  "deviceTags": {
    "aTagKey": [
      "exampleTagValue"
    ],
    "tagWithMultipleValues": [
      "tagValue",
      "anotherTagValue"
    ]
  },
  "flowId": "333333333333cccccccccccc",
  "flowName": "My Great Workflow",
  "flowVersion": "myFlowVersion",
  "globals": {
    "aJsonGlobal": {
      "key": "value"
    },
    "aNumberGlobal": 42,
    "aStringGlobal": "My value"
  },
  "relayId": "<ID of the resource that connected the device>",
  "relayType": "<apiToken|device|flow|user>",
  "time": Fri Feb 19 2016 17:26:00 GMT-0500 (EST),
  "triggerId": "<trigger key>",
  "triggerType": "deviceIdConnect"
}

Edge Workflow Payload

The payload’s data object contains a single property:

  • lastDisconnectTime: A Date object representing the last time the device disconnected from the MQTT broker. If this is the first time this device connected, or if the Gateway Edge Agent has been restarted, then this field will be null.

In the general case, a Device: Connect workflow payload in an Edge Workflow looks like the following:

{
  "agentEnvironment": {
    "EXAMPLE": "Environment Variable"
  },
  "agentVersion": "1.31.0",
  "applicationId": "555555555555eeeeeeeeeeee",
  "applicationName": "My Great Application",
  "data": {
    "lastDisconnectTime": null
  },
  "device": {
    "applicationId": "555555555555eeeeeeeeeeee",
    "attributes": {
      "exampleNumber": {
        "attributeTags": {
          "attrTagKey": "tagValue1"
        },
        "dataType": "number",
        "name": "exampleNumber"
      },
      "exampleString": {
        "attributeTags": {
          "attrTagKey": "tagValue2"
        },
        "dataType": "string",
        "name": "exampleString"
      }
    },
    "creationDate": "2018-03-16T18:19:03.376Z",
    "deviceClass": "edgeCompute",
    "deviceId": "222222222222bbbbbbbbbbbb",
    "id": "222222222222bbbbbbbbbbbb",
    "name": "My Great Device",
    "tags": {
      "aTagKey": [
        "exampleTagValue"
      ],
      "tagWithMultipleValues": [
        "tagValue",
        "anotherTagValue"
      ]
    }
  },
  "deviceId": "222222222222bbbbbbbbbbbb",
  "deviceName": "My Great Device",
  "deviceTags": {
    "aTagKey": [
      "exampleTagValue"
    ],
    "tagWithMultipleValues": [
      "tagValue",
      "anotherTagValue"
    ]
  },
  "flowId": "333333333333cccccccccccc",
  "flowName": "My Great Workflow",
  "flowVersion": "myFlowVersion",
  "globals": {
    "aJsonGlobal": {
      "key": "value"
    },
    "aNumberGlobal": 42,
    "aStringGlobal": "My value"
  },
  "isConnectedToLosant": true,
  "time": Fri Feb 19 2016 17:26:00 GMT-0500 (EST),
  "triggerId": "<trigger key>",
  "triggerType": "onConnect"
}

Was this page helpful?


Still looking for help? You can also search the Losant Forums or submit your question there.