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 CloudSync for GCP
  • NEQTO Engine Firmware List
  • Support Guidelines

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. Utils
    • 14. nqLinux
    • 15. nqService
    • 16. nqMqtt
    • 17. nqFOTA
    • 18. 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
    • 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
  • SAP Cloud Platform Internet of Things
  • Splunk
  • Niagara

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

17. BLE

The ble object is a built-in object that provides BLE(Bluetooth Low Energy) functionality.

Functional overview:

  • Provides BLE Central and BLE Peripheral functions.
  • Provides the ability to scan the advertising data. (for Central)
  • Provides the GATT Client function. (for Central)
  • Provides the ability to send the advertising data. (for Peripheral)

Limitations:

  • Available only for the NEQTO Bridge Wi-Fi Module.
  • BLE Central and BLE Peripheral cannot be operated at the same time.
  • GATT Server function is not supported.
  • ble instance can be created only once.
  • When using Central, the number of simultaneous Peripheral connections is 1.



ble Global Object

Methods()/PropertiesSummaryVersionNote
ble.create()Creates the BLE instance.01.00.00+{Central} or {Peripheral} will be generated.



Details

ble.create(bleOptions)

Creates the BLE instance.

After creating a ble instance, you need to wait until the BLE function is activated.
The ready state can be determined by the done event callback.
Wi-Fi communication may be disconnected for about 30 seconds while preparing the BLE function.

ble instance can be created only once.
Note that the BLE resource that has been created once can be released by restarting the script.
In addition, it is necessary to reboot the device to return the once enabled BLE communication function to the completely stopped state.

NameTypeM/OSummaryNote
bleOptionsObjectmandatoryInstance configuration options
Refer to bleOptions for details.
return{Central},
{Peripheral}
-{Central} : Generated {Central}
{Peripheral} : Generated {Peripheral}
If resources are insufficient or parameters are abnormal, an exception occurs.

bleOptions

NameTypeM/OSummaryNote
rolestringmandatoryBLE role
Specify 'central' or 'peripheral'.
namestringmandatoryDevice name
Maximum length is 31 bytes.
Used only when 'peripheral' is specified.
advMaxnumberoptionalMaximum advertising interval [ms]
Range: 20~10240
The default value is 1250.
Used only when 'peripheral' is specified.
It must be greater than the minimum advertising interval.
advMinnumberoptionalMinimum advertising interval [ms]
Range: 20~10240
The default value is 1000.
Used only when 'peripheral' is specified.
It must be less than the maximum advertising interval.
ch37booleanoptionalEnable advertisning channel 37
The default value is true.
Used only when 'peripheral' is specified.
ch38booleanoptionalEnable advertisning channel 38
The default value is true.
Used only when 'peripheral' is specified.
ch39booleanoptionalEnable advertisning channel 39
The default value is true.
Used only when 'peripheral' is specified.



{Central}

This object is an object for performing BLE central operation.
You can scan nearby BLE devices to get advertising data.
You can also connect to a BLE device and perform data communication.

Methods()/PropertiesSummaryVersionNote
.advScan()Scans advertising data.01.00.00+
.connect()Connects to the BLE device.01.00.00+
.disconnect()Disconnects the BLE device.01.00.00+
.setCfg()Sets the characteristics.01.00.00+
.read()Reads the characteristics value.01.00.00+
.write()Writes to the characteristics value.01.00.00+
.on()Registers an event handler.01.00.00+



Details

.advScan(scanOptions)

Scans advertising data.
The acquired advertisement data will be notified by the get events.

NameType/ObjectM/OSummaryNote
scanOptionsobjectmandatoryScan options
Refer to scanOptions for details.
returnundefined--If parameters are abnormal, an exception occurs.

scanOptions

NameType/ObjectM/OSummaryNote
timenumbermandatoryScan time [ms]
Range: 100 - 40000
If the setting time is short, the advertising data may not be notified.
If the setting time is long, the advertising data of the same device address may be notified multiple times.
modenumbermandatoryScan mode
1: Active scan mode
2: Passive scan mode
addrstringoptionalDevice address filtering
Only the advertising data of the specified device address will be notified. If omitted, all advertising data will be notified.
If the scan cannot be started, an error event will occur.

.connect(devAddr,bond,callback)

Connects to the BLE device.

NameType/ObjectM/OSummaryNote
devAddrstringmandatoryDevice address to connect
Device address(12 digits) + Device address type(1digit)
Refer to About device address type.
bondnumbermandatorySecurity settings
0: Disable bonding
1: Enable bonding
When bonding is enabled, communication in connected state is secure.
Set 0 if the connected device does not support security.
callback(err)functionoptinalExecutes callback processing when connection is completed.
err : {number}
0: Success
other: Failure (error code)
returnundefined--If parameters are abnormal, an exception occurs.

.disconnect(devAddr,callback)

Disconnects the BLE device.

NameType/ObjectM/OSummaryNote
devAddrstringmandatoryConnected device address
Device address(12 digits) + Device address type(1digit)
Refer to About device address type
callback(err)functionoptinalExecutes callback processing when disconnection is completed.
err : {number}
0: Success
other: Failure (error code)
returnundefined--If parameters are abnormal, an exception occurs.

.setCfg(config,callback)

Sets the characteristics.
It must already be connected to the BLE device.

NameType/ObjectM/OSummaryNote
configobjectmandatoryCharacteristics configuration options
Refer to config for details.
callback(err)functionoptionalExecutes callback processing when setting is completed.
err : {number}
0: Success
other: Failure (error code)
returnundefined--If parameters are abnormal, an exception occurs.

config

NameType/ObjectM/OSummaryNote
devAddrstringmandatoryConnected device address
Device address(12 digits) + Device address type(1digit)
Refer to About device address type.
srvUuidstringmandatoryService UUID
Specify the UUID without hyphen.
chUuidstringmandatoryCharacterictics UUID
Specify the UUID without hyphen.
modenumbermandatoryNotify mode request
0: None
1: Notification
2: Indication
3: Notification + Indication

.read(readOptions,callback)

Reads the characteristics value.
It must already be connected to the BLE device.

NameType/ObjectM/OSummaryNote
readOptionsobjectmandatoryCharacteristics read options
Refer to readOptions for details.
callback(err,data)functionoptionalExecutes callback processing when data reading is completed.
err : {number}
0: Success
other: Failure (error code)
data : {ArrayBuffer}
Read data
If there is no read data, it will be null.
returnundefined--If parameters are abnormal, an exception occurs.

readOptions

NameType/ObjectM/OSummaryNote
devAddrstringmandatoryConnected device address
Device address(12 digits) + Device address type(1digit)
Refer to About device address type.
srvUuidstringmandatoryService UUID
Specify the UUID without hyphen.
chUuidstringmandatoryCharacterictics UUID
Specify the UUID without hyphen.

.write(writeOptions,data,callback)

Writes to the characteristics value.
It must already be connected to the BLE device.

NameType/ObjectM/OSummaryNote
writeOptionsobjectmandatoryCharacteristics write options
Refer to writeOptions for details.
dataArrayBuffermandatoryWrite data
callback(err)functionoptionalExecutes callback processing when data writing is completed.
err : {number}
0: Success
other: Failure (error code)
returnundefined--If parameters are abnormal, an exception occurs.

writeOptions

NameType/ObjectM/OSummaryNote
devAddrstringmandatoryConnected device address
Device address(12 digits) + Device address type(1digit)
Refer to About device address type.
srvUuidstringmandatoryService UUID
Specify the UUID without hyphen.
chUuidstringmandatoryCharacterictics UUID
Specify the UUID without hyphen.

.on(event,callback)

Registers an event handler.

NameType/ObjectM/OSummaryNote
eventstringmandatoryEvent name
Names that can be used are: error, done, scanEnd, get, disc, notify.
callback()functionmandatoryExecutes callback processing when an event occurs.
returnundefined--

event : ’error’

Executes callback when an error occurs
The arguments for the callback are as follows:

ArgumentsTypeSummaryNote
ercdnumbererror code

event : ’done’

In the generated instance, execute the callback process when Central function is ready.

event : ’scanEnd’

Executes callback processing at the end of scanning.

event : ’get’

Executes callback processing when advertising data is received.
The arguments for the callback are as follows:

ArgumentsTypeSummaryNote
devAddrstringDevice address
rssinumberReceived signal strength [dBm]
typenumberData type
1: Scan response data
2: Advertising data
dataArrayBufferReceived data

event : ’disc’

Executes callback processing when communication with the BLE device is disconnected.

event : ’notify’

Executes callback processing when Notification or Infdication is received from the BLE device.
Callback does not occur if you are not connected to a BLE device.
The arguments for the callback are as follows:

ArgumentsTypeSummaryNote
devAddrstringDevice address
c_uuidstringCharacteristics UUID
dataArrayBufferNotified data



{Peripheral}

This object is an object for performing BLE peripheral operation.
Advertise at specified intervals from the time when the BLE Peripheral function is ready.
You can edit your own device name and the advertising data to send.

Methods()/PropertiesSummaryVersionNote
.edtAdv()Edits the advertising data.01.00.00+
.edtScn()Edits the scan response data.01.00.00+
.edtName()Edits the device name.01.00.00+
.on()Registers an event handler.01.00.00+



Details

.edtAdv(data)

Edits the advertising data.

NameType/ObjectM/OSummaryNote
dataArrayBuffermandatoryAdvertising data
The maximum data length is 24 bytes.
returnundefined--If parameters are abnormal, an exception occurs.

.edtScn(data)

Edits the scan response data.

NameType/ObjectM/OSummaryNote
dataArrayBuffermandatoryScan response data
The maximum data length is 27 bytes.
returnundefined--If parameters are abnormal, an exception occurs.

.edtName(name)

Edits the device name.
If you edit the device name, the scan response data will be updated.

NameType/ObjectM/OSummaryNote
namestringmandatoryDevice name
The maximum data length is 31 bytes.
returnundefined--If parameters are abnormal, an exception occurs.

.on(event,callback)

Registers an event handler.

NameType/ObjectM/OSummaryNote
eventstringmandatoryEvent name
Names that can be used are: error, done.
callback()functionmandatoryExecutes callback processing when an event occurs.
returnundefined--

event : ’error’

Executes callback when an error occurs.
The arguments for the callback are as follows:

ArgumentsTypeSummaryNote
ercdnumbererror code

event : ’done’

In the generated instance, execute the callback process when Peripheral function is ready.



Appendix

error code

CodeSummaryNote
0No error
1Processing conflict
2Invalid argument error
3Memory allocation failure
4Disconnected
5Specified Characteristics not detected
6The number of generations reached the upper limit
7connection refused
128Other errorOther errors
otherReserved

About device address type

'p' or 'r' is added to the end of the device address notified when the advertising data is received.
This represents the type of device address.

CharacterTypeSummaryNote
rRandom addressThe address that can change dynamically.
When connecting to a device, you must specify the device address up to 'r'.
pPublic addressThis address is fixed for each device.
Specify only the device address when connecting to the device.



Object Usage Examples

Sample 1

Creates the BLE central instance.
After creating the instance, scan for 1 second.
Display the advertising data.


///// create BLE central instance
var bleState= -1;
var central=ble.create({role:'central'});
///// event 'done'
central.on('done', function(){
  bleState = 0;
});
///// event 'error'
central.on('error', function(ercd) {
  print('Error(error code:' + ercd + ')');
});
///// event 'scan end'
central.on('scanEnd', function(){
  bleState = 0;
});
///// event 'get'
central.on('get', function(devAddr, rssi, type, advDat) {
  print('device addr: ' + devAddr);
  print('rssi       : ' + rssi);
  print('type       : ' + type);
  var datStream = new Uint8Array(advDat);
  var prnDat = '';
  for (var i=0; i<datStream.length; i++) {
    prnDat += (('00' + datStream[i].toString(16).toUpperCase()).substr(-2));
    prnDat += ' ';
  }
  print(prnDat);
});
while(bleState != 0) {} // Wait for BLE function activation

///// advertise scan start
var advOpt={time:1000,mode:2};
central.advScan(advOpt);
bleState = 1;

while(bleState != 0) {} // Wait for scan end

Sample 2

Creates the BLE peripheral instance.
Edits the advertising data every 60 seconds.

///// create BLE peripheral instance
var bleState = -1;
var bleOptions = {role:'peripheral',name:'neqto'};
var peripheral = ble.create(bleOptions);
///// event 'done'
peripheral.on('done', function() {
 print('ble instance created');
 bleState = 0;
});
///// event 'error'
peripheral.on('error',function(ercd){
 print('error(' + ercd + ')');
});
while(bleState != 0) {} // Wait for BLE function activation

///// device name edit
peripheral.edtName('NEQTO Bridge');

var editCnt = 0;
var to = setInterval(function(){
 var aryBuf = new ArrayBuffer(3);
 var advDat = new Uint8Array(aryBuf);
 editCnt++;
 advDat[0] = editCnt % 1000 / 100 + 0x30; 
 advDat[1] = editCnt % 1000 % 100 / 10 + 0x30;
 advDat[2] = editCnt % 10 + 0x30;
 ///// advertise data edit
 peripheral.edtAdv(aryBuf);
}, 60000);

Sample 3

Creates the BLE central instance.
Connects the BLE device.
Configure the notification settings for characteristics.
Writes a value to the characteristics.

var DevAddr = 'CAFExxxx5963r';
var ServiceUUID = '0E5E300088004649xxxxxxxxxxxxxxxx';
var NotifyCharacteristicsUUID = '0E5E300188004649xxxxxxxxxxxxxxxx';
var WriteCharacteristicsUUID = '0E5E300488004649xxxxxxxxxxxxxxxx';

///// create BLE central instance
var bleState = -1;
var bleOptions = {role:'central'};
var central = ble.create(bleOptions);
///// event 'done'
central.on('done', function(){
  bleState = 0;
});
///// event 'error'
central.on('error', function(ercd) {
  print('Error(error code:' + ercd + ')');
});
///// event 'notify'
central.on('notify', function(devAddr, c_uuid, data) {
  var noteDat = new Uint8Array(data);

  print('device address: '+ devAddr);
  print('UUID: ' + c_uuid);
  print('data length: ' + noteDat.length);
});
while(bleState != 0) {} // Wait for BLE function activation

// connect
bleState = 1;
central.connect(DevAddr, 0, function(err) {
  print('connect:'+err);
  bleState = 0;
});
while(bleState != 0) {} // Waiting for BLE connect

// config setting
var config = {
  devAddr: DevAddr,
  srvUuid: ServiceUUID,
  chUuid: NotifyCharacteristicsUUID,
  mode:1
};
bleState = 1;
central.setCfg(config, function(err) {
  print('configuration finish:'+err);
  bleState = 0;
});
while(bleState != 0) {} // Waiting for config

// write
var wrOptions = {
  devAddr: DevAddr,
  srvUuid: ServiceUUID,
  chUuid: WriteCharacteristicsUUID,
};
var data = new ArrayBuffer(1);
var wrDat = new Uint8Array(data);
wrDat[0] = 0x01;
bleState = 1;
central.write(wrOptions, data, function(err) {
  print('data wrote:'+err);
  bleState = 0;
});



Updated: 2022-06-03
← 16. ADC18. Utils →
  • ble Global Object
  • Details
    • ble.create(bleOptions)
    • bleOptions
  • {Central}
  • Details
    • .advScan(scanOptions)
    • scanOptions
    • .connect(devAddr,bond,callback)
    • .disconnect(devAddr,callback)
    • .setCfg(config,callback)
    • config
    • .read(readOptions,callback)
    • readOptions
    • .write(writeOptions,data,callback)
    • writeOptions
    • .on(event,callback)
    • event : ’error’
    • event : ’done’
    • event : ’scanEnd’
    • event : ’get’
    • event : ’disc’
    • event : ’notify’
  • {Peripheral}
  • Details
    • .edtAdv(data)
    • .edtScn(data)
    • .edtName(name)
    • .on(event,callback)
    • event : ’error’
    • event : ’done’
  • Appendix
    • error code
    • About device address type
  • Object Usage Examples
    • Sample 1
    • Sample 2
    • Sample 3
AboutNewsProductsFAQPrivacy 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.
© 2023 JIG-SAW INC.