NEQTO Docs
  • Languages iconEnglish
    • 日本語
  • Docs
  • API
  • FAQ

›neqto.js

Getting Started

  • NEQTO Hello World!
  • Tutorial Step 1. NEQTO Console Setting
  • Tutorial Step 2. Device Settings & Launching Service (NEQTO Bridge)
  • Tutorial Step 2. Device Settings & Launching Service (STM32 Discovery)
  • Tutorial Step 2. Device Settings & Launching Service (SPRESENSE)
  • Tutorial Step 3. Application development using scripts

NEQTO

  • NEQTO Account Registration
  • Sub-accounts
  • API Usage
  • NEQTO Engine Firmware List
  • Support Guidelines
  • For safe and secure use of the NEQTO products
  • Vulnerability Disclosure Policy

NEQTO Console

  • Introduction
  • Fundamentals
  • Administrative Actions
  • Device Management
  • Linux-based Device Management
  • Batch Registration
  • Scripts
  • Actions and Contacts
  • View Data from the Console
  • NEQTO Apps

    • About NEQTO Apps
    • NEQTO Infinitypool
    • NEQTO Insights
    • NEQTO Custodia
    • NEQTO Flow
  • Machine Driver
  • Recommended Browsers
  • Billing Information

SPRESENSE

    Hardware Specifications

    • 01. About Spresense

    Software Specifications

    • 01. Operational Flow
    • 02. Initial Installation
    • 03. Spresense Wi-Fi Initial Setup
    • 04. Spresense LTE-M Initial Setup
    • 05. Debug Log Acquisition
    • 06. System LED Indications
    • 07. Event Messages
    • 08. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. GPIO
    • 12. UART
    • 13. SPI
    • 14. I2C
    • 15. ADC
    • 16. GNSS
    • 17. Camera
    • 18. Utils
    • 19. nqSpresense
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi
    • 24. nqLte

STM32 Discovery

    Hardware Specifications

    • 01. About STM32 Discovery Kit (B-L4S5I-IOT01A)

    Software Specifications

    • 01. Operational Flow
    • 02. Initial Installation
    • 03. STM32 Discovery Wi-Fi Initial Setup
    • 04. Debug Log Acquisition
    • 05. System LED Indications
    • 06. Event Messages
    • 07. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. UserSW
    • 12. GPIO
    • 13. UART
    • 14. SPI
    • 15. I2C
    • 16. ADC
    • 18. Utils
    • 19. nqDiscovery
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi

NEQTO Bridge

    Hardware Specifications

    • 01. NEQTO Bridge Module
    • 02. NEQTO Bridge Wi-Fi Module
    • 03. NEQTO Bridge LTE-1 Module
    • 04. NEQTO Bridge LTE-M/NB Module
    • 05. NEQTO Bridge IO Board
    • 06. NEQTO Bridge Digital IO Board
    • 07. NEQTO Bridge Connector Board

    Software Specifications

    • 01. Operational Flow
    • 02. NEQTO Bridge Wi-Fi Module Initial Setup
    • 03. NEQTO Bridge LTE Module Initial Setup
    • 04. Debug Log Acquisition
    • 05. System LED Indications
    • 06. Event Messages
    • 07. Updating Firmware

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. Sleep
    • 10. RTC
    • 11. UserSW
    • 12. GPIO
    • 13. UART
    • 14. SPI
    • 15. I2C
    • 16. ADC
    • 17. BLE
    • 18. Utils
    • 19. nqBridge
    • 20. nqService
    • 21. nqMqtt
    • 22. nqFOTA
    • 23. nqWiFi
    • 24. nqLte
    • 25. nqLAN
    • 26. nqEx

Linux-based device

    Software Specifications

    • 01. System Requirements
    • 02. Installation
    • 03. Software Configurations
    • 04. Operational Flow
    • 05. Debug Log Acquisition
    • 06. Event Messages
    • 07. Updating Software

    neqto.js

    • 01. About neqto.js
    • 02. Log
    • 03. Timers
    • 04. HTTP
    • 05. HTTPS
    • 06. MQTT
    • 07. Secure
    • 08. Storage
    • 09. RTC
    • 10. UNIXSocket
    • 11. FileSystem
    • 12. SubProcess
    • 13. SubTask
    • 14. Queue
    • 15. Utils
    • 16. nqLinux
    • 17. nqService
    • 18. nqMqtt
    • 19. nqFOTA
    • 20. nqLAN

neqto.js Libraries

  • About neqto.js Libraries
  • UART

    • GM65 Barcode Reader
    • SRF Ultrasonic Range Finder - Serial Mode

    I2C

    • HTS221 v2 Temperature and Humidity Sensor
    • LIS2DW12 v2 Accelerometer
    • SRF Ultrasonic Range Finder - I2C Mode
    • [Archive] HTS221 Temperature and Humidity Sensor
    • [Archive] LIS2DW12 Accelerometer

    Utils

    • RTC Alarm Synchronized Scheduler

    Integration

    • AWS S3 v2
    • AWS IoT Core v2
    • Azure IoT v2
    • [Archive] GCP IoT Core
    • [Archive] AWS S3
    • [Archive] AWS IoT Core

neqto.js Snippets

  • About neqto.js Snippets
  • DataDog
  • Dropbox
  • Google Sheets
  • InfluxDB
  • Oracle Cloud Object Storage
  • Salesforce
  • Splunk
  • Niagara
  • [Archive] SAP Cloud Platform Internet of Things

Release Notes

  • NEQTO Console Updates
  • NEQTO Firmware (Bridge Wi-Fi/LTE Module) Releases
  • NEQTO Firmware (STM32 Discovery Wi-Fi) Releases
  • NEQTO Firmware (Spresense Wi-Fi/LTE-M) Releases
  • NEQTO Engine for Linux Releases
  • neqto.js Libraries Releases

18. Utils

The utils object is a built-in object that provides utility functions.

Functional overview:

  • Supports UTF-8 encoding/decoding.
  • Provides the ability to parse X.509 certificates.



utils Global Object

Methods()/PropertiesSummaryVersionNote
utils.stringToUtf8bin()Encodes string data in UTF-8.01.06.00+
utils.utf8binToString()Decodes binary data in UTF-8.01.06.00+
utils.getX509CertInfo()Gets the X.509 certificate information.02.02.00+



Details

utils.stringToUtf8bin(data)

Encodes string data in UTF-8.

NameTypeM/OSummaryNote
datastringmandatoryString data
returnArrayBuffer-Encoded binary dataWhen an error occurs, an exception is raised.

utils.utf8binToString(data[,offset[,length]])

Decodes binary data in UTF-8.

NameTypeM/OSummaryNote              
dataArrayBuffer,
Array[ArrayBuffer]
mandatoryBinary data
'ArrayBuffer' or Array of 'ArrayBuffer' can be specified.
If Array of 'ArrayBuffer' is specified, concatenates the binary data in the order of the array, then starts the decoding process.
offsetnumberoptionalOffset of decode processing start position
If array of 'ArrayBuffer' is specified for 'data', it will be an offset over all 'data' after the concatenation of the binary data.
The default value is 0.
If 'length' is used, it cannot be omitted.
lengthnumberoptionalDecode length [byte]
The default value is calculated by subtracting the decode start position offset from the total size of 'data'. A size less than or equal to the default value must be specified.
It can be omitted even if 'offset' is used.
return{DecodedData},
undefined
-{DecodedData} : Decoded data
If decoding fails, 'undefined' is returned.
When an error occurs, an exception is raised.

{DecodedData}

NameTypeSummaryNote
.strstringDecoded string data
.binArrayBufferWhen leftover data from 1 to 3 bytes exists at the end of the binary data to be decoded, the leftover data portion is output as binary data.
If leftover data does not exist, it will be 'undefined'.

utils.getX509CertInfo(cert)

Gets the X.509 certificate information.

NameTypeM/OSummaryNote
certstringmandatoryX.509 certificate
Specify a string in PEM format. Use \n for line feed code.
return{CertInfo}, null-{CertInfo} : X.509 certificate information
In case of a parsing error, 'null' is returned.

{CertInfo}

NameTypeSummaryNote
.certVersionnumberVersion number
.serialNumberstringSerial number
.issuerNamestringIssuer name
.subjectNamestringSubject name
.issuedOnnumberIssue date (unixtime[ms])
.expiresOnnumberExpiration date (unixtime[ms])
.signedUsingstringSignature algorithm
.keySizenumberPublic key size
.basicConstraintsstringBasic constraints
.subjectAltNamestringSubject alternative name
.certTypestringCertificate type
.keyUsagestringKey usage
.extKeyUsagestringExtended key usage
.certificatePoliciesstringCertificate policies



Object Usage Examples

Sample 1

This is a sample of split decoding using offset for data encoded in UTF-8.
This example utilizes the offset and length of .utf8binToString().
The possibility of splitting multi-byte characters without prior consideration of their cutoff points is shown.

var testStr_1 = 'Thank you Teşekkür ありがとう';
print(testStr_1);
var testEnc_1 = utils.stringToUtf8bin(testStr_1);
print(ab2Hex_00(testEnc_1));

var chunk = 7;
for(var n = 0; n < 20; n++) {
    var testDec_1 = utils.utf8binToString(testEnc_1, 0, chunk + n);
    print(('00' + n).substr(-2) + '_1:' + testDec_1['str']);
    //if(testDec_1['bin']) print(ab2Hex_00(testDec_1['bin']));

    var rest = testDec_1['bin'];
    var len = 0;
    if(rest) len = rest.byteLength;
    var testDec_2 = utils.utf8binToString(testEnc_1, chunk + n - len);
    print(('00' + n).substr(-2) + '_2:' + testDec_2['str']);
    //if(testDec_2['bin']) print(ab2Hex_00(testDec_2['bin']));
}

function ab2Hex_00(ab) {
    ret_str = '';
    var a = new Uint8Array(ab);
    for(var i = 0; i < a.length; i++) {
        ret_str += ('00' + a[i].toString(16).toUpperCase()).substr(-2);
    }
    return ret_str;
}

Sample 2

This is a sample that splits the UTF-8 encoded data into two parts and decodes them individually.
This example can be utilized when the decoding target is stream data.
The possibility of splitting multi-byte characters without prior consideration of their cutoff points is shown.

var testStr_1 = 'Thank you Teşekkür ありがとう';
print(testStr_1);
var testEnc_1 = utils.stringToUtf8bin(testStr_1);
print(ab2Hex_00(testEnc_1));

var chunk = 7;
for(var n = 0; n < 20; n++) {
    var chunk_1 = testEnc_1.slice(0, chunk + n);
    var chunk_2 = testEnc_1.slice(chunk + n);

    var testDec_1 = utils.utf8binToString(chunk_1);
    print(('00' + n).substr(-2) + '_1:' + testDec_1['str']);
    //if(testDec_1['bin']) print(ab2Hex_00(testDec_1['bin']));

    var rest = testDec_1['bin'];
    var testDec_2 = utils.utf8binToString([rest, chunk_2]);
    print(('00' + n).substr(-2) + '_2:' + testDec_2['str']);
    //if(testDec_2['bin']) print(ab2Hex_00(testDec_2['bin']));
}

function ab2Hex_00(ab) {
    ret_str = '';
    var a = new Uint8Array(ab);
    for(var i = 0; i < a.length; i++) {
    ret_str += ('00' + a[i].toString(16).toUpperCase()).substr(-2);
    }
    return ret_str;
}

Sample 3

This is a sample to get X.509 certificate information.

var ca = '-----BEGIN CERTIFICATE-----\n' +
'SIGD0jCCArqgAwIBAgIBATANBgkqhkiG9w0BAQUFADB6MQswCQYDVQQGEwJKUDEO\n' +
'MAwGA1UECAwFSXdhdGUxFTATBgNVBAoMDE1vYmljb21tIEx0ZDEcMBoGA1UEAwwT\n' +
//........
'HvMvDtFO71gaEtIkpejHGLgGhQK1dQ==\n' +
'-----END CERTIFICATE-----\n';

var info = utils.getX509CertInfo(ca);

if(info) {
    for(var key in info) {
        if(key == 'issuedOn' || key == 'expiresOn') {
            var date = new Date(info[key]);
            print(key + ':', date.toString());
        } else {
            print(key + ':', info[key]);
        }
    }
} else print("Cert parse error");



Updated: 2024-01-17
← 17. BLE19. nqBridge →
  • utils Global Object
  • Details
    • utils.stringToUtf8bin(data)
    • utils.utf8binToString(data[,offset[,length]])
    • {DecodedData}
    • utils.getX509CertInfo(cert)
    • {CertInfo}
  • Object Usage Examples
    • Sample 1
    • Sample 2
    • Sample 3
AboutNewsProductsFAQPrivacy PolicyVulnerability Disclosure Policy
NEQTO Console
IntroductionFundamentalsAdministrative ActionsDevice Management NEQTO Apps
NEQTO Bridge
NEQTO Bridge ModuleNEQTO Bridge Wi-Fi ModuleNEQTO Bridge LTE-1 ModuleError Logging Event Messages
API Documentation
API UsageGlobal APIRegional APIAPI Terms of Service
Jigsaw, Inc.
© 2025 JIG-SAW INC.