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
utils.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. |
Example of use:
utils.endesa.torscp(value)
| Param | Type | Description |
|---|---|---|
| value | string | value to be converted |
Example of use:
utils.endesa.toDbmPlusQuality(value)
| Param | Type | Description |
|---|---|---|
| value | string | value to be converted |
Example of use:
utils.endesa.prepareMsisdn(msisdn)
If msisdn starts with “34”, then returns the value without “34”.
Kind: global function
Returns: returns msisdn parameter without format
| Param | Type | Description |
|---|---|---|
| msisdn | string | msisdn to be converted |
Example of use:
utils.endesa.commandFrom(command)
Depending on the command value, specific translation will be returned.
Kind: global function
Returns: returns msisdn parameter without format
| Param | Type | Description |
|---|---|---|
| command | string | command to be translated |
Example of use:
utils.odm.addValueToContext(key,value)
Kind: global function
| Param | Type | Description |
|---|---|---|
| key | string | key to be added to context |
| value | string | value to be added to context |
Example of use:
utils.odm.sleep(time)
Sleeps for specified time
| Param | Type | Description |
|---|---|---|
| time | number | time to sleep in milliseconds |
Example of use:
utils.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 which the datamodel belongs. |
Example of use:
utils.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 which the datamodel belongs. |
Example of use:
utils.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. |
Example of use:
utils.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. |
Example of use:
utils.odm.httpRequest(request, payload)
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. |
Example of use:
utils.date.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:
It will return:
utils.date.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:
It will return:
utils.date.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:
It will return:
utils.date.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:
It will return:
utils.date.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:
It will return:
utils.date.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:
It will return:
utils.date.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:
It will return:
utils.date.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:
It will return:
utils.bytes.fromHexString(hexString)
Kind: global function
Returns: return an Uint8Array object equivalent to de hexadecimal String
| Param | Type | Description |
|---|---|---|
| hexString | string |
String in hexadecimal format |
Example of use:
It will return:
utils.bytes.toHexString(array)
Kind: global function
Returns: return the hexadecimal string representation.
| Param | Type | Description |
|---|---|---|
| array | Array of bytes |
hexadecimal string representation |
Example of use:
It will return:
utils.bytes.fromText(str)
Kind: global function
Returns: return the Uint8Array representation of the string with UTF encoding.
| Param | Type | Description |
|---|---|---|
| str | string |
any text |
Example of use:
It will return:
utils.bytes.toText(bytes)
Kind: global function
Returns: return the string representation of array of bytes in UTF.
| Param | Type | Description |
|---|---|---|
| bytes | Array of bytes |
bytes representing a text in UTF |
Example of use:
It will return: