0.0.1 • Published 6 years ago

node-omron-envsensor v0.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

node-omron-envsensor

The node-omron-envsensor is a Node.js module which allows you to communicate with the OMRON Environment Sensor (2JCIE-BL01).

OMRON Environment Sensor (2JCIE-BL01)

Supported OS

The node-omron-envsensor supports only Linux-based OSes, such as Raspbian, Ubuntu, and so on. This module does not support Windows and Mac OS for now. (If noble is installed properly, this module might work well on such OSes.)

Dependencies

See the document of the noble for details on installing the noble.

Note that the noble has to be run as root on most of Linux environments. Noarmal users can not access the BLE using the noble generally. See the document of the noble for details.

Installation

$ cd ~
$ npm install noble
$ npm install node-omron-envsensor

Table of Contents


Quick Start

Discovering and connecting to a device

The code below discovers a device, establishes a connection with the device, then gets the device information.

// Load the node-omron-envsensor and get a `Envsensor` constructor object
const Envsensor = require('../lib/envsensor.js');
// Create an `Envsensor` object
const envsensor = new Envsensor();
// `EnvsensorDevice` object
let device = null;

// Initialize the `Envsensor` object
envsensor.init().then(() => {
  // Discover a device
  return envsensor.discover({quick:true});
}).then((device_list) => {
  if(device_list.length === 0) {
    throw new Error('No device was found.');
  }
  // `EnvsensorDevice` object representing the found device
  device = device_list[0];
  // Connect to the device
  return device.connect();
}).then(() => {
  // Get the device information
  return device.getDeviceInfo();
}).then((data) => {
  // Show the device information
  console.log(JSON.stringify(data, null, '  '));
  // Disconnect the device
  return device.disconnect();
}).then(() => {
  process.exit();
}).catch((error) => {
  console.error(error);
});

First of all, you have to create an Envsensor object from the Envsensor constructor object. In the code above, the variable envsensor is the Envsensor object.

Calling the init() method, the Envsensor object becomes ready for use. Never forget to call the method. Note that the all asynchronous methods implemented in the Envsensor object return a Promise object.

The discover() method of the Envsensor object discovers OMRON Environment Sensor 2JCIE-BL01 devices. By default, the discovery process takes 5 seconds. In the code above, the quick parameter is set to true. This means that the method returns immediately after a device is found.

In the code above, the variable device is a EnvsensorDevice object representing the found device. This object provides a lot of methods to interact with the device.

At this moment, you are not able to interact with the device yet. You have to call the connect() method in order to interact with it. Once the device is connected, you can call the all methods provided by the EnvsensorDevice object.

The sample code above will output the result as follows:

{
  "deviceName": "EnvSensor-BL01",
  "modelNumber": "2JCIE-BL01",
  "serialNumber": "0586MY0005",
  "firmwareRevision": "01.09",
  "hardwareRevision": "01.01",
  "manufacturerName": "OMRON"
}

See the section "getDeviceInfo() method" for the details of the meanings of the values.

Getting the latest sensor data

The OMRON Environment Sensor 2JCIE-BL01 stores the latest sensor data in the flash memory. You can obtain the latest sensor data using the getLatestData() method of the EnvsensorDevice object anytime.

// Load the node-omron-envsensor and get a `Envsensor` constructor object
const Envsensor = require('node-omron-envsensor');
// Create an `Envsensor` object
const envsensor = new Envsensor();
// `EnvsensorDevice` object
let device = null;

// Initialize the `Envsensor` object
envsensor.init().then(() => {
  // Discover a device
  return envsensor.discover({quick:true});
}).then((device_list) => {
  if(device_list.length === 0) {
    throw new Error('No device was found.');
  }
  // `EnvsensorDevice` object representing the found device
  device = device_list[0];
  // Connect to the device
  return device.connect();
}).then(() => {
  // Get the latest sensor data
  return device.getLatestData();
}).then((data) => {
  // Show the result
  console.log(JSON.stringify(data, null, '  '));
  // Disconnect the device
  return device.disconnect();
}).then(() => {
  process.exit();
}).catch((error) => {
  console.error(error);
});

The sample code above will output the result as follows:

{
  "rowSeq": 0,
  "temperature": 31.41,
  "humidity": 40.67,
  "ambientLight": 140,
  "uvIndex": 0.02,
  "pressure": 996.8,
  "soundNoise": 46.01,
  "discomfortIndex": 78.57,
  "heatStroke": 25.38,
  "batteryVoltage": 2854
}

See the section "getLatestData() method" for the details of the meanings of the values.

Receiving sensor data notifications

The OMRON Environment Sensor 2JCIE-BL01 supports a notification mechanism to notify sensor data in real time.

You have to set the measurement interval using the setBasicConfigurations() method. The code blow sets the interval to 3 seconds. This means that the device notifies the sensor data every 3 seconds.

Then you have to set the onsensordata event handler to receive notifications coming from the device.

Calling the startMonitoringData() method, the device starts to notify sensor data and the onsensordata event handler is called whenever a notification is received.

Calling the stopMonitoringData() method, the device stops to notify sensor data.

// Load the node-omron-envsensor and get a `Envsensor` constructor object
const Envsensor = require('node-omron-envsensor');
// Create an `Envsensor` object
const envsensor = new Envsensor();
// `EnvsensorDevice` object
let device = null;

// Initialize the `Envsensor` object
envsensor.init().then(() => {
  // Discover a device
  return envsensor.discover({quick:true});
}).then((device_list) => {
  if(device_list.length === 0) {
    throw new Error('No device was found.');
  }
  // `EnvsensorDevice` object representing the found device
  device = device_list[0];
  // Connect to the device
  return device.connect();
}).then(() => {
  // Set the measurement interval to 3 seconds
  return device.setBasicConfigurations({
    measurementInterval: 3
  });
}).then(() => {
  // Set a callback function to receive notifications
  device.onsensordata = (data) => {
    console.log(JSON.stringify(data, null, '  '));
  };
  // Start monitoring data
  return device.startMonitoringData();
}).then(() => {
  // Stop monitoring data and disconnect the device in 10 seconds
  setTimeout(() => {
    // Stop monitoring data
    device.stopMonitoringData().then(() => {
      // Disconnect the device
      return device.disconnect();
    }).then(() => {
      process.exit();
    });
  }, 10000);
}).catch((error) => {
  console.error(error);
});

The sample code above will output the result as follows:

{
  "rowSeq": 0,
  "temperature": 31.51,
  "humidity": 40.46,
  "ambientLight": 135,
  "uvIndex": 0.02,
  "pressure": 996.8,
  "soundNoise": 33.18,
  "discomfortIndex": 78.65,
  "heatStroke": 25.46,
  "batteryVoltage": 2858
}
...

See the section "getLatestData() method" for the details of the meanings of the values.


Envsensor object

In order to use the node-omron-envsensor, you have to load the node-omron-envsensor module as follows:

const Envsensor  = require('node-omron-envsensor');

You can get an Envsensor constructor from the code above. Then you have to create an Envsensor object from the Envsensor constructor as follows:

const envsensor = new Envsensor();

The Envsensor constructor takes an argument optionally. It must be a hash object containing the properties as follows:

PropertyTypeRequiredDescription
nobleNobleoptiona Noble object of the noble module

The node-omron-envsensor module uses the noble module in order to interact with the device(s) on BLE. If you want to interact other BLE devices using the noble module, you can create an Noble object by yourself, then pass it to this module. If you don't specify a Noble object to the noble property, this module automatically create a Noble object internally.

The sample code below shows how to pass a Nobel object to the Envsensor constructor.

// Create a Noble object
const noble = require('noble');

// Create a Envsensor object
const Envsensor = require('node-omron-envsensor');
const envsensor = new Envsensor({'noble': noble});

In the code snippet above, the variable envsensor is an Envsensor object. The Envsensor object has a lot of methods as described in sections below.

init() method

A Envsensor object is not ready to use initially. It has to be initialized using the init() method as below:

envsensor.init().then(() => {
  // You can call methods implemented in the `Envsensor` object
}).catch((error) => {
  console.error(error);
});

The init() method returns a Promise object. Once the Envsensor object is initialized successfully, you can call methods as described in the sections below.

discover([params]) method

The discover method finds devices. This method returns a Promise object. This method takes an argument which is a hash object containing parameters as follows:

PropertyTypeRequiredDescription
durationIntegerOptionalDuration for discovery process (msec). The default value is 5000 (msec).
idFilterStringOptionalIf this value is set, the device whose ID (id) does not start with the specified keyword will be ignored.
quickBooleanOptionalIf this value is true, this method finishes the discovery process when the first device is found, then calls the resolve() function without waiting the specified duration. The default value is false.

In the code snippet below, no parameter is passed to the method:

envsensor.init().then(() => {
  return envsensor.discover();
}).then((device_list) => {
  // Do something...
}).catch((error) => {
  console.error(error);
});

If no parameter is passed to the method as code above, an Array object will be passed to the resolve() function in 5 seconds. The Array object contains EnvsensorDevice objects representing the found devices. See the section "EnvsensorDevice objects" for more details.

If you want a quick response, you can set the quick property to true.

envsensor.init().then(() => {
  return envsensor.discover({
    duration: 5000,
    quick: true
  });
}).then((device_list) => {
  // Do something...
}).catch((error) => {
  console.error(error);
});

As the quick property is set to true, the resolve() function will be called immediately after a device is found regardless the value of the duration property.

ondiscover event hander

The ondiscover property on the Envsensor object is an event handler whenever a device is newly found in the discovery process. A EnvsensorDevice object is passed to the callback function set to the ondiscover property.

envsensor.init().then(() => {
  envsensor.ondiscover = (device) => {
    console.log('- ' + device.id);
  };
  console.log('Starting the discovery process...');
  return envsensor.discover({
    duration: 10000
  });
}).then((device_list) => {
  console.log('The discovery process was finished.');
  console.log(device_list.length + ' devices were found.');
  process.exit();
}).catch((error) => {
  console.error(error);
});

The code snippet above will output the result as follows:

Starting the discovery process...
- c4f4393b5905
- ded7723b7199
The discovery process was finished.
2 devices were found.

scartScan([params]) method

The startScan() method starts to scan advertising packets from devices. This method takes an argument which is a hash object containing the parameters as follows:

PropertyTypeRequiredDescription
idFilterStringOptionalIf this value is set, advertising packets from the devices whose ID (id) does not start with the specified keyword will be ignored.

Whenever a packet is received, the callback function set to the onadvertisement property of the Envsensor object will be called. When a packet is received, a hash object representing the packet will be passed to the callback function.

// Set a callback function called when a packet is received
envsensor.onadvertisement = (ad) => {
  console.log(JSON.stringify(ad, null, '  '));
};

// Start to scan advertising packets from BL01
envsensor.startScan({
  idFilter: 'ded7723b7199'
});

// Stop to scan in 30 seconds
setTimeout(() => {
  envsensor.stopScan();
  process.exit();
}, 30000);

The code snippet above will output the result as follows:

{
  "id": "ded7723b7199",
  "uuid": "ded7723b7199",
  "address": "de:d7:72:3b:71:99",
  "localName": "Env",
  "rssi": -29,
  "companyId": "02d5",
  "data": { ... }
}
...

The data property depends on the beacon mode. See the section "Advertisement data" for the details of the data format.

stopScan() method

The stopScan() method stops to scan advertising packets from devices. See the section "startScan() method" for details.

onadvertisement event handler

If a callback function is set to the onadvertisement property, the callback function will be called whenever an advertising packet is received from a device during the scan is active (from the moment when the startScan() method is called, to the moment when the stopScan() method is called).

See the section "startScan() method" for details.


EnvsensorDevice object

The EnvsensorDevice object represents an OMRON Environment Sensor (2JCIE-BL01), which is created through the discovery process triggered by the Envsensor.discover() method. This section describes the properties and methods implemented in this object.

Properties

The EnvsensorDevice object supports the properties as follows:

PropertyTypeDescription
idStringID of the device. (e.g., "192.168.10.4")
ondisconnectedFunctionSee the section "ondisconnected event handler" for details.
onsensordataFunctionSee the section "onsensordata event handler" for details.
oneventflagFunctionSee the section "oneventflag event handler" for details.

isConnected() method

The isConnected() method returns whether the device is connected or not. If the device is connected, this method returns true. Otherwise, it returns false.

if(device.isConnected()) {
  console.log('Connected.');
} else {
  console.log('Not connected.');
}

connect() method

The connect() method establishes a connection with the device (i.e., pairing). This method returns a Promise object. If the device has already been connected, this method does nothing and calls the resolve() function immediately.

The code snippet below establishes a connection with a device, then it shows the ID of the device. Finally, it disconnects the device:

device.connect().then(() => {
  console.log('Connected.');
  console.log('- ' + device.id);
  return device.disconnect();
}).then(() => {
  console.log('Disconnected.');
}).catch((error) => {
  console.error(error);
});

The result will be as follows:

Connected.
- ded7723b7199
Disconnected.

disconnect() method

The disconnect() method disconnects the device. This method returns a Promise object. If the device has already been disconnected, this method does nothing and calls the resolve() function immediately.

See the previous section for details.

ondisconnected event handler

The ondisconnected event handler will be called when the connection with the device is disconnected. When this event handler is called, a hash object which contains the properties as follows is passed to this event handler:

PropertyTypeDescription
wasCleanBooleanIf the connection was closed intentionally, that is, if the connection was closed because the disconnect() method was called, this value is true. Otherwise, this value is false.
device.ondisconnected = (reason) => {
  if(reason.wasClean === true) {
    console.log('The connection was closed intentionally.');
  } else {
    console.log('The connection was closed unexpectedly.')
  }
};

getDeviceInfo() method

The getDeviceInfo() method fetches the device information from the device. This method returns a Promise object.

If the information is fetched successfully, a hash object containing the information will be passed to the resolve() function. The hash object has the properties as follows:

PropertyTypeDescription
deviceNameStringDevice Name (e.g., "EnvSensor-BL01")
modelNumberStringModel Number (e.g., "2JCIE-BL01")
serialNumberStringSerial Number (e.g., "0586MY0005")
firmwareRevisionStringFirmware Revision (e.g., "01.09")
hardwareRevisionStringHardware Revision (e.g., "01.01")
manufacturerNameStringManufacturer Name (e.g., "OMRON")
device.getDeviceInfo().then((data) => {
  console.log(JSON.stringify(data, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "deviceName": "EnvSensor-BL01",
  "modelNumber": "2JCIE-BL01",
  "serialNumber": "0586MY0005",
  "firmwareRevision": "01.09",
  "hardwareRevision": "01.01",
  "manufacturerName": "OMRON"
}

Though most of values are fixed values, only the value of the deviceName could be changed depending on the beacon mode.

Beacon ModeBeacon Mode NameDevice Name
0x00Event Beacon (SCAN RSP)"EnvSensor-BL01"
0x01Standard Beacon"EnvSensor-BL01"
0x02General Broadcaster 1"IM-BL01"
0x03Limited Broadcaster 1"IM-BL01"
0x04General Broadcaster 2"EP-BL01"
0x05Limited Broadcaster 2"EP-BL01"
0x07Alternate Beacon"EnvSensor-BL01"
0x08Event Beacon (ADV)"EnvSensor-BL01"

getBasicConfigurations() method

The getBasicConfigurations() method fetches the basic configurations from the device. This method returns a Promise object.

If the basic configurations are fetched successfully, a hash object containing the configurations will be passed to the resolve() function. The hash object has the properties as follows:

PropertyTypeDescription
measurementIntervalIntegerMeasurement interval. The unit is second. The value is in the range of 1 to 3600.
beaconModeIntegerBeacon Mode. The value is 0, 1, 2, 3, 4, 5, 7, or 8. See the section "Advertisement data" for details.
txPowerLevelIntegerTx Power. The unit is dBm. The value is -20, -16, -12, -8, -4, 0, or 4.
uuidStringUUID. This value is used when the beacon mode is 0x07 (Alternate Beacon). When the device is in the beacon mode, it sends iBeacon compatible packets as advertising packets.
device.getBasicConfigurations().then((data) => {
  console.log(JSON.stringify(data, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "measurementInterval": 3,
  "beaconMode": 8,
  "txPowerLevel": 0,
  "uuid": "0C4C3000-7700-46F4-AA96D5E974E32A54"
}

setBasicConfigurations(params) method

The setBasicConfigurations() method sets the basic configurations to the device. This method returns a Promise object.

This method takes a hash object as an argument containing the properties as follows:

PropertyTypeRequiredDescription
measurementIntervalIntegerOptionalMeasurement interval. The value must be in the range of 1 to 3600 (sec).
beaconModeIntegerOptionalBeacon Mode. The value must be 0, 1, 2, 3, 4, 5, 7, or 8. See the section "Advertisement data" for details.
txPowerLevelIntegerOptionalTx Power. The value must be -20, -16, -12, -8, -4, 0, or 4 (dBm).
uuidStringOptionalUUID. This value is used when the beacon mode is 0x07 (Alternate Beacon). When the device is in the beacon mode, it sends iBeacon compatible packets as advertising packets. The format must be "0C4C3000-7700-46F4-AA96D5E974E32A54".

Note that at least one property must be specified though all properties are optional.

Though the device supports the iBeacon compatible advertising packet, it does not allow you to set the values of the major and the minor and apply them to iBeacon compatible packets. In an iBeacon compatible packet, the major and the minor are used for other purposes. See the section "Advertisement data" for details.

device.setBasicConfigurations({
  measurementInterval: 3,
  beaconMode: 0
}).then(() => {
  console.log('Done.');
}).catch((error) => {
  console.error(error);
});

getRecordingStatus() method

The OMRON Environment Sensor (2JCIE-BL01) supports storing measurement records in its flash memory. The flash memory is divided to 2048 blocks which are called "pages". 13 records can be stored in a page. That is, at most 26,624 (13 2048) records can be stored in the flash memory. The page number is in the range of 0 to 2047. The row number is in the range of 0 to 12. In this document, the storing position in the flash memory is represented in the form of (page, row*). (0, 0) means that the page number is 0 and the row number is 0. (0, 1) means that the page number is 0 and the row number is 1.

By default, the recording mode is disabled. You can enable the recording mode using the startRecording() method, disable using the stopRecording() method.

After the recording mode is started, the first record is saved in the position (0, 0). The next record is saved in the position (0, 1). If the position reaches the last row, which means that the position is (0, 12), the next record is saved in the position (1, 0).

If the position reaches the position (2047, 12), the next record is saved in the position (0, 0). That means the new record replaces the old record.

The getRecordingStatus() method reads the status of the recording mode from the device. This method returns a Promise object.

If the status of the recording mode is fetched successfully, a hash object containing the status will be passed to the resolve() function. The hash object has the properties as follows:

PropertyTypeDescription
beaconModeIntegerBeacon Mode. The value is 0, 1, 2, 3, 4, 5, 7, or 8.
isRecordingBooleanIf the device is in the recording mode, the value is true. Otherwise, it is false.
pageIntegerLatest page number. The value is in the range of 0 to 2047.
rowIntegerLatest row number. The value is in the range of 0 to 12.
measurementIntervalIntegerMeasurement interval. The unit is second. The value is in the range of 1 to 3600.
unixTimeIntegerCreated time of the latest page. The value is a UNIX time. The unit is second. If The recording mode is disabled, this value is set to 0.

As you can see the table above, you can know all information related to the recording mode using this method.

device.getRecordingStatus().then((data) => {
  console.log(JSON.stringify(data, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "beaconMode": 0,
  "isRecording": false,
  "page": 0,
  "row": 0,
  "measurementInterval": 3,
  "unixTime": 0
}

startRecording() method

The startRecording() method starts the recording mode. This method returns a Promise object.

If the recording mode has already been started, this method does nothing and calls the resolve() function.

The OMRON Environment Sensor (2JCIE-BL01) allows us to enable the recording mode only if the beacon mode is 0, 1, 7, or 8. If the beacon mode is 2, 3, 4, 5, this method changes the beacon mode to 8 automatically.

device.startRecording().then(() => {
  console.log('OK');
}).catch((error) => {
  console.error(error);
});

stopRecording() method

The stopRecording() method stops the recording mode. This method returns a Promise object.

If the recording mode has already been stopped, this method does nothing and calls the resolve() function.

device.stopRecording().then(() => {
  console.log('OK');
}).catch((error) => {
  console.error(error);
});

getRecordedDataList() method

The getRecordedDataList() method fetches the records saved in the specified page in the flash memory. This method returns a Promise object.

This method takes a hash object as an argument containing properties as follows:

PropertyTypeRequiredDescription
pageIntegerOptionalPage number that you want to read. The value must be in the range of 0 to 2047.

If the page is not specified, the latest page is applied. Note that this method rejects if the recording mode has not been started.

If the records are fetched successfully, a hash object will be passed to the resolve() function. The hash object has the properties as follows:

PropertyTypeDescription
pageIntegerPage number in which this method read the records.
measurementIntervalIntegerMeasurement interval. The unit is second. The value is in the range of 1 to 3600.
dataListArrayList of the records saved in the page. At most 13 records are contained in the list.
device.getRecordedDataList({ page: 2 }).then((data) => {
  console.log(JSON.stringify(data, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "page": 2,
  "measurementInterval": 3,
  "dataList": [
    {
      "row": 0,
      "temperature": 29.7,
      "humidity": 47.33,
      "ambientLight": 166,
      "uvIndex": 0.02,
      "pressure": 993.3,
      "soundNoise": 34.3,
      "discomfortIndex": 77.5,
      "heatStroke": 25.05,
      "batteryVoltage": 2851,
      "unixTime": 1527746251,
      "timeStamp": "2018-05-31T14:57:31+09:00"
    },
    ...
  ]
}

The structure of each data in the dataList is as same as the data obtained from the getLatestData() method. See the section "getLatestData() method" for details.

getLatestData() method

The getLatestData() method fetches the latest measured data from the device. This method returns a Promise object.

If the the record is fetched successfully, a hash object will be passed to the resolve() function. The hash object has the properties as follows:

PropertyTypeDescription
rowIntegerThe recording mode has been started, this value means the latest row number in the range of 0 to 12. Otherwise, if the recording mode has not been started and the beacon mode is 0, 1, 7, or 8, this value always 0. Otherwise, this value means the sequence number in the range of 0 to 255.
temperatureFloatTemperature (degC)
humidityFloatRelative Humidity (%RH)
ambientLightFloatAmbient Light (lux)
uvIndexFloatUV Index
pressureFloatBarometric Pressure (hPa)
soundNoiseFloatSound noise (dB)
discomfortIndexFloatDiscomfort Index
heatStrokeFloatHeatstroke risk factor (degC)
batteryVoltageIntegerBattery voltage (mV)
device.getLatestData().then((data) => {
  console.log(JSON.stringify(data, null, '  '));
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "row": 12,
  "temperature": 29.55,
  "humidity": 50.98,
  "ambientLight": 169,
  "uvIndex": 0.02,
  "pressure": 993.4,
  "soundNoise": 40.68,
  "discomfortIndex": 77.85,
  "heatStroke": 25.35,
  "batteryVoltage": 2844
}

startMonitoringData() method

The startMonitoringData() method starts monitoring measured data notifications in real time. This method returns a Promise object.

If it starts monitoring measured data notifications successfully, the onsensordata event handler will be called whenever a notification is received.

device.onsensordata = (data) => {
  console.log(JSON.stringify(data, null, '  '));
};
device.startMonitoringData().then(() => {
  console.log('Started.');
}).catch((error) => {
  console.error(error);
});

The code above will output the result as follows:

{
  "row": 4,
  "temperature": 33.73,
  "humidity": 41.75,
  "ambientLight": 165,
  "uvIndex": 0.02,
  "pressure": 993.1,
  "soundNoise": 35.59,
  "discomfortIndex": 81.59,
  "heatStroke": 27.38,
  "batteryVoltage": 2861
}
...

The structure of the data passed to the onsensordata event handler is as same as the data obtained from the getLatestData() method. See the section "getLatestData() method" for details.

stopMonitoringData() method

The stopMonitoringData() method stops monitoring measured data notifications. This method returns a Promise object.

device.stopMonitoringData().then(() => {
  console.log('Stopped.');
}).catch((error) => {
  console.error(error);
});

onsensordata event handler

The onsensordata event handler will be called whenever a measured data notification is received. See the section "startMonitoringData() method" for details.


Advertisement data

OMRON Environment Sensor (2JCIE-BL01) has 8 types of beacon mode. The beacon mode affects the local name, the device name, the recording mode, and the format of the advertising packet as follows:

Beacon ModeBeacon Mode NameLocal NameDevice NameRecordingADV format
0x00Event Beacon (SCAN RSP)"Env""EnvSensor-BL01"allowed(B)
0x01Standard Beacon"Env""EnvSensor-BL01"allowed(B)
0x02General Broadcaster 1"IM""IM-BL01"not allowed(D)
0x03Limited Broadcaster 1"IM""IM-BL01"not allowed(D)
0x04General Broadcaster 2"EP""EP-BL01"not allowed(E)
0x05Limited Broadcaster 2"EP""EP-BL01"not allowed(E)
0x07Alternate Beacon"Env""EnvSensor-BL01"allowed(A)/(B) Alternate
0x08Event Beacon (ADV)"Env""EnvSensor-BL01"allowed(C)

You can change the beacon mode using the setBasicConfigurations() method as follows:

const Envsensor = require('node-omron-envsensor');
const envsensor = new Envsensor();
let device = null;

envsensor.init().then(() => {
  return envsensor.discover({quick: true});
}).then((device_list) => {
  if(device_list.length === 0) {
    throw new Error('No device was found.');
  }
  device = device_list[0];
  return device.connect();
}).then(() => {
  // Set the beacon mode and the measurement interval
  return device.setBasicConfigurations({
    measurementInterval: 1,
    beaconMode: 7
  });
}).then(() => {
  return device.disconnect();
}).then(() => {
  // Set a callback function called when a packet is received
  envsensor.onadvertisement = (ad) => {
    console.log(JSON.stringify(ad, null, '  '));
  };
  // Start to scan advertising packets from the device
  envsensor.startScan();
}).catch((error) => {
  console.error(error);
});

The sample code above discovers a device, then changes the beacon mode of the found device, then listens to the measured data notifications in real time. The object passed to the onadvertisement event handler consists of the properties as follows:

PropertyTypeDescription
idStringID of the device.
uuidStringUUID of the device. Basically it is as same as the value of the id.
addressStringAddress of the device. Basically it is as same as the value of the id except that the address includes : in the string.
localNameStringLocal name. The value depends on the beacon mode ("Env", "IM", or "EP").
rssiIntegerRSSI.
companyIdStringCompany identifier defined by Bluetooth SIG. If the ADV format is (A), this value is "004c" (Apple, Inc.). Otherwise, this value is "02d5" (OMRON Corporation).
dataObjectAdvertising data. The content depends on the beacon mode. See the following sections for details.

The structures of the data are described in the following sections.

(A) Beacon

Example of the advertisement data:

{
  "id": "ded7723b7199",
  "uuid": "ded7723b7199",
  "address": "de:d7:72:3b:71:99",
  "localName": "Env",
  "rssi": -42,
  "companyId": "004c",
  "data": {
    "type": 2,
    "length": 21,
    "uuid": "0C4C3000-7700-46F4-AA96-D5E974E32A54",
    "major": 17,
    "minor": 2,
    "txPower": 195
  }
}

Structure of the data:

PropertyTypeDescription
typeIntegerBeacon type. This value is always 2 which means "iBeacon".
lengthIntegerByte length of the data. This value is always 21 (0x15).
uuidStringUUID of iBeacon.
majorIntegerIf the device is in the recording mode, this value means the latest page number. Otherwise, this value is 0.
minorIntegerIf the device is in the recording mode, this value means the latest row number. Otherwise, this value is 0.
txPowerIntegerTX Power.

(B) Connection Advertise 1

Example of the advertisement data:

{
  "id": "ded7723b7199",
  "uuid": "ded7723b7199",
  "address": "de:d7:72:3b:71:99",
  "localName": "Env",
  "rssi": -51,
  "companyId": "02d5",
  "data": {
    "page": 2,
    "row": 4,
    "uniqueId": "0540c920",
    "eventFlag": { ... },
    "temperature": 26.59,
    "humidity": 52.38,
    "ambientLight": 47,
    "pressure": 991.7,
    "soundNoise": 35.59,
    "discomfortIndex": 74.14,
    "heatStroke": 22.97,
    "batteryVoltage": 2790
  }
}

Structure of the data:

PropertyTypeDescription
pageIntegerIf the device is in the recording mode, this value means the latest page number. Otherwise, this value is 0.
rowIntegerIf the device is in the recording mode, this value means the latest row number. Otherwise, this value is 0.
uniqueIdStringUnique Identifier.
temperatureFloatTemperature (degC)
humidityFloatRelative Humidity (%RH)
ambientLightFloatAmbient Light (lux)
pressureFloatBarometric Pressure (hPa)
soundNoiseFloatSound noise (dB)
discomfortIndexFloatDiscomfort Index
heatStrokeFloatHeatstroke risk factor (degC)
batteryVoltageIntegerBattery voltage (mV)

(C) Connection Advertise 2 (ADV_IND)

Example of the advertisement data:

{
  "id": "ded7723b7199",
  "uuid": "ded7723b7199",
  "address": "de:d7:72:3b:71:99",
  "localName": "Env",
  "rssi": -41,
  "companyId": "02d5",
  "data": {
    "page": 28,
    "row": 8,
    "uniqueId": "0540c920",
    "eventFlag": { ... }
  }
}

Structure of the data:

PropertyTypeDescription
pageIntegerIf the device is in the recording mode, this value means the latest page number. Otherwise, this value is 0.
rowIntegerIf the device is in the recording mode, this value means the latest row number. Otherwise, this value is 0.
uniqueIdStringUnique Identifier of the device.

(D) Sensor ADV 1 (ADV_IND)

Example of the advertisement data:

{
  "id": "ded7723b7199",
  "uuid": "ded7723b7199",
  "address": "de:d7:72:3b:71:99",
  "localName": "IM",
  "rssi": -40,
  "companyId": "02d5",
  "data": {
    "sequenceNumber": 7,
    "temperature": 27.02,
    "humidity": 52.28,
    "ambientLight": 51,
    "uvIndex": 0.01,
    "pressure": 991.8,
    "soundNoise": 32.77,
    "accelerationX": -988.5,
    "accelerationY": 17.2,
    "accelerationZ": 28.1,
    "discomfortIndex": 74.69,
    "heatStroke": 23.35,
    "batteryVoltage": 2790
  }
}

Structure of the data:

PropertyTypeDescription
sequenceNumberIntegerSequence number. The value is in the range of 0 to 255.
temperatureFloatTemperature (degC)
humidityFloatRelative Humidity (%RH)
ambientLightFloatAmbient Light (lux)
uvIndexFloatUV Index
pressureFloatBarometric Pressure (hPa)
soundNoiseFloatSound noise (dB)
accelerationXFloatAcceleration X (mg)
accelerationYFloatAcceleration Y (mg)
accelerationZFloatAcceleration Z (mg)
discomfortIndexFloatDiscomfort Index
heatStrokeFloatHeatstroke risk factor (degC)
batteryVoltageIntegerBattery voltage (mV)

(E) Sensor ADV 2 (ADV_IND)

Example of the advertisement data:

{
  "id": "ded7723b7199",
  "uuid": "ded7723b7199",
  "address": "de:d7:72:3b:71:99",
  "localName": "EP",
  "rssi": -45,
  "companyId": "02d5",
  "data": {
    "sequenceNumber": 169,
    "temperature": 27.13,
    "humidity": 52.21,
    "ambientLight": 54,
    "uvIndex": 0.01,
    "pressure": 992.1,
    "soundNoise": 34.3,
    "discomfortIndex": 74.83,
    "heatStroke": 23.4,
    "batteryVoltage": 2790
  }
}

Structure of the data:

PropertyTypeDescription
sequenceNumberIntegerSequence number. The value is in the range of 0 to 255.
temperatureFloatTemperature (degC)
humidityFloatRelative Humidity (%RH)
ambientLightFloatAmbient Light (lux)
uvIndexFloatUV Index
pressureFloatBarometric Pressure (hPa)
soundNoiseFloatSound noise (dB)
discomfortIndexFloatDiscomfort Index
heatStrokeFloatHeatstroke risk factor (degC)
batteryVoltageIntegerBattery voltage (mV)

Low level APIs of EnvsensorDevice object

In most cases, with the APIs described in this document, you could achieve what you want to do. If you want to do more sophisticated operations, you can use the low-level APIs implemented in the EnvsensorDevice object.

Using the low-level APIs, you can access most of the BLE characteristic implemented in the OMRON Environment Sensor (2JCIE-BL01) directly. See README_LOW_LEVEL_API.md for details.


Release Note

  • v0.0.1 (2018-06-02)
    • First public release

References


License

The MIT License (MIT)

Copyright (c) 2018 Futomi Hatano

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.