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

20. nqService

The nqService object is a built-in object that provides various functions dedicated to NEQTO.

Functional overview:

  • Provides the function to notify events to NEQTO Console.
  • Provides a function to send measurement data or arbitrary data to NEQTO Console in batch.
  • Provides a function to acquire service specific information assigned to a NEQTO device.
  • Provides a function to set the behavior of Express Mode.
  • Provides a function to set the behavior of Safe Mode.

Limitations:

  • The number of session resources that can be used is 1.
  • The maximum data size that can be sent at once is up to 128KB.
    If the maximum data size is exceeded, communication will be forcibly disconnected.



nqService Global Object

Methods()/PropertiesSummaryVersionNote
nqService.eventNotify()Performs event notification.*
nqService.batteryNotify()Performs battery event notification.02.02.00+*
nqService.cancelNotify()Cancels event notification or battery event notification.
nqService.startPublish()Starts the communication for batch data transmission.*
nqService.writePublish()Writes the send data after nqService.startPublish().
nqService.endPublish()Ends the communication started by nqService.startPublish().
nqService.cancelPublish()Cancels the communication started by nqService.startPublish().
nqService.on()Registers an event handler.01.07.00+
nqService.getServiceId()Gets the service specific information assigned to the NEQTO device.02.00.00+
nqService.setExpressConf()Sets the operating parameters for Express Mode.02.00.00+
nqService.inhibitSafeMode()Inhibits Safe Mode.02.03.00+

* These methods cannot be used simultaneously.
  After executing one of the methods, wait for the communication to end before using the next method.



Details

nqService.eventNotify(eventType[,content][,callback][,timestamp])

Performs event notification.
Please check the notes regarding this method.

eventTypeSummaryVersionNote
'info','warn','error','fatal'Notifies the user event messages to the NEQTO Console.
'time'Gets the time information from NEQTO and corrects the device's internal clock.

eventType : 'info','warn','error','fatal'

Notifies the user event messages to the NEQTO Console.

NameTypeM/OSummary                            Note
eventTypestringmandatoryEvent Type
Specify the desired event message level.
'info','warn','error','fatal'
contentstringmandatorySpecify any message.There is no limit to the number of characters, but memory resources are finite. Resource error occurs when the limit is reached. As a guide, please use within the maximum of 256 characters.
callback
(statusCode)
functionoptionalExecutes callback processing at the end of communication.
statusCode : {number}
Status code of the HTTP response
201: Success
Other than: Failure
This callback process is executed, and after the callback process exits, this method can be executed again.
timestampnumberoptionalTimestamp
Specify unixtime [ms].
If not specified, it is the time when this method is called.
Version 02.01.00+
(In previous versions, it will be the time when this method is called)
returnundefined--When an error occurs, an exception is raised.

eventType : 'time'

Gets the time information from NEQTO and corrects the device's internal clock.

NameTypeM/OSummary                            Note
eventTypestringmandatoryEvent Type
'time'
callback
(statusCode)
functionoptionalExecutes callback processing at the end of communication.
statusCode : {number}
Status code of the HTTP response.
200: Success
Other than: Failure
returnundefined--When an error occurs, an exception is raised.

nqService.batteryNotify(eventType,status[,callback][,timestamp])

Performs battery event notification.
Notifies the specified battery status to the NEQTO Console.
Please check the notes regarding this method.

The battery status will return to the N/A state when the system transitions to behavior other than that of the operating script, such as "Script Reload" or "Firmware Update".

NameTypeM/OSummary                            Note
eventTypestringmandatoryEvent Type
Specify the desired event message level.
'info','warn','error','fatal'
statusstring, nullmandatoryBattery Status
Specify the battery state.
'charging': Now charging
'full': 100% or less
'half': 50% or less
'low': 25% or less
'empty': Under voltage
'malfunction': Fault detected
null: N/A
callback
(statusCode)
functionoptionalExecutes callback processing at the end of communication.
statusCode : {number}
Status code of the HTTP response
201: Success
Other than: Failure
This callback process is executed, and after the callback process exits, this method can be executed again.
timestampnumberoptionalTimestamp
Specify unixtime [ms].
If not specified, it is the time when this method is called.
returnundefined--When an error occurs, an exception is raised.

nqService.cancelNotify()

Cancels event notification or battery event notification.

NameTypeM/OSummaryNote
returnundefined--

nqService.startPublish(dataLen)

Starts the communication for batch data transmission.
Please check the notes regarding this method.

Note that the batch data needs to be formatted using the nqMqtt.get method.
In addition, the formatted data can be further combined using ','. (See sample code)

NameTypeM/OSummaryNote
dataLennumbermandatorySpecify the total transmission data length [byte].
returnundefined--When an error occurs, an exception is raised.

nqService.writePublish(data[,callback])

Writes the send data after nqService.startPublish().
When performing divided transmission, use the callback process and execute multiple times. (See sample code)

NameTypeM/OSummary                                       Note
datastring, ArrayBuffermandatoryTransmission dataThe data size to be written at once should be 4KB or less. If an error occurs, reduce the data size to be written at one time.
If the length of the transmission data is 0, no transmission process will be performed and the callback will not be raised.
(ArrayBuffer supported: Version 02.01.00+)
callback
(len)
functionoptionalExecutes callback processing when transmission is completed.
len : {number} (Version 01.06.02+)
Transmission data length [byte]
If a communication error occurs during transmission, the value will be 0.
If a communication error occurs, nqService.startPublish() can be executed again after this callback process is executed and the callback process exits.
returnundefined--When an error occurs, an exception is raised.

nqService.endPublish([data][,callback])

Ends the communication started by nqService.startPublish().
If transmission data is specified, it will end after transmission is complete.

NameTypeM/OSummary                            Note
datastring, ArrayBufferoptionalTransmission dataThe data size to be written should be 4KB or less. If an error occurs, reduce the data size to be written and execute divided writing using nqService.writePublish().
(ArrayBuffer supported: Version 02.01.00+)
callback
(statusCode)
functionoptionalExecutes callback processing when transmission is completed.
statusCode : {number}
Status code of the HTTP response.
200: Success
Other than: Failure
This callback process is executed, and after the callback process exits, nqService.startPublish() can be executed again.
returnundefined--When an error occurs, an exception is raised.

nqService.cancelPublish()

Cancels the communication started by nqService.startPublish().

NameTypeM/OSummaryNote
returnundefined--

nqService.on(event,callback)

Registers an event handler.

NameTypeM/OSummaryNote
eventstringmandatoryEvent name
Names that can be used are: reload
callback()functionmandatoryExecutes callback processing when an event occurs.
returnundefined--

event : ’reload’

Executes callback processing before the operation script's forced termination event occurs by a trigger command from the NEQTO Console, such as "Script Reload" or "Firmware Update".
It can be used to execute minimal post-processing.
Note that this callback does not occur when the script terminates spontaneously, such as when a throw statement is executed or when an exception occurs due to syntax error, etc.

If an infinite loop occurs in the callback processing, the trigger command control from the NEQTO Console may become unavailable. Please check the related notes here before implementing the callback process.

nqService.getServiceId()

Gets the service specific information assigned to the NEQTO device.

NameTypeM/OSummaryNote
return{ServiceID}-{ServiceID} : Service specific information

{ServiceID}

NameTypeSummaryNote
.regionstringRegionasia-pacific-1, north-america-1
.groupstringGroup ID
.nodestringNode sID

nqService.setExpressConf(timeout)

Sets the operating parameters for Express Mode.

This configuration is only applied when Express Mode is enabled, and the last value set is stored in nonvolatile memory. If Express Mode is disabled, it is ignored. When switching Express Mode to disabled, all parameters will return to default values.

NameTypeM/OSummaryNote
timeoutnumbermandatorySpecifies the network connection wait timeout value [s].
Range: -1, 0 - 3600
The default value is -1.
If -1 is specified, the system default value of 30 seconds is applied.
returnundefined--When an error occurs, an exception is raised.

nqService.inhibitSafeMode()

Inhibits Safe Mode.

If an exception occurs after 60 seconds have elapsed since the script was started, after the exception factor is notified by an event message, the script is automatically reloaded and restarted. However, if an exception occurs in less than 60 seconds, it will enter safe mode.

This function is disabled each time the script is started. To keep it enabled, always call this method at the top of the script code.

NameTypeM/OSummaryNote
returnundefined--
//==============================================================
// neqto.js application
// Sample Application
//==============================================================
log.setLevel(0,2); //-1:NONE 0:ERROR 1:WARNING 2:DEBUG 3:TRACE, 0:DISABLE 1:LOG 2:CONSOLE 3:BOTH
log.printLevel(2); //0:DISABLE 1:LOG 2:CONSOLE 3:BOTH

nqService.inhibitSafeMode();



Object Usage Examples

Sample 1

This is a sample that notifies event messages at regular intervals.

var count = 0;
var notifying = 0;
var INTERVAL = 15000; //ms
var MAX_COUNT = 3;
var cb_done = function(statusCode) {
    count++;
    if(statusCode == 201) {
        print(Date() + ' Success! :' + statusCode);
    } else {
        print(Date() + ' Failure :' + statusCode);
    }
    notifying = 0;
};
var to = setInterval(function() {
    if(count >= MAX_COUNT) {
        clearInterval(to);
        print('try out');
    } else {
        if(notifying == 0) {
            notifying = 1;
            nqService.eventNotify('info', 'userlevel-Notify-' + count, cb_done);
            print('busy');
        }
    }
}, INTERVAL);

Sample 2

This is a sample that performs a time correction event at regular intervals.

var count = 0;
var correcting = 0;
var INTERVAL = 15000; //ms
var MAX_COUNT = 3;
var cb_done = function(statusCode) {
    count++;
    if(statusCode == 200) {
        print(Date() + ' Success! :' + statusCode);
    } else {
        print(Date() + ' Failure :' + statusCode);
    }
    correcting = 0;
};
var to = setInterval(function() {
    if(count >= MAX_COUNT) {
        clearInterval(to);
        print('try out');
    } else {
        if(correcting == 0) {
            correcting = 1;
            nqService.eventNotify('time', cb_done);
            print('busy');
        }
    }
}, INTERVAL);

Sample 3

This is a sample for batch transmission of sensor data stored in the storage.

var mb = storage.open(0);
mb.reset();
var FRAME_TYPE = 'nqSRV';
var w_len;
var allFrameSize;
var readIdx;
var nowUnix = (new Date()).getTime();
var lwM2MStr;
for(n=0; n<5; n++) {
    lwM2MStr = nqMqtt.get('LwM2MString', nowUnix + (n * 10000), 3313, 0, 5702, "Float", "1.0", 5703, "Float", "-1.0", 5704, "Float", "0.0", 5700, "Float", (1.0 + n*0.2).toFixed(1), "G");
    w_len = mb.writeFrame(FRAME_TYPE, (n > 0 ? ',' + lwM2MStr : lwM2MStr));
}
var getFrameData = function(init) {
    var tmpStr;
    var frame = '';
    if(init == 1) {
        readIdx = 0;
    }
    if(allFrameSize > 0) {
        tmpStr = mb.searchFrame(FRAME_TYPE, readIdx++);
        allFrameSize -= tmpStr.length;
        frame += tmpStr;
    }
    return frame;
}
var cb_done = function(statusCode) {
    if(statusCode == 200) {
        print(Date() + ' Success! :' + statusCode);
        mb.reset(); //Delete the data that could be sent
    } else {
        print(Date() + ' Failure :' + statusCode);
    }
};
var cb_w_done = function(len) {
    if(len === 0) {
        print(Date() + ' cb write failure!'); //disconnected
    } else {
        print(Date() + ' cb write success!');
        var frameData = getFrameData(0);
        if(allFrameSize <= 0) {
            nqService.endPublish(frameData, cb_done);
        } else {
            nqService.writePublish(frameData, cb_w_done);
        }
    }
};
allFrameSize = mb.searchAllFrame(FRAME_TYPE);
if(allFrameSize > 0) {
    print('allFrameSize:' + allFrameSize);
    nqService.startPublish(allFrameSize);
    nqService.writePublish(getFrameData(1), cb_w_done);
}



Updated: 2025-01-23
← 19. nqBridge21. nqMqtt →
  • nqService Global Object
  • Details
    • nqService.eventNotify(eventType[,content][,callback][,timestamp])
    • eventType : 'info','warn','error','fatal'
    • eventType : 'time'
    • nqService.batteryNotify(eventType,status[,callback][,timestamp])
    • nqService.cancelNotify()
    • nqService.startPublish(dataLen)
    • nqService.writePublish(data[,callback])
    • nqService.endPublish([data][,callback])
    • nqService.cancelPublish()
    • nqService.on(event,callback)
    • event : ’reload’
    • nqService.getServiceId()
    • {ServiceID}
    • nqService.setExpressConf(timeout)
    • nqService.inhibitSafeMode()
  • 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.