UTILS JavaScript API

Connector functions UTILS JS API guide

In this javascript code, there are helper operations available to help users who are building their own functions. We will explain them below.

JS UTILS API

These operations are grouped by their topic, at this time the available areas are:

  • AT commands
  • Endesa commands
  • ODM commands
  • Time commands

atcmd.toDBm(value)

Translates the response got by the ‘AT+CSQ’ command, which is the GSM signal strength and a numerical value, to its corresponding dBm value.

Kind: global function
Returns: The translation to dBm value

Param Type Description
value number The GSM signal strength.

endesa.torscp(value)

endesa.toDbmPlusQuality(value)

endesa.prepareMsisdn(msisdn)

If msisdn starts with “34”, then returns the value without “34”. Kind: global function
Returns: returns msisdn parameter without formatted

Param Type Description
msisdn string msisdn to be transformated

Example of use:

var newMsisdn = utils.endesa.prepareMsisdn("341234567890");
//newMsisdn will be: 1234567890

endesa.commandFrom(command)

Depending on the command value, specific translation will be returned. Kind: global function
Returns: returns msisdn parameter without formatted

Param Type Description
command string command to be translated

Example of use:

var newCommand = utils.endesa.commandFrom("9600;8E1");
//newCommand will be: ATS37=9S13=1\r\n

odm.addIdentificationHint(key, value, structured)

odm.sleep(time)

odm.encryptString(originalValue, datastreamConfiguration, organizationName)

Encrypt an original string with the configuration established by the datastream of the organization

Kind: global function
Returns: The originalValue encrypted

Param Type Description
originalValue string The value to encrypt.
datastreamConfiguration string The datastream of provision type, of the datamodel that define this value. This datastream has the configuration of encryption.
organizationName string The organization name to wich belongs to the datamodel.

odm.decryptString(encryptedValue, datastreamConfiguration, organizationName)

Decrypt an encrypted string with the configuration established by the datastream of the organization

Kind: global function
Returns: The encryptedValue decrypted

Param Type Description
encryptedValue string The encrypted value to decrypt.
datastreamConfiguration string The datastream of provision type, of the datamodel that define this value. This datastream has the configuration of encryption.
organizationName string The organization name to wich belongs to the datamodel.

odm.getAddressTypeFromAddress(address)

Calculates the address type from a given address

Kind: global function
Returns: The address type

Param Type Description
address string The address which the type will be calculated for.

odm.entitiesValue(entities, datastream, index) ⇒ *

Extract from the first entity of entities array specified datastream “value” field value.

Kind: global function
Returns: * - Specified datastream “value” field. It can be complex object. null if datastream does not exist.

Param Type Description
entities Array Array of objects with flattened entity.
datastream String Datastream name, for example: ‘provision.device.identifier’.
index number Array Index. If provided datastream is an array (i.e. comm module), element index must be specified.

odm.httpRequest(request, payload) ⇒ Object

Executes specified request with specified payload.

Kind: global function
Returns: Object - JSON with response. It will have two fields: ‘statusCode’ with http result code and ‘body’ with response body content.

Param Type Description
request Object Object with requests parameters: ‘method’, ‘uri’ and ‘headers’. - ‘method’: GET, POST, PUT, DELETE. - ‘uri’: request uri. - ‘headers’: json with http request headers.
payload * data to be sent. It can be null.

time.period.previousQuarter(referenceTimeMillis)

Calculates previous quarter from specified time in milliseconds.

Kind: global function
Returns: return an object with initial and final times of defined period

Param Type Description
referenceTimeMillis number reference time in milliseconds

Example of use:

var period = utils.date.period.previousQuarter(1698841200000);//2023-11-01 12:20:00

It will return:

{
    "initial": 1698840000000, //2023-11-01 12:00:00:000
    "final": 1698840899000, //2023-11-01 12:14:59:999
    "type": "previousQuarter" 
}

time.period.previousDay(referenceTimeMillis)

Calculates previous day from specified time in milliseconds.

Kind: global function
Returns: return an object with initial and final times of defined period

Param Type Description
referenceTimeMillis number reference time in milliseconds

Example of use:

var period = utils.date.period.previousDay(1698841200000);//2023-11-01 12:20:00

It will return:

{
    "initial": 1698840000000, //2023-10-31 00:00:00:000
    "final": 1698840899000, //2023-10-31 23:59:59:999
    "type": "previousDay" 
}

time.period.previousWeek(referenceTimeMillis)

Calculates previous week from specified time in milliseconds.

Kind: global function
Returns: return an object with initial and final times of defined period

Param Type Description
referenceTimeMillis number reference time in milliseconds

Example of use:

var period = utils.date.period.previousWeek(1698841200000);//2023-11-01 12:20:00 (Wednesday)

It will return:

{
    "initial": 1698840000000, //2023-10-23 00:00:00:000 (Monday)
    "final": 1698840899000, //2023-10-29 23:59:59:999 (Sunday)
    "type": "previousWeek" 
}

time.period.previousMonth(referenceTimeMillis)

Calculates previous month from specified time in milliseconds.

Kind: global function
Returns: return an object with initial and final times of defined period

Param Type Description
referenceTimeMillis number reference time in milliseconds

Example of use:

var period = utils.date.period.previousMonth(1698841200000);//2023-11-01 12:20:00

It will return:

{
    "initial": 1698840000000, //2023-10-01 00:00:00:000
    "final": 1698840899000, //2023-10-31 23:59:59:999
    "type": "previousMonth" 
}

time.period.customPeriodUtc(initialTimeStr, finalTimeStr)

Calculates specified period in utc times in milliseconds.

Kind: global function
Returns: return an object with initial and final times of defined period

Param Type Description
referenceTimeMillis number reference time in milliseconds

Example of use:

var period = utils.date.period.customPeriodUtc("2011-11-01T14:20:00.000+0100","2011-11-01T14:25:00.000+0100");

It will return:

{
    "initial": 1698844800000, //2011-11-01T13:20:00.000
    "final": 1698845100000, //2011-11-01T13:25:00.000
    "type": "custom" 
}

time.period.lastMinutes(minutes, referenceTimeMillis)

Calculates a period of defined minutes until reference time. If referenceTimeMillis is not defined, current time will be used as reference

Kind: global function
Returns: return an object with initial and final times of defined period

Param Type Description
minutes number number of minutes of period
referenceTimeMillis number reference time in milliseconds

Example of use:

var period = utils.date.period.lastMinutes(15, 1698841200000);//2023-11-01 12:20:00

It will return:

{
    "initial": 1698840000000, //2023-11-01 12:05:00:000
    "final": 1698841200000, //2023-11-01 12:20:00:000
    "type": "lastMinutes" 
}

time.period.lastHours(hours, referenceTimeMillis)

Calculates a period of defined hours until reference time. If referenceTimeMillis is not defined, current time will be used as reference

Kind: global function
Returns: return an object with initial and final times of defined period

Param Type Description
hours number number of hours of period
referenceTimeMillis number reference time in milliseconds

Example of use:

var period = utils.date.period.lastHours(24, 1698841200000);//2023-11-01 12:20:00

It will return:

{
    "initial": 1698840000000, //2023-10-31 12:20:00:000
    "final": 1698841200000, //2023-11-01 12:20:00:000
    "type": "lastHours" 
}

time.period.lastDays(days, referenceTimeMillis)

Calculates a period of defined days until reference time. If referenceTimeMillis is not defined, current time will be used as reference

Kind: global function
Returns: return an object with initial and final times of defined period

Param Type Description
days number number of hours of period
referenceTimeMillis number reference time in milliseconds

Example of use:

var period = utils.date.period.lastDays(7, 1698841200000);//2023-11-01 12:20:00

It will return:

{
    "initial": 1698840000000, //2023-10-25 12:20:00:000
    "final": 1698841200000, //2023-11-01 12:20:00:000
    "type": "lastDays" 
}