Table of Contents

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

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

Variables:

Functions:

Variables of the sgx Library

When the data processor is initialized, variables of the sgx library are assigned values read from the incoming data. In the data processor script, you can read the values of these variables in the same way as for the eui variable below.

var eui = sgx.eui

eui

Identifier (EUI) of the data source

Usage Example

var eui = sgx.eui

dataTimestamp

Timestamp of data receipt in milliseconds (UTC).

applicationConfig

Application configuration object declared for the data source.

deviceConfig

Configuration object defined for the data source.

deviceGroups

Groups with which the data source is associated.

latitude

Latitude of the data source, specified in its definition (decimal format, as in Google Maps).

longitude

Longitude of the data source, specified in its definition (decimal format, as in Google Maps).

altitude

Altitude of the data source above sea level, specified in its definition.

tags

Map of tags added to the data source definition.

port

LoRaWAN port number assigned to the data transmission.

Functions of the sgx Object

verify(received, receivedStatus)

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

Parameters

  • received (Array): Array of data objects to verify.
  • receivedStatus (String): Status of the received data.

Returns

  • void: The function does not return any value.

Usage Example

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 save it in the results. Calling it may be necessary when using the put function in the code.

See also: put

Parameters

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

Returns

  • void: The function does not return any value.

Usage Example

sgx.accept("temperature");

addCommand(targetEUI, payload, overwrite)

The addCommand function is used to add a new command.

Parameters

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

Returns

  • void: The function does not return any value.

Usage Example

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): Text to be sent as part of the command.
  • overwrite (Boolean): Flag indicating whether to invalidate previous (not yet delivered) commands.

Returns

  • void: The function does not return any value.

Usage Example

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 a payload in hexadecimal format.

Parameters

  • targetEUI (String): Unique identifier of the target device.
  • payload (String): Data in hexadecimal format to be sent as part of the command.
  • overwrite (Boolean): Flag indicating whether to invalidate previous (not yet delivered) commands.

Returns

  • void: The function does not return any value.

Usage Example

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): Type of the new notification. Accepted values: info, warning, alert.
  • newMessage (String): Content of the new notification.

Returns

  • void: The function does not return any value.

Usage Example

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

addVirtualData(newEUI, newName, newValue)

The addVirtualData function is used to add new virtual data.

Parameters

  • newEUI (String): Unique identifier of the new device.
  • newName (String): Name of the new data.
  • newValue (Mixed): Value of the new data.

Returns

  • void: The function does not return any value.

Usage Example

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

clearData()

The clearData function removes all received values from the queue.

Parameters

None

Returns

  • void: The function does not return any value.

getAverage(channelName, scope, newValue)

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

Parameters

  • channelName (String): Channel name.
  • scope (Number): Value range.
  • newValue (Number, optional): New value to include in calculations.

Returns

  • Number: Average value for the given channel.

Usage Example

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): Channel name.
  • scope (Number): Value range.
  • newValue (Number, optional): New value to include in calculations.

Returns

  • Number: Minimum value for the given channel.

Usage Example

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): Channel name.
  • scope (Number): Value range.
  • newValue (Number, optional): New value to include in calculations.

Returns

  • Number: Maximum value for the given channel.

Usage Example

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): Channel name.
  • scope (Number): Value range.
  • newValue (Number, optional): New value to include in calculations.

Returns

  • Number: Sum of values for the given channel.

Usage Example

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 given channel.

Parameters

  • channelName (String): Channel name.
  • skipNull (Boolean): Skip null values. Optional parameter.

Returns

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

Usage Example

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): Channel name.
  • skipNull (Boolean): Skip null values. Optional parameter. Defaults to skipNull==false.

Returns

  • Object: The last data for the given channel.

Usage Example

var lastData = sgx.getLastData("temperature");

getModulo(value, divider)

The getModulo function is used to get the remainder of dividing the value by the divisor.

Parameters

  • value (Number): Value to divide.
  • divider (Number): Divisor.

Returns

  • Number: Remainder of the division.

Usage Example

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

getOutput()

The getOutput function is used to get processing results.

Returns

  • Mixed: Processing result.

Usage Example

var output = sgx.getOutput();

getTimestamp(channelName)

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

Parameters

  • channelName (String): Channel name.

Returns

  • Number: Timestamp for the given channel.

Usage Example

var timestamp = sgx.getTimestamp("temperature");

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

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

Parameters

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

Returns

  • Number: UTC timestamp.

Usage Example

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): Channel name.

Returns

  • Mixed: Value for the given channel, or null if there is no data.

Usage Example

var value = sgx.getValue("temperature");

getStringValue(channelName)

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

Parameters

  • channelName (String): Channel name.

Returns

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

Usage Example

var stringValue = sgx.getStringValue("temperature");

put(name, newValue, timestamp)

The put function is used to store new data.

Parameters

  • name (String): Data name.
  • newValue (Mixed): New data value.
  • timestamp (Number, optional): Timestamp of the data.

Returns

  • void: The function does not return any value.

Usage Example

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

Notes

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

Usage Example

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

See also: accept

setState(newState)

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

Parameters

  • newState (String): New device state.

Returns

  • void: The function does not return any value.

Usage Example

sgx.setState("active");

setStatus(newStatus)

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

Parameters

  • newStatus (String): New device status.

Returns

  • void: The function does not return any value.

Usage Example

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: Reversed hexadecimal string.

Usage Example

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

swap32(val)

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

Parameters

  • val (Number): 32-bit number.

Returns

  • Number: Number with swapped byte order.

Usage Example

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): Longitude of point 1.
  • latitude2 (Number): Latitude of point 2.
  • longitude2 (Number): Longitude of point 2.

Returns

  • Number: Distance between the two points in meters.

Usage Example

// distance between two points
var dist = sgx.distance(52.2296756, 21.0122287, 41.8919300, 12.5113300);

// distance of a point from the transmitted 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 device location point saved in its configuration.

Parameters

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

Returns

  • Number: Distance between the two points in meters.

Usage Example

// distance of the specified point from the location specified in the device configuration
var dist = sgx.homeDistance(41.8919300, 12.5113300);

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