Skip to content

Compound Sensor

A single physical sensor may provide more than one kind of sensor reading. For example, a single sensor package may include both a temperature sensor and a humidity sensor. The Compound sensor class provides access to such devices.

Creates a new Compound object instance.

Compound(options)

options

An object of properties used to construct the class.

sensor - The hardware connection definition.

interval (optional) - The sampling interval in milliseconds.

Returns a sample object containing sub-objects for each kind of sensor reading.

sample()

An object containing one or more sub-objects, each named after the corresponding sensor class (e.g., thermometer, hygrometer).

const sensor = new device.sensor.Compound({
sensor: {
io: device.io.I2C,
address: 0x44
}
});
const sample = sensor.sample();
if (sample.thermometer) {
console.log(`Temperature: ${sample.thermometer.temperature} °C`);
}
if (sample.hygrometer) {
console.log(`Humidity: ${sample.hygrometer.humidity}%`);
}

Compound sensors