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)

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" 
}