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

›neqto.js

Getting Started

  • NEQTO Hello World!
  • Step 1. Console Settings
  • Step 2. Device Setting & Start Service

    • When using NEQTO Bridge
    • When using Spresense
  • Step 3. Using Sensors

NEQTO

  • NEQTO Account Registration
  • API Usage
  • Batch Registration
  • Support Guidelines

NEQTO Console

  • Introduction
  • Fundamentals
  • Administrative Actions
  • Device Management
  • Scripts
  • Actions and Contacts
  • NEQTO Apps
  • 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
    • 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
    • 10. RTC
    • 12. GPIO
    • 13. UART
    • 15. I2C
    • 17. Camera
    • 18. nqSpresense
    • 19. nqService
    • 20. nqMqtt
    • 21. nqFOTA
    • 22. nqWiFi

NEQTO Bridge Series

    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

    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. nqBridge
    • 19. nqService
    • 20. nqMqtt
    • 21. nqFOTA
    • 22. nqWiFi
    • 23. nqLte
    • 24. nqLAN
    • 25. nqEx

neqto.js Libraries

    I2C

    • LIS2DW12 v2 Accelerometer
    • HTS221 v2 Temperature and Humidity Sensor
    • [Archive] LIS2DW12 Accelerometer
    • [Archive] HTS221 Temperature and Humidity Sensor

    Integration

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

neqto.js Snippets

  • DataDog Snippet
  • Dropbox Snippet
  • Google Sheets Snippet
  • InfluxDB Snippet
  • Oracle Cloud Object Storage Snippet
  • Salesforce Snippet
  • SAP Cloud Platform Internet of Things Snippet
  • Splunk Snippet
  • Niagara Snippet

Release Notes

  • NEQTO Console Updates
  • NEQTO Firmware (Bridge Wi-Fi/LTE Module) Releases
  • NEQTO Firmware (Spresense Wi-Fi) Releases

05. HTTPS

The https object is a built-in object that provides secure HTTP client functionality.

Functional overview:

  • Provides the HTTP client function.
  • Supports HTTP v1.1.
  • Supports TLS.
  • Supports server and client authentication.

Limitations:

  • The number of HTTP session resources that can be used simultaneously is 2.
    Note that both http and https objects share this resource.
  • Resource errors cause exceptions.



HTTPS Global Object

Methods()/PropertiesSummaryVersionNote
https.request()Starts HTTPS communication.00.00.15+{ClientRequest}, and {IncomingMessage} instances are generated.



Details

https.request(options[,callback][,sockTo])

Starts HTTPS communication.

NameTypeM/OSummaryNote
optionsObjectmandatoryProperties for setting communication parameters
host : {string}
Domain name or IP address of HTTPS server(*1)
The default value is '127.0.0.1'.
port : {number}
HTTPS Server Port Number
The default value is 443.
method : {string}
Method Name
Specify one of 'GET', 'POST', 'PUT', 'HEAD'.
The default value is 'GET'.
path : {string}
Request path
The default value is '/'.
headers : {Object}
Request header
Specify an object that contains any request header. This parameter is optional.
ca : {string}
CA SSL Certificate (*2)
cert : {string}
Client SSL Certificate (*3)
No default value.
key : {string}
Client private key (*3)
No default value.
Unset elements will be set with default values. (Related to the following *2,3)
However, this argument itself is required.

*1: An exception will be raised if the number of characters exceeds 127 bytes.
*2: This parameter is required.
*3: If not specified, client authentication is disabled.
callback(res)functionoptionalExecutes the callback process when the response header is received. The following arguments are attached.
res : {IncomingMessage}
An instance of {IncomingMessage}
Required when receiving data.
sockTonumberoptionalSession timeout value [ms]
(Up to 4,294,967,295 ms can be specified. Any value exceeding the maximum will be set to maximum.)
The default value is 90000.
If specified, the session will be destroyed on timeout and notified by the error event.
return{ClientRequest}-{ClientRequest} : Generated {ClientRequest}If resources are insufficient or parameters are abnormal, an exception occurs.



{ClientRequest}

This object is generated internally and returned by https.request().

Methods()/PropertiesSummaryVersionNote
.on()Registers an event handler.00.00.15+
.write()Sends data.00.00.15+
.end()Complete the HTTP-request.00.00.15+
.abort()HTTP-request transmission/HTTP-response reception is forcibly stopped.00.00.15+
.errCodeError code00.00.15+



Details

.on(event,callback)

Registers an event handler.

NameTypeM/OSummaryNote
eventstringmandatoryThe event name that can be used is error.
callback()functionmandatoryExecutes callback processing when an event occurs.
returnundefined--

event : ’error’

Executes callback when an error occurs during the HTTP-request.
The error can refer to the error code (.errCode) during or after callback execution.

.write(data[,callback])

Sends data.
Data is sent as Request-Body. Executes callback processing when transmission is completed.

NameTypeM/OSummaryNote
datastring, ArrayBuffermandatoryTransmission dataDivided writing is possible by cooperating with callback processing. The 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.
callback()functionoptionalExecutes callback processing when transmission of write data is completed.
returnundefined--

.end([data][,callback])

If data exists, it is sent at Request-Body and completes the HTTP-request.
Executes callback processing when transmission of request data is completed.
This method is required when completing an HTTP-request.

NameTypeM/OSummaryNote
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 .write().
callback()functionoptionalExecutes the callback process when the write data has been transmitted.
returnundefined--

Usually, it is used as follows.

request.write('Hello World');
request.end();

The following is a sample of divided writing.

var WRITE_CHUNK = 1024;
var getBodyStream = function(){
  var buff;
  //...
  //Prepare data up to WRITE_CHUNK.
  //If there is no more data, return null.
  //...
  return buff; //{string}/{arrayBuffer}/null
};
var writeBodyStream = function(){
    var buff = getBodyStream();
    if (buff != null){
      print('request stream write!!!');
      request.write(buff ,writeBodyStream);
    }else{
      request.end(function() {
        print('request stream end!!!');
      });
    }
}
writeBodyStream();

.abort()

HTTP-request transmission/HTTP-response reception is forcibly stopped.
This function triggers the call of the error event.

NameTypeM/OSummaryNote
returnundefined--

.errCode

Returns error code. This property has a value of type number.
The following is the meaning of each value. It can be referenced in the callback of the error or later.

Error codeSummary
0No error
1Aborted by calling .abort()
2Parameter error
3Resource error
4Callback processing error
5Socket Timeout
6Cancel due to sleep transition
103Request-Body shortage error
104Request-Body error
115Socket error



{IncomingMessage}

This object is generated internally by https.request() and returned as an argument of the callback process.
The received response header can be referenced when this object is returned.

Methods/PropertiesSummaryVersionNote
.on()Registers an event handler.00.00.15+
.read()Reads Response-Body.00.00.15+
.readBin()Reads Response-Body in binary format.00.00.15+
.statusCodeStatus code on the status line of the HTTP response frame00.00.15+
.statusMessageStatus message on the status line of the HTTP response frame00.00.15+
.headersHTTP response frame header00.00.15+



Details

.on(event,callback)

Registers an event handler.

NameTypeM/OSummaryNote
eventstringmandatoryAvailable event names are error, readable, and end.
callback()functionmandatoryExecutes callback processing when an event occurs.
returnundefined--

event : ’error’

Executes the callback process when the reception of HTTP response is not completed.
At the same time, it is reflected in the error event of {ClientRequest}.

event : ’readable’

Executes callback processing when data exists in the reception buffer for HTTP-response.
When receiving data, this event must be handled.
Note that this readable event does not occur, and the end event may occur directly.

event : ’end’

Executes the callback process when the reception of HTTP-response is completed.
When receiving data, this event must be handled.

.read()

Reads Response-Body.

NameTypeM/OSummaryNote
returnstring, null-Read Response-Body dataIf it does not exist, null is returned.

.readBin()

Reads Response-Body in binary format.

NameTypeM/OSummaryNote
returnArrayBuffer, null-Read Response-Body dataIf it does not exist, null is returned.

This is a sample to read a character string in binary.

res.on('end' ,function() {
  r_data = res.readBin();
  r_data_u8 = new Uint8Array(r_data);
  var s = '';
  for( n = 0 ; n < r_data_u8.length ; n++){
    s += r_data_u8[n].toString();
  }
  print('body:' + s);
});

.statusCode

This property has a value of type number.
You can refer to the status code on the status line of the HTTP response frame.

.statusMessage

This property has a value of type string.
You can refer to the status message on the status line of the HTTP response frame.

.headers

This property has a value of type Object.
You can refer to the header of the HTTP response frame. The header name becomes the property name.

For example, to obtain the value of the 'Date' header from the response header, do the following:

https.request(options, function(res) {
 print(res.headers['Date']);
});



Object Usage Examples

Sample 1

This is a sample of the GET method. Reads data in a divided manner.

var HEADERS = {};
var options = {method: 'GET', host: '192.168.1.1', port: 443, path: '/test.txt', headers: HEADERS};
options.ca = '-----BEGIN CERTIFICATE-----\n' +
'SIGD0jCCArqgAwIBAgIBATANBgkqhkiG9w0BAQUFADB6MQswCQYDVQQGEwJKUDEO\n' +
'MAwGA1UECAwFSXdhdGUxFTATBgNVBAoMDE1vYmljb21tIEx0ZDEcMBoGA1UEAwwT\n' +
//........
'HvMvDtFO71gaEtIkpejHGLgGhQK1dQ==\n' +
'-----END CERTIFICATE-----\n';

var request = https.request(options, function(res) {
  print(res.statusCode);
  print(this.statusMessage);
  res.on('error', function() {
    print('response error!');
  });
  res.on('readable', function() {
    print(res.read());
  });
  res.on('end', function() {
    print(res.read());
    print('response complete!');
  });
});
request.on('error', function() {
  print('errCode=' + request.errCode);
});
request.end(function() {
  print('request done!!!');
});

Sample 2

This is a sample of the POST method. Send "Hello World".

var BODY = 'Hello World';
var HEADERS = {'Content-Type': 'text/plain', 'Content-Length': BODY.length.toString()};
var options = {method: 'POST', host: '192.168.1.1', port: 443, path: '/post', headers: HEADERS};
options.ca = '-----BEGIN CERTIFICATE-----\n' +
'SIGD0jCCArqgAwIBAgIBATANBgkqhkiG9w0BAQUFADB6MQswCQYDVQQGEwJKUDEO\n' +
'MAwGA1UECAwFSXdhdGUxFTATBgNVBAoMDE1vYmljb21tIEx0ZDEcMBoGA1UEAwwT\n' +
//........
'HvMvDtFO71gaEtIkpejHGLgGhQK1dQ==\n' +
'-----END CERTIFICATE-----\n';

var request = https.request(options, function(res) {
  print(res.statusCode);
  print(this.statusMessage);
  res.on('error', function() {
    print('response error!');
  });
  res.on('end', function() {
    print('response complete!');
  });
});
request.on('error', function() {
  print('errCode=' + request.errCode);
});
request.end(BODY, function() {
  print('request done!!!');
});



Updated: 2020-08-28
← 04. HTTP06. MQTT →
  • HTTPS Global Object
  • Details
    • https.request(options[,callback][,sockTo])
  • {ClientRequest}
  • Details
    • .on(event,callback)
    • event : ’error’
    • .write(data[,callback])
    • .end([data][,callback])
    • .abort()
    • .errCode
  • {IncomingMessage}
  • Details
    • .on(event,callback)
    • event : ’error’
    • event : ’readable’
    • event : ’end’
    • .read()
    • .readBin()
    • .statusCode
    • .statusMessage
    • .headers
  • Object Usage Examples
    • Sample 1
    • Sample 2
AboutNewsProductsFAQPrivacy Policy}
NEQTO Console
IntroductionFundamentalsAdministrative ActionsDevice Management NEQTO Apps
NEQTO Bridge Series
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.
© 2021 JIG-SAW INC.