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.
Constructor
Section titled “Constructor”Compound(options)
Section titled “Compound(options)”Creates a new Compound object instance.
Compound(options)Parameters
Section titled “Parameters”options
An object of properties used to construct the class.
sensor- The hardware connection definition.
interval(optional) - The sampling interval in milliseconds.
Instance Methods
Section titled “Instance Methods”sample()
Section titled “sample()”Returns a sample object containing sub-objects for each kind of sensor reading.
sample()Return Value
Section titled “Return Value”An object containing one or more sub-objects, each named after the corresponding sensor class (e.g., thermometer, hygrometer).
Examples
Section titled “Examples”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}%`);}