Table of contents

The definition of a data source (device) in Signomix allows you to define code for the data processor. When new data is received from this source, the data processor runs the JavaScript interpreter and executes the code defined for this data source.

When creating code for the processor, the user can use the functions of the sgx library built into the data processor. Below is the documentation of this library.

verify(received, receivedStatus)

The verify function is used to verify the received data and update the status of the object.

Parameters

  • received (Array): An array of data objects for verification.
  • receivedStatus (String): The status of the received data.

Returns

  • void: The function does not return any value.

Example of use

var receivedData = [ { name: "temperature", value: 22.5, timestamp: 1628765432 }, { name: "humidity", value: 60, timestamp: 1628765432 } ]; var status = "ok"; sgx.verify(receivedData, status)

accept(name)

The accept function is used to accept data with the specified name and store it in the results. Its call may be necessary when the put function is used in the code.

See also: put

Parameters

  • name (String): The name of the data to accept.

Returns

  • void: The function does not return any value.

Example of use

sgx.accept("temperature")

addCommand(targetEUI, payload, overwrite)

The addCommand function is used to add a new command.

Parameters

  • targetEUI (String): The unique identifier of the target device.
  • payload (Object): The data (JavaScript object) to be sent as part of the command.
  • overwrite (Boolean): Flag indicating whether to invalidate previous (not yet transmitted) commands.

Returns

  • void: The function does not return any value.

Example of use

var targetEUI = "00124B0004F12345"; var payload = { command: "activate", parameters: { duration: 10 } }; var overwrite = true; sgx.addCommand(targetEUI, payload, overwrite)

addPlainCommand(targetEUI, payload, overwrite)

The addPlainCommand function is used to add a new command in plain text format.

Parameters

  • targetEUI (String): Unique identifier of the target device.
  • payload (String): The text to be sent as part of the command.
  • overwrite (Boolean): Flag indicating whether to invalidate previous (not yet transmitted) commands.

Returns

  • void: The function does not return any value.

Example of use

var targetEUI = "00124B0004F12345"; var payload = 'start' var overwrite = false; sgx.addPlainCommand(targetEUI, payload, overwrite)

addHexCommand(targetEUI, payload, overwrite)

The addHexCommand function is used to add a new command with payload in hexadecimal format.

Parameters

  • targetEUI (String): The unique identifier of the target device.
  • payload (String): Hexadecimal format data to be sent as part of the command.
  • overwrite (Boolean): Flag indicating whether to invalidate previous (not yet transmitted) commands.

Returns

  • void: The function does not return any value.

Example of use

var targetEUI = "00124B0004F12345"; var payload = "00FFAA01"; var overwrite = true; sgx.addHexCommand(targetEUI, payload, overwrite)

addNotification(newType, newMessage)

The addNotification function is used to add a new notification.

Parameters

  • newType (String): The type of the new notification. Accepted values: info,warning,alert.
  • newMessage (String): The content of the new notification.

Returns

  • void: The function does not return any value.

Example of use

sgx.addNotification("info", "Device activated successfully.")

addVirtualData(newEUI, newName, newValue)

The addVirtualData function is used to add new virtual data.

Parameters

  • newEUI (String): The unique identifier of the new device.
  • newName (String): The name of the new data.
  • newValue (Mixed): The value of the new data.

Returns

  • void: The function does not return any value.

Example of use

sgx.addVirtualData("00124B0004F67890", "virtualTemperature", 25)

getAverage(channelName, scope, newValue)

The getAverage function is used to get the average value for a given channel.

Parameters

  • channelName (String): The name of the channel.
  • scope (Number): The range of the value.
  • newValue (Number, optional): The new value to be included in the calculation.

Returns

  • Number: The average value for a given channel.

Example of use

var average = sgx.getAverage("temperature", 10); var newAverage = sgx.getAverage("temperature", 10, 23.0)

getMinimum(channelName, scope, newValue)

The getMinimum function is used to get the minimum value for a given channel.

Parameters

  • channelName (String): The name of the channel.
  • scope (Number): The range of the value.
  • newValue (Number, optional): The new value to be included in the calculation.

Returns

  • Number: The minimum value for a given channel.

Example of use

var minimum = sgx.getMinimum("temperature", 10); var newMinimum = sgx.getMinimum("temperature", 10, 18)

getMaximum(channelName, scope, newValue)

The getMaximum function is used to get the maximum value for a given channel.

Parameters

  • channelName (String): The name of the channel.
  • scope (Number): The range of the value.
  • newValue (Number, optional): The new value to be included in the calculation.

Returns

  • Number: The maximum value for a given channel.

Example of use

var maximum = sgx.getMaximum("temperature", 10); var newMaximum = sgx.getMaximum("temperature", 10, 27)

getSum(channelName, scope, newValue)

The getSum function is used to get the sum of values for a given channel.

Parameters

  • channelName (String): The name of the channel.
  • scope (Number): The range of values.
  • newValue (Number, optional): The new value to be included in the calculation.

Returns

  • Number: The sum of the values for a given channel.

Example of use

var sum = sgx.getSum("temperature", 10); var newSum = sgx.getSum("temperature", 10, 22)

getLastValue(channelName, skipNull)

The getLastValue function is used to get the last value for a channel.

Parameters

  • channelName (String): The name of the channel.
  • skipNull (Boolean): Skip null values. Optional parameter.

Returns

  • Mixed: The last value for the channel, or null if there is no data.

Example of use

var lastValue = sgx.getLastValue("temperature")

getLastData(channelName, skipNull)

The getLastData function is used to get the last data for a given channel.

Parameters

  • channelName (String): The name of the channel.
  • skipNull (Boolean): Skip null values. Optional parameter. If missing, skipNull==false.

Returns

  • Object: the last data for the given channel.

Example of use

var lastData = sgx.getLastData("temperature")

getModulo(value, divider)

The getModulo function is used to get the remainder from dividing the value by the divider.

Parameters

  • value (Number): The value to be divided.
  • divider (Number): The divider.

Returns

  • Number: The remainder of the divider.

Example of use

var modulo = sgx.getModulo(10, 3); // 1

getOutput()

The getOutput function is used to get the results of processing.

It returns

  • Mixed: the result of the processing.

Example of use

var output = sgx.getOutput()

getTimestamp(channelName)

The getTimestamp function is used to get the timestamp for a given channel.

Parameters

  • channelName (String): The name of the channel.

Returns

  • Number: The timestamp for the given channel.

Example of use

var timestamp = sgx.getTimestamp("temperature")

getTimestampUTC(y, m, d, h, min, s)

The getTimestampUTC function is used to get the UTC timestamp based on the given parameters.

Parameters

  • y (Number): Year.
  • m (Number): Month.
  • d (Number): Day.
  • h (Number): Hour.
  • min (Number): Minute.
  • s (Number): Second.

Returns

  • Number: UTC timestamp.

Example of use

var timestampUTC = sgx.getTimestampUTC(2024, 6, 5, 12, 0, 0)

getValue(channelName)

The getValue function is used to get the value for a given channel.

Parameters

  • channelName (String): The name of the channel.

Returns

  • Mixed: The value for the channel, or null if no data is available.

Example of use

var value = sgx.getValue("temperature")

getStringValue(channelName)

The getStringValue function is used to get the text value for a given channel.

Parameters

  • channelName (String): The name of the channel.

Returns

  • String: The text value for the given channel, or null if no data is available.

Example of use

var stringValue = sgx.getStringValue("temperature")

put(name, newValue, timestamp)

The put function is used to put new data.

Parameters

  • name (String): Name of the data.
  • newValue (Mixed): The new value of the data.
  • timestamp (Number, optional): The timestamp of the data.

Returns

  • void: The function does not return any value.

Example of use

sgx.put("temperature", 23.5); sgx.put("temperature", 23.5, 1628765432)

Notes

Using the put function disables the mechanism for automatically accepting and storing received data in the database. If the put function is used in the code of the data processor then in the database
only the data passed in the put and accept functions will be recorded.

Example of use

// Signomix received a request with data named `temperature` and `humidity`, but in the // data processor script we want to add a value for the data `pressure` sgx.put("pressure", 1000) // without the following lines, null values for `temperature` and `humidity` will be recorded in the database sgx.accept("temperature") sgx.accept("humidity")

See also accept

setState(newState)

The setState function is used to set the new state of the device.

Parameters

  • newState (String): The new state of the device.

Returns

  • void: The function does not return any value.

Example of use

sgx.setState("active")

setStatus(newStatus)

The setStatus function is used to set the new status of the device.

Parameters

  • newStatus (String): New device status.

Returns

  • void: The function does not return any value.

Example of use

sgx.setStatus("offline")

reverseHex(hexStr)

The reverseHex function is used to reverse the order of characters in a hexadecimal string.

Parameters

  • hexStr (String): Hexadecimal string.

Returns

  • String: The inverted hexadecimal string.

Example of use

var reversedHex = sgx.reverseHex("00FFAA01"); // "01AAFF00"

swap32(val)

The swap32 function is used to change the byte order of a 32-bit number.

Parameters

  • val (Number): A 32-bit number.

Returns

  • Number: A number with the byte order changed.

Example of use

var swapped = sgx.swap32(0x12345678); // 0x78563412

distance(latitude1, longitude1, latitude2, longitude2)

The distance function is used to calculate the distance between two geographic points.

Parameters

  • latitude1 (Number): Latitude of point 1.
  • longitude1 (Number): The longitude of point 1.
  • latitude2 (Number): Latitude of point 2.
  • longitude2 (Number): Longitude of point 2.

Returns

  • Number: The distance between two points in meters.

Example of use

// the distance between two points var dist = sgx.distance(52.2296756, 21.0122287, 41.8919300, 12.5113300); // the distance of a point from the uploaded location var dist = sgx.distance(2.2296756, 21.0122287, sgx.getValue("latitude"), sgx.getValue("longitude") )

homeDistance(latitude, longitude)

The homeDistance function is used to calculate the distance between a given geographic point
and the location point of the device stored in its configuration.

Parameters

  • latitude (Number): Latitude of the point.
  • longitude (Number): The longitude of the point.

Returns

  • Number: The distance between two points in meters.

Example of use

// distance of the specified point from the location specified in the device configuration var dist = sgx.homeDistance(41.8919300, 12.5113300); // distance of the uploaded location from the location specified in the device configuration var dist = sgx.homeDistance( sgx.getValue("latitude"), sgx.getValue("longitude") )
© 2023-2025 Grzegorz Skorupa