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

20. nqMqtt

The nqMqtt object is a built-in object that provides MQTT communication function with NEQTO Console.

Functional overview:

  • Provides functions to send measurements and arbitrary data to NEQTO Console.
  • Provides a function to receive push notifications from NEQTO Console.



nqMqtt Global Object

Methods()/PropertiesSummaryVersionNote
nqMqtt.on()Registers an event handler.00.00.15+
nqMqtt.publish()Publishes a message to NEQTO Console.00.00.15+
nqMqtt.end()Terminates nqMqtt.00.00.15+
nqMqtt.isConnected()Gets MQTT connection status.00.00.15+
nqMqtt.isReconnecting()Gets the status of MQTT when reconnecting.00.00.15+
nqMqtt.canPublish()Gets the status of whether the MQTT message can be published.00.00.18+
nqMqtt.get()Gets information related to the given argument.00.00.15+The following arguments can be used as of version 00.00.20+:
'LwM2MObjectS','LwM2MArgStrS','LwM2MString'



Details

nqMqtt.on(event,callback)

Registers an event handler.

NameTypeM/OSummaryNote
eventstringmandatoryEvent name
Names that can be used are; push, connect, reconnect, close, error
callback()functionmandatoryExecutes callback processing when an event occurs.
returnundefined--

event: ’push’

Registers a push event handler. Executes callback processing when receiving a push notification of a custom message from NEQTO Console. The arguments for the callback are as follows:

ArgumentsTypeSummaryNote
messagestringReceived message
A string of up to 380 bytes.
If maximum number of bytes is exceeded, the message is discarded.

event: ’connect’

Registers a connect event handler. Executes callback when MQTT connection and reconnection are successful. MQTT connection may be completed before the script starts. In that case, the callback will not be executed. The arguments for the callback are as follows:

ArgumentsTypeSummaryNote
connackObjectconnack is the content of the recieved connack packet.
This argument is not mandatory.

event: ’reconnect’

Registers a reconnect event handler. Executes callback when MQTT reconnection is started.

event: ’close’

Registers a close event handler. Executes callback when MQTT is disconnected.

event: ’error’

Registers an error event handler. Executes callback when an error occurs or the MQTT connection fails. The arguments for the callback are as follows:

ArgumentsTypeSummaryNote
err{MqttError}Error information

nqMqtt.publish(topic,message[,options][,callback])

Publishes a message to NEQTO Console.

NameTypeM/OSummaryNote
topicnullmandatoryTopic Name
This value must always be set to null.
messagestring, ObjectmandatoryMessage to publish
Specify the object returned by nqMqtt.get('LwM2MObject') or nqMqtt.get('LwM2MArgStr').
If the message to be published is more than 2500 bytes, an argument error occurs and the callback process of .on('error') is executed.
optionsObjectoptionalPublish Options
Not used. Please omit it.
callback(err)functionoptionalExecute the callback process when the publish process is completed.
err : {MqttError}
Error information
When err.code is 0, it means success.
returnundefined--

Note: If the next publish() is performed before the current publish() callback, the latter pubish() may be discarded. Before performing a publish(), it is recommended to check whether the callback of the previous publish() has been executed, or check whether publishing is possible with canPublish().

nqMqtt.end([callback])

Terminates nqMqtt. Use this function only when you need to terminate the script.

NameTypeM/OSummaryNote
callback()functionoptionalExecutes callback processing when nqMqtt terminates.
returnundefined--

nqMqtt.isConnected()

Gets MQTT connection status.

NameTypeM/OSummaryNote
returnboolean-MQTT connection status
true: MQTT connected
false: Not connected

nqMqtt.isReconnecting()

Gets the status of MQTT when reconnecting.

NameTypeM/OSummaryNote
returnboolean-MQTT reconnecting status
true: MQTT reconnecting
false: Not reconnecting

nqMqtt.canPublish()

Gets the status of whether the MQTT message can be published.

NameTypeM/OSummaryNote
returnboolean-Whether the MQTT message can be published
true: Can publish
false: Cannot publish

nqMqtt.get(name[,args...])

Gets information related to the given argument.

NameTypeM/OSummaryNote
namestringmandatoryThe name of the data object to be obtained
Names that can be used are; LwM2MObject, LwM2MArgStr, LwM2MString, LwM2MObjectS, LwM2MArgStrS, LwM2MStringS
Generally, use 'LwM2MObject'.
Use 'LwM2MArgStr' when temporarily saving to a memory block.
Use 'LwM2MString' when sending sensor data using nqService.
argsstring, numberoptionalArguments used when getting the value
returnObject, string, undefined-Object : The requested object
string : The requested string data
undefined : Failure due to request error

nqMqtt.get(’LwM2MObject’,timestamp,objId,insId,resId,datatype,value[,resId2,datatype2,value2][,resId3,datatype3,value3][,resId4,datatype4,value4][,unit])

Creates a LwM2M object data to be used in the message of nqMqtt.publish().

For Object ID, Instance ID, Resource ID and Data Type, please refer to here. In addition, this setting must match the component settings on the NEQTO Console.

NameTypeM/OSummaryNote
’LwM2MObject’stringmandatoryName to get LwM2M object data
timestampnumbermandatoryTimestamp
Specify unixtime [ms].
objIdnumbermandatoryObject ID
The object ID uses the number defined by LwM2M.
insIdnumbermandatoryInstance ID
If there are multiple of the same Resource ID pairs, this is used to differentiate between them.
resIdnumbermandatoryResource ID
The resource ID uses the number defined by LwM2M.
datatypestringmandatoryData Type
The data type uses the number defined by LwM2M.
('Float', 'Integer', 'String', 'Boolean')
valuestringmandatoryValue
Specify a string type value.
When referencing data of type number, convert it to a string and specify it.
resId2numberoptionalThe second resource ID.
Same as resId.
resId, resId2, resId3, resId4 must specify different values for each.
datatype2stringoptionalThe second data type
Same as datatype.
value2stringoptionalThe second value
Same as value.
resId3numberoptionalThe third resource ID.
Same as resId.
resId, resId2, resId3, resId4 must specify different values for each.
datatype3stringoptionalThe third data type
Same as datatype.
value3stringoptionalThe third value
Same as value.
resId4numberoptionalThe fourth resource ID.
Same as resId.
resId, resId2, resId3, resId4 must specify different values for each.
datatype4stringoptionalThe fourth data type
Same as datatype.
value4stringoptionalThe fourth value
Same as value.
unitstringoptionalUnit
Specify any string indicating the unit.
('G', 'm', 's', 'ms', ...)
returnObject,
undefined
-Object : The created object data
undefined : If creation fails

Up to 4 objects created by nqMqtt.get(’LwM2MObject’) can be combined and used in nqMqtt.publish(). This sample publishes by combining temperature and humidity.

var utime = new Date().getTime();
var tempObj = nqMqtt.get(   'LwM2MObject',
                            utime,
                            3303,
                            0,
                            5700,'Float','25.0');
var humiObj = nqMqtt.get(   'LwM2MObject',
                            utime,
                            3304,
                            0,
                            5700,'Float','50.0');
var pubObj = [ tempObj , humiObj ];
nqMqtt.publish(null, pubObj, function(err){
    if(0 == err.code){
        print('publish OK');
    }
    else{
        print('publish NG');
    }
});

Note the allowable size of the publish message.

nqMqtt.get(’LwM2MArgStr’,timestamp,objId,insId,resId,datatype,value[,resId2,datatype2,value2][,resId3,datatype3,value3][,resId4,datatype4,value4][,unit])

Creates a LwM2M string data to be used in the message of nqMqtt.publish().

NameTypeM/OSummaryNote
’LwM2MArgStr’stringmandatoryName to get LwM2M string data
:::Subsequent arguments are the same as LwM2MObject.
returnObject
undefined
-string : The created string data
undefined : If creation fails

Up to 4 objects created by nqMqtt.get(’LwM2MArgStr’) can be combined and used in nqMqtt.publish(). This sample publishes by combining temperature and humidity.

var utime = new Date().getTime();
var tempObj = nqMqtt.get(   'LwM2MArgStr',
                            utime,
                            3303,
                            0,
                            5700,'Float','25.0');
var humiObj = nqMqtt.get(   'LwM2MArgStr',
                            utime,
                            3304,
                            0,
                            5700,'Float','50.0');
var pubObj = tempObj + ',' + humiObj;
nqMqtt.publish(null, pubObj, function(err){
    if(0 == err.code){
        print('publish OK');
    }
    else{
        print('publish NG');
    }
});

Note the allowable size of the publish message.

nqMqtt.get(’LwM2MString’,timestamp,objId,insId,resId,datatype,value[,resId2,datatype2,value2][,resId3,datatype3,value3][,resId4,datatype4,value4][,unit])

Creates a LwM2M string data to be used in the batch transmission method of nqService.

NameTypeM/OSummaryNote
’LwM2MString’stringmandatoryName to get LwM2M string data
:::Subsequent arguments are the same as LwM2MObject.
returnObject
undefined
-string : The created string data
undefined : If creation fails

nqMqtt.get(’LwM2MObjectS’,timestamp,objId,insId,resId,datatype,value[,resId2,datatype2,value2][,resId3,datatype3,value3][,resId4,datatype4,value4][,unit])

Creates a LwM2M object data to be used in the message of nqMqtt.publish(). Functionally the same as LwM2MObject, but each of the returned values are encrypted.

nqMqtt.get(’LwM2MArgStrS’,timestamp,objId,insId,resId,datatype,value[,resId2,datatype2,value2][,resId3,datatype3,value3][,resId4,datatype4,value4][,unit])

Creates a LwM2M string data to be used in the message of nqMqtt.publish(). Functionally the same as LwM2MArgStr, but each of the returned values are encrypted.

nqMqtt.get(’LwM2MStringS’,timestamp,objId,insId,resId,datatype,value[,resId2,datatype2,value2][,resId3,datatype3,value3][,resId4,datatype4,value4][,unit])

Creates a LwM2M string data to be used in the batch transmission method of nqService. Functionally the same as LwM2MString, but each of the returned values are encrypted.



Appendix

Object ID, Instance ID, Resource ID and Data Type

In NEQTO Console, you can select data display format and graph by resource ID. For the object ID, select any from the available IDs. See the LwM2M specification for examples of object ID and resource ID combinations. The instance ID is used to distinguish between multiple combinations of the same resource ID and object ID. The data type is defined in relation to the resource ID.

The object ID, resource ID and data type supported by NEQTO are as follows;

NameObject ID
Generic Sensor3300
Illuminance3301
Temperature3303
Humidity3304
Accelerometer3313
Magnetometer3314
Current3317
Pressure3323
Acidity(pH)3326
Conductivity3327
Distance3330
Colour3335
Location3336
Addressable Text Display3341
On/Off switch3342
Multi-state Selector3348
NameResource IDData Display FormatData Type
Digital Input State5500Boolean
Digital Input Counter5501Float,
Integer
Latitude5514String
Longitude5515String
Text5527String
Multi-state Input5547Float,
Integer
Sensor Value5700Float,
Integer
X Value5702Float,
Integer
Y Value5703Float,
Integer
Z Value5704Float,
Integer
Colour5706String
Application Type5750Float,
Integer

The following are examples of temperature sensor, humidity sensor, and acceleration sensor.

//value,Xvalue,Yvalue,Zvalue: Any numeric character string

var timestamp = new Date().getTime();

//Temperature sensor (ObjectID:Temperature, ResourceID:Sensor Value, DataType:Float)
nqMqtt.get('LwM2MObject',timestamp,3303,0,5700,"Float",value);

//Humidity sensor (ObjectID:Humidity, ResourceID:Sensor Value, DataType:Float)
nqMqtt.get('LwM2MObject',timestamp,3304,0,5700,"Float",value);

//Acceleration sensor (ObjectID:Accelerometer, ResourceID:X/Y/Z Value, DataType:Float)
nqMqtt.get('LwM2MObject',timestamp,3313,0,5702,"Float",Xvalue,5703,"Float",Yvalue,5704,"Float",Zvalue);

{MqttError}

Methods()/PropertiesTypeSummaryNote
.codenumberError code
Refer to mqtt errors table for error code details.
.messagestringError contents
Refer to mqtt errors table for error content details.

mqtt errors table

Error code table.

.code.messageNote
0OKNo error
1Connection failedConnection (reconnection) failure
10Illegal argumentInvalid argument error
11DisconnectedDisconnect error
12Publish failedPublish failed
13Subscribe failedSubscribe failed
14Unsubscribe failedUnsubscribe failed
255Other errorOther errors
OthersReservedReserved



Object Usage Examples

Sample 1

This is a sample to perform the following processing.

  • Prints custom messages received from the NEQTO Console.
  • Create and publish "acceleration", "temperature", and "color" data respectively.
//Register event handler
nqMqtt.on('connect',function(connack){
    print('mqttConnect');
});
nqMqtt.on('close',function(){
    print('nqMqttClose');
});
nqMqtt.on('error',function(err){
    print('mqttError:'+err.code.toString());
});
nqMqtt.on('push',function(message){
    print(message); //Received custom message
});

//Publish "Acceleration"
while(false==nqMqtt.canPublish()){setTimeout(100).wait();}
var valX = 1.0; /* dummy X value */
var valY = 1.1; /* dummy Y value */
var valZ = 1.2; /* dummy Z value */
var strX = valX.toFixed(1);
var strY = valY.toFixed(1);
var strZ = valZ.toFixed(1);
var utime = new Date().getTime();
var acceObj = nqMqtt.get(   'LwM2MObject',
                            utime,
                            3313,
                            0,
                            5702,'Float',strX,
                            5703,'Float',strY,
                            5704,'Float',strZ);
nqMqtt.publish(null,acceObj,function(err){
    if(0==err.code){
        print('publish OK');
    }
    else{
        print('publish NG');
    }
});

//Publish "Temperature"
while(false==nqMqtt.canPublish()){setTimeout(100).wait();}
var valT = 20.2; /* dummy Temperature */
var strT = valT.toFixed(1);
var utime = new Date().getTime();
var tempObj = nqMqtt.get(   'LwM2MObject',
                            utime,
                            3303,
                            0,
                            5700,'Float',strT);
nqMqtt.publish(null,tempObj,function(err){
    if(0==err.code){
        print('publish OK');
    }
    else{
        print('publish NG');
    }
});

//Publish "Color"
while(false==nqMqtt.canPublish()){setTimeout(100).wait();}
var strC = '"#FFFF99"'; /* dummy Color */
var utime = new Date().getTime();
var colorObj = nqMqtt.get(  'LwM2MObject',
                            utime,
                            3335,
                            0,
                            5706,'String',strC);
nqMqtt.publish(null,colorObj,function(err){
    if(0==err.code){
        print('publish OK');
    }
    else{
        print('publish NG');
    }
});



Updated: 2021-02-19
← 19. nqService21. nqFOTA →
  • nqMqtt Global Object
  • Details
    • nqMqtt.on(event,callback)
    • event: ’push’
    • event: ’connect’
    • event: ’reconnect’
    • event: ’close’
    • event: ’error’
    • nqMqtt.publish(topic,message[,options][,callback])
    • nqMqtt.end([callback])
    • nqMqtt.isConnected()
    • nqMqtt.isReconnecting()
    • nqMqtt.canPublish()
    • nqMqtt.get(name[,args...])
    • nqMqtt.get(’LwM2MObject’,timestamp,objId,insId,resId,datatype,value[,resId2,datatype2,value2][,resId3,datatype3,value3][,resId4,datatype4,value4][,unit])
    • nqMqtt.get(’LwM2MArgStr’,timestamp,objId,insId,resId,datatype,value[,resId2,datatype2,value2][,resId3,datatype3,value3][,resId4,datatype4,value4][,unit])
    • nqMqtt.get(’LwM2MString’,timestamp,objId,insId,resId,datatype,value[,resId2,datatype2,value2][,resId3,datatype3,value3][,resId4,datatype4,value4][,unit])
    • nqMqtt.get(’LwM2MObjectS’,timestamp,objId,insId,resId,datatype,value[,resId2,datatype2,value2][,resId3,datatype3,value3][,resId4,datatype4,value4][,unit])
    • nqMqtt.get(’LwM2MArgStrS’,timestamp,objId,insId,resId,datatype,value[,resId2,datatype2,value2][,resId3,datatype3,value3][,resId4,datatype4,value4][,unit])
    • nqMqtt.get(’LwM2MStringS’,timestamp,objId,insId,resId,datatype,value[,resId2,datatype2,value2][,resId3,datatype3,value3][,resId4,datatype4,value4][,unit])
  • Appendix
    • Object ID, Instance ID, Resource ID and Data Type
    • {MqttError}
    • mqtt errors table
  • Object Usage Examples
    • Sample 1
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.