Global variables

On top of all the parserUtils functions available in our (pre-)parsers, we have multiple global variables that can be accessed. These global variables can be recognized by the g_ prefix.


Return current device name

g_deviceName

This global variable will return the name of the device that the current payload belongs to.

Example usage in JavaScript

function parsePayload(payloadStr) {
  console.log(g_deviceName)
}

Example output

"ExampleDevice1"

Return device definition details

g_definition

This global variable will return a JSON object that represents the current device definition. That includes data point details, thresholds and more.

Example usage in JavaScript

function parsePayload(payloadStr) {
  console.log(g_definition)
}

Example output

{
    "definitionName": "gps_tracker_example",
    "displayName": "GPS Trackers",
    "deviceIcon": "fas fa-location",
    "version": "1",
    "manufacturer": "Example Inc.",
    "sensors": [{
        "name": "GPS",
        "thresholds": [{
                "name": "Entered Amsterdam",
                "type": "geofenceinside",
                "information": "Amsterdam"
            },
            {
                "name": "Entered Zwolle",
                "type": "geofenceinside",
                "information": "Zwolle"
            }
        ],
        "type": "gps",
        "displayName": "GPS"
    }],
    "supportsVirtualDevices": false
}

Return a list of current device data point values

g_sensors

This global variable will return an array of the device's current data point values. Each entry has a data point name, value, type and updatedUTC timestamp.

Example usage in JavaScript

function parsePayload(payloadStr) {
  console.log(g_sensors)
}

Example output

[
  {
    "name": "Temperature",
    "value": 23.3,
    "updatedUTC": 1656406710,
  },
  {
    "name": "Humidity",
    "value": 526,
    "updatedUTC": 1656406710,
  }
]

Return a list of current device tags

g_deviceTags

This global variable will return a comma seperated array of the device's current tags.

Example usage in JavaScript

function parsePayload(payloadStr) {
  console.log(g_deviceTags)
}

Example output

["deviceTag1", "deviceTag2"]