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

›Integration

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

AWS IoT Core v2

This library is a built-in class that provides functions to communicate with AWS IoT Core.

Library usage requirements
Type Integrations
Name AWS_IoT_Core_V2
Version 2.1.0
Code size used 3.2KB
Resources used HTTPS x 1, MQTT x 1, Timers x 1

Related Documents

  • For detailed specifications regarding AWS IoT Core, please refer to the "AWS IoT Core Documentation".
  • Specification of the HTTPS object (NEQTO Bridge/STM32 Discovery/SPRESENSE/Linux)
  • Specification of the MQTT object (NEQTO Bridge/STM32 Discovery/SPRESENSE/Linux)



Abstracts

Methods()/PropertiesSummaryNote
new AWS_IOT_CORE()Creates an AWS_IOT_CORE instance.

{AWS_IOT_CORE} Instance

Methods()/PropertiesSummaryNote
.httpPost()Sends data to AWS IoT Core via HTTPS.
.abortHttpRequest()Aborts the currently ongoing HTTP request.
.mqttConnect()Connects to AWS IoT Core with MQTT.
.errorsArray containing invalid key names (string)
Generated when an invalid parameter is detected in the constructor or .setConfig().
.CONST.VERSIONVersion (string)v2.1.0+



Details

new AWS_IOT_CORE([config])

Creates an AWS_IOT_CORE instance.

NameTypeM/ODescriptionNote
configObjectoptionalConfiguration
Refer to config for details.
return{AWS_IOT_CORE}-{AWS_IOT_CORE} : Generated {AWS_IOT_CORE}If invalid parameters are detected, .errors will be generated.

config

NameTypeM/ODescriptionNote
hoststringmandatoryAn AWS IoT Core endpoint
deviceCertstringmandatoryThe X.509 certificate associated with this device
Specify a string in PEM format. Use \n for line feed code.
devicePrivKeystringmandatoryThe private key associated with this device
Specify a string in PEM format. Use \n for line feed code.
castringmandatoryRoot CA certificate for AWS IoT Core
Specify a string in PEM format. Use \n for line feed code.
httpTimeoutnumberoptionalHTTP request timeout value [s]
If 0, the timeout function is disabled.
The default value is 0.
v2.1.0+
timeoutnumber-This parameter is ignored.Unused

Set the Configuration (config) when creating an AWS_IOT_CORE instance.
If an invalid parameter is detected, an array containing the name of the invalid keys is generated as the .errors property. If the parameters are successful, the .errors property will be deleted.

var iot = new AWS_IOT_CORE({
    host: <value>,
    deviceCert: <value>,
    devicePrivKey: <value>,
    ca: <value>
});
if('errors' in iot) {
    //TODO: Handle errors
}

.setConfig(config)

Set the Configuration (config) after the AWS_IOT_CORE instance is created.
If an invalid parameter is detected, an array containing the name of the invalid keys is generated as the .errors property. If the parameters are successful, the .errors property will be deleted.

var iot = new AWS_IOT_CORE();
iot.setConfig({
    host: <value>,
    deviceCert: <value>,
    devicePrivKey: <value>,
    ca: <value>
});
if('errors' in iot) {
    //TODO: Handle errors
}

Setter Methods

After the AWS_IOT_CORE instance is created, Configuration (config) can be set individually using the following setter methods.
If successful, the own instance is returned. If an invalid parameter is detected, false is returned.

Setter MethodDescriptionNote
.setHost(value)Sets the host.
.setDeviceCert(value)Sets the deviceCert.
.setDevicePrivKey(value)Sets the devicePrivKey.
.setRootCA(value)Sets the ca.
.setHttpTimeout(value)Sets the httpTimeout.v2.1.0+
.setTimeout(value)Sets the timeout.Unused

.httpPost(topic,headers,getBody,callback[[,qos],sockTo])

Sends data to AWS IoT Core via HTTPS.
The destination will be the AWS IoT Core endpoint specified by topic.

NameTypeM/ODescriptionNote
topicstringmandatorySpecify the MQTT topic.
This configuration value is converted to /topics/${topic}.
headersobjectmandatorySpecify HTTP request headers.
"Content-Length" must be included.
getBodyfunctionmandatoryExecute callback processing at the timing when this method will accept the data (body) to be sent.
Returns data in string or ArrayBuffer chunks of 4KB or less until there is no more data, and finally returns null.
callback(err, resp)functionmandatoryExecute callback processing when this method is completed.
Notify the processing result using the argument of the callback function.
err: {HttpReqError}, null
resp: {HttpResponse}, null
If an error occurs in the HTTP request, err is set; if an HTTP response could be received, resp is set.
qosnumberoptionalSpecify the MQTT quality of service level.
This configuration value is converted to ?qos=${qos}.
The default value is 0.
sockTonumberoptionalSpecify the HTTP session timeout value [ms].
This parameter is the sockTo setting value of the https.request() method. For details, refer to the HTTPS object specification.
v2.1.0+
returnundefined-

{HttpReqError}

NameTypeDescriptionNote
.errCodenumberThe error code of the HTTPS request
For details, refer to the error code table of the HTTPS object.

{HttpResponse}

NameTypeDescriptionNote
.statusCodenumberThe status code of the HTTP response
.statusMessagestringThe status message of the HTTP response
.bodystring, nullHTTP response data (Response-Body)

.abortHttpRequest()

Aborts the currently ongoing HTTP request.

NameTypeM/ODescriptionNote
returnundefined-

.mqttConnect([options])

Connects to AWS IoT Core with MQTT.

This method is a wrapper function for the mqtt.connect() method.
Create an MQTT client instance {Client} for MQTT connection to AWS IoT Core.
Refer to MQTT object specification for information on how to use the generated {Client} instance.

NameTypeM/ODescriptionNote
optionsobjectoptionalThis parameter is the options setting of the mqtt.connect() method. For details, refer to the MQTT object specification.
return{Client}, undefined-MQTT client instance for AWS IoT Core

Configuration values related to mqtt.connect() that are overridden by this method:

  • mqtt.set(’ssl.ca’, certificate)
    • certificate: config.ca
  • mqtt.set(’ssl.cert’, certificate)
    • certificate: config.deviceCert
  • mqtt.set(’ssl.key’, clientkey)
    • clientkey: config.devicePrivKey
  • mqtt.connect(url[, options])
    • url: mqtts://${config.host}:8883



Usage Examples

The following common code is used in all sample code:

Make sure that the root CA certificate is appropriate for the AWS IoT Core endpoint in advance.
For information on how to obtain a CA certificate, please refer to here.

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

var rootCa = '-----BEGIN CERTIFICATE-----\n...<CA>...\n-----END CERTIFICATE-----';
var deviceCert = '-----BEGIN CERTIFICATE-----\n...<CERT>...\n-----END CERTIFICATE-----';
var deviceKey = '-----BEGIN RSA PRIVATE KEY-----\n...<KEY>...\n-----END RSA PRIVATE KEY-----';

//TODO: Configuration
var iot = new AWS_IOT_CORE({
    host: <value>,
    deviceCert: deviceCert,
    devicePrivKey: deviceKey,
    ca: rootCa
});
if('errors' in iot) {
    //TODO: Handle errors
    throw new Error("Invalid configuration");
}

Sample 1

Send data to AWS IoT Core via HTTPS.

var topic = "testtopic/shadowtopic/dummy";
var body = JSON.stringify({
    "message": "HTTP post"
});
var headers = {
    "Content-Length": body.length.toString()
};

var busy;
var getBody = function() {
    var temp = body;
    body = null;
    return temp;
};
var callback = function(err, resp) {
    if(err) {
        print("Error!", err.errCode);
    } else {
        print("Response:", resp.body);
        print("Status:", resp.statusCode, resp.statusMessage);
    }
    busy = false;
};

busy = true;
iot.httpPost(topic, headers, getBody, callback);
while(busy);
print("Done");

Sample 2

Send data in chunks to AWS IoT Core via HTTPS.

var topic = "testtopic/shadowtopic/dummy";
var body = JSON.stringify({
    "message": "This is a really long string[...]"
});
var headers = {
    "Content-Length": body.length.toString()
};

var busy;
var chunkSize = 8; //4KB or less
var index = 0;
var getBody = function() {
    var chunk = body.substring(index, index + chunkSize);
    if(chunk) {
        index = index + chunkSize;
        return chunk;
    }
    return null;
};
var callback = function(err, resp) {
    if(err) {
        print("Error!", err.errCode);
    } else {
        print("Response:", resp.body);
        print("Status:", resp.statusCode, resp.statusMessage);
    }
    busy = false;
};

busy = true;
iot.httpPost(topic, headers, getBody, callback);
while(busy);
print("Done");

Sample 3

Connect to AWS IoT Core with MQTT.
Use the automatic reconnection feature of the MQTT object.

var mqttConnect = function(onConnected, onDisconnected) {
    var cli = iot.mqttConnect({ reconnectCount: 1855 }); //Enable automatic reconnection
    if(!cli) return undefined;
    cli.on('error', function(err) {
        //TODO: Handle errors
        print("Error!", err.code, `(${cli.get('errnoConnect')})`);
    });
    cli.on('message', function(topic, message) {
        //TODO: Handle messages
        print("Message:", `[${topic}]`, message);
    });
    cli.on('close', function() {
        print("DISCONNECTED");
        if(onDisconnected) {
            onDisconnected();
        }
    });
    cli.on('connect', function() {
        print("CONNECTED");
        if(onConnected) {
            onConnected();
        }
    });
    return cli;
};

var onMqttConnect = function() {
    client.subscribe("testtopic/subtopic/#", { qos: 1 }, function(err) {
        if(err.code != 0) {
            //TODO: Handle errors
            print("Subscribe failed:", err.code);
        }
    });
};

var client = mqttConnect(onMqttConnect);
if(!client) {
    throw new Error("Failed to create mqtt instance");
}

var publishInterval = 5 * 1000;
var publishEvent = false;
var publishCnt = 0;
setInterval(function() {
    publishEvent = true;
}, publishInterval);

while(1) {
    if(client && client.canPublish() && publishEvent) {
        publishEvent = false;
        publishCnt++;
        var message = JSON.stringify({ "message": "publish" + publishCnt });
        client.publish("testtopic/subtopic/dummy", message, { qos: 1 }, function(err) {
            if(err.code == 0) {
                print("Publish OK");
            } else {
                //TODO: Handle errors
                print("Publish failed:", err.code);
            }
        });
    }
}

Sample 4

Connect to AWS IoT Core with MQTT.
Performs manual reconnection not using the automatic reconnection feature of the MQTT object.

var mqttConnect = function(onConnected, onDisconnected) {
    var cli = iot.mqttConnect();
    if(!cli) return undefined;
    cli.on('error', function(err) {
        //TODO: Handle errors
        print("Error!", err.code, `(${cli.get('errnoConnect')})`);
        if(err.code == 1 && onDisconnected) { //Connection failed
            onDisconnected();
            return;
        }
    });
    cli.on('message', function(topic, message) {
        //TODO: Handle messages
        print("Message:", `[${topic}]`, message);
    });
    cli.on('close', function() {
        print("DISCONNECTED");
        if(onDisconnected) {
            onDisconnected();
        }
    });
    cli.on('connect', function() {
        print("CONNECTED");
        if(onConnected) {
            onConnected();
        }
    });
    return cli;
};

var onMqttConnect = function() {
    client.subscribe("testtopic/subtopic/#", { qos: 1 }, function(err) {
        if(err.code != 0) {
            //TODO: Handle errors
            print("Subscribe failed:", err.code);
        }
    });
};
var onMqttDisconnect = function() {
    setTimeout(function() {
        print("Reconnecting...");
        client.reconnect();
    }, 10000);
};

var client = mqttConnect(onMqttConnect, onMqttDisconnect);
if(!client) {
    throw new Error("Failed to create mqtt instance");
}

var publishInterval = 5 * 1000;
var publishEvent = false;
var publishCnt = 0;
setInterval(function() {
    publishEvent = true;
}, publishInterval);

while(1) {
    if(client && client.canPublish() && publishEvent) {
        publishEvent = false;
        publishCnt++;
        var message = JSON.stringify({ "message": "publish" + publishCnt });
        client.publish("testtopic/subtopic/dummy", message, { qos: 1 }, function(err) {
            if(err.code == 0) {
                print("Publish OK");
            } else {
                //TODO: Handle errors
                print("Publish failed:", err.code);
            }
        });
    }
}


The company names and product names mentioned above are registered trademarks or trademarks of their respective companies.

Updated: 2024-03-26
← AWS S3 v2Azure IoT v2 →
  • Abstracts
    • {AWS_IOT_CORE} Instance
  • Details
    • new AWS_IOT_CORE([config])
    • .httpPost(topic,headers,getBody,callback[[,qos],sockTo])
    • {HttpReqError}
    • {HttpResponse}
    • .abortHttpRequest()
    • .mqttConnect([options])
  • Usage Examples
    • Sample 1
    • Sample 2
    • Sample 3
    • Sample 4
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.