Recognition

Detects the current motion state of the device.

obniz.motion.start(temperature, accel, recognition)

This method initializes the motion module.
You can specify the sensitivity for motion detection using arguments. The sensitivity level ranges from 0.0 to 1.0. Setting it to 0 will cause the module to ignore all movements, consistently resulting in a none state.

Please note that motion detection requires analyzing multiple data points, so it may take a moment before the first response is retrieved.

The motion detection sensitivity is set via the third argument.

// Javascript Example
obniz.motion.onRecognitionUpdate = ((motion, possibility) => {
  console.log(`Motion: ${motion}\nPossibility: ${possibility}`);
});

// Start with 0.7 sensitivity for motion recognition
obniz.motion.start(0, 0, 0.7);

obniz.motion.onRecognitionUpdate

This callback function is triggered whenever a motion detection update is received.

Key Description
motion The currently detected motion state: 'none' or 'moving'.
possibility The confidence level of the detected motion (ranging from 0 to 1).
// Javascript Example
obniz.motion.onRecognitionUpdate = ((motion, possibility) => {
  console.log(`Motion: ${motion}\nPossibility: ${possibility}`);
});

obniz.motion.start(0, 0, 0.7);

obniz.motion.getRecognitionWait()

This method performs a single measurement and retrieves the current value, rather than continuous monitoring. It is an asynchronous function that returns the result once the measurement is complete.

// Javascript Example
const recognition = await obniz.motion.getRecognitionWait();
console.log(`Motion: ${recognition.motion} (${recognition.possibility})`);