Phi function reference

Other IoT functions: for debugging, triggering alarms, setting data, getting reliability info

The following functions from PHP and Twig are available in Phi:

  • dump(array variablename)

    Returns null

    This function dumps the value of a variable given by variablename while doing a dry run of a Phi script.

    An alias of print(). When running outside of a dry run this function is ignored.

  • fireTrigger(string triggerCodeName, string explanation)

    Returns null

    Causes a trigger of an alarm to fire.

    If you create a trigger, and choose the ”Triggered from the Phi code“ option, then the trigger will not be set until you call the fireTrigger() function in your Phi code for the asset or data pool.

    Note that if the trigger was set the last time the Phi code was run, and you call the fireTrigger() function again, then there will be no further effect. However if the trigger was set the last time the Phi code was run, and you don't call the fireTrigger() function again, then the trigger will turn off.

  • getAssetReliability(datetime fromTimestamp, datetime toTimestamp[, integer assetId])

    Returns float

    Returns a number between 0 and 1 of how reliable an asset's connectivity was between the specified timestamps.

    When called from within a metric, the parameters fromTimestamp and toTimestamp can be written verbatim, as these are created by the execution of the script.

    This will only return a meaningful result if the normal communication interval has been defined on the schema of the related asset (e.g. "every 15 minutes"). Given a time range, the function adds up all of the for and asset communicated regularly in the given time range. If the asset communicated within the normal communication interval (plus the tolerance for late communication, if set), every time, this means the asset was reliable; whereas if communications arrived late, the amount lateness time is summed up and proportionally subtracted from 1, in proportion to the measured time period.

    In summary, a result of 0 means the asset failed to communicate at all in the time period, whereas 1 menas it always communicated on time (allowing for tolerance) or sooner.

  • setValue(string field, string value)

    Returns null

    Sets the value of a calculated field whose code name is given by field to the value value.