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

›neqto.js Snippets

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

InfluxDB Snippet

This snippet can be used by copy-pasting to the neqto.js script.

NEQTO BridgeSPRESENSE
v00.00.30+v01.00.00+

This snippet provides a function to send IoT data to InfluxDB.

Details

The send_influxdb function can be used to POST the passed time-series data in Line Protocol format to an InfluxDB 'bucket' using its API, over HTTPS. The result (error/response) is then passed to the callback function.

To start using this snippet, HOST (Address of the InfluxDB instance), PORT (Port of the InfluxDB server), ORG_NAME (Name of the Organization), ACCESS_TOKEN (Token from InfluxDB account), and CA are required to be configured by the user.

NOTE: The provided function only allows payloads up to size of 4KB. For bigger sized payloads, please refer to the sample for divided writing in neqto.js docs for NEQTO Bridge and Sony Spresense.

The following CA can be used (as of 2020-07-30),

/* DST Root CA X3 - 44afb080d6a327ba893039862ef8406b */
var CA = "-----BEGIN CERTIFICATE-----\nMIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/\nMSQw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KbYK7p2CNTUQ\n-----END CERTIFICATE-----";
//=================================================================
// INFLUXDB SNIPPET
//=================================================================

//=================================================================
// The following configuration are MANDATORY. Set by user.
//=================================================================
// The address of the InfluxDB server.
// eg. '<REGION>.<PROVIDER>.cloud2.influxdata.com' or 'xx.xx.xx.xx'
var HOST = '<YOUR_HOST>';

// The port of the InfluxDB server.
// eg. 443 for Influx Cloud and 9999 for self-hosted InfluxDB server
var PORT = '<YOUR_PORT>';

// The Access Token for authorization, from InfluxDB.
// eg. 'xxxxxxxxxxxxxxxx'
var ACCESS_TOKEN = '<YOUR_ACCESS-TOKEN>';

// The name of the Organization to send data to.
var ORG_NAME = '<YOUR_ORGANIZATION>';

// Public certificate of the certificate authority that signed the InfluxDB server certificate for SSL/TLS handshake.  
// eg. '-----BEGIN CERTIFICATE-----\n...<CA>...\n-----END CERTIFICATE-----'
var CA = '<YOUR_CA>';
//=================================================================

/**
 * Upload data to InfluxDB Measurement Field using Access Token.
 * https://docs.influxdata.com/influxdb/v2.0/api/#operation/PostWrite
 * @function send_influxdb
 * @param {string} bucket - The bucket to send data to, as a String.
 * @param {string} measurement - The measurement to write data to, as a String.
 * @param {object} fieldsObj - All field key-value pairs for the point, as an Object.
 * @param {object} tagsObj - All tag key-value pairs for the point, as an Object.
 * @param {object} precision - The precision of the timestamp, as a String.
 * @param {function} callback - User callback to return the result (error/response).
 * @returns {undefined}
 */
var send_influxdb = function (bucket, measurement, fieldsObj, tagsObj, precision, callback) {
    var fields = '';
    for (var key in fieldsObj) fields += `,${key}=${fieldsObj[key]}`;
    var tags = '';
    for (var key in tagsObj) tags += `,${key}=${tagsObj[key]}`;
    var factor = 1000000; // precision == 'ms'
    if (precision == 's') factor = 0.001;
    else if (precision == 'ms') factor = 1;
    else if (precision == 'us') factor = 1000;
    var timestamp = Number(new Date().getTime() * factor);
    var body = `${measurement}${tags} ${fields.substring(1)} ${timestamp}`; // <measurement>[,<tag_key>=<tag_value>[,<tag_key>=<tag_value>]] <field_key>=<field_value>[,<field_key>=<field_value>] [<timestamp>]
    var options = {
        "method": 'POST',
        "host": HOST,
        "port": Number(PORT),
        "path": `/api/v2/write?org=${ORG_NAME}&bucket=${bucket}&precision=${precision}`,
        "headers": {
            "Content-Type": 'text/plain',
            "Authorization": `Token ${ACCESS_TOKEN}`,
            "Content-Length": body.length.toString()
        },
        "ca": CA
    };
    var request = https.request(options, function (response) {
        response.on('end', function () {
            callback(null, { "statusCode": response.statusCode, "statusMessage": response.statusMessage, "body": response.read() });
        });
    });
    request.on('error', function () {
        callback({ "errCode": request.errCode }, null);
    });
    request.end(body.toString(), function () {
        print("[request] SUCCESS");
    });
}

Function Usage Example

/*
<INSERT ABOVE SNIPPET HERE WITH SET CONFIGURATIONS>
*/

//=================================================================
log.setLevel(-1);       //-1:NONE 0:ERROR 1:WARNING 2:DEBUG 3:TRACE
log.printLevel(2);      //0:DISABLE 1:LOG 2:CONSOLE 3:BOTH
//=================================================================
// MAIN SCENARIO
//=================================================================

/**
 * Callback to fetch error/response from the request.
 * @function callback
 * @param {object} err - Error returned in case of a failed request. Has one property - `errCode`.
 * @param {object} data - Response returned by a successfully completed request. Has three properties - `statusCode`, `statusMessage`, and `body`.
 */
var callback = function (err, data) {
    if (err) {
        print("[error]", err.errCode);
    } else {
        print("[status]", data.statusCode, data.statusMessage);
        print("[response]", data.body);
    }
}

var bucket = "test";
var precision = "ms"; /* "s", "ms", "us", "ns" */
var measurement = "testMeasurement";
var fields = {
    "fieldKey1": '"stringValue"', /* string field value must be enclosed in double quotes */
    "fieldKey2": 'floatValue', /* float field value can be in scientific notation */
    "fieldKey3": 'integerValue_i', /* integer field values must have a trailing 'i' */
    "fieldKey4": 'unsignedIntegerValue_u', /* unsigned integer field values must have a trailing 'u' */
    "fieldKey5": 'booleanValue' /* t, T, true, True, TRUE; f, F, false, False, FALSE */
};
var tags = {
    "tagKey1": 'tagValue1',
    "tagKey2": 'tagValue2'
};
send_influxdb(bucket, measurement, fields, tags, precision, callback);
The company names and product names mentioned above are registered trademarks or trademarks of their respective companies.

Updated: 2021-02-19
← Google Sheets SnippetOracle Cloud Object Storage Snippet →
  • Details
  • Function Usage Example
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.