node-usb232-pir
v1.0.0
Published
A Node.js module for CL-USB232-PIR sensor.
Downloads
10
Maintainers
Readme
node-usb232-pir
A Node.js module for CL-USB232-PIR sensor. This module used node-serialport which is awesome module to help communicate with sensor with serial port.
Installation
yarn add node-usb232-pir
Usage
import PirSensor from 'node-usb232-pir';
const PORT_PATH = 'COM6'; // Sensor serial port path.
const sensor = new PirSensor(PORT_PATH, { autoRead: true });
sensor.on('open', () => console.log('\nPort Opened!\n'));
sensor.on('close', () => console.log('\nPort Closed!\n'));
sensor.on('data', val => console.log('Is target near from sensor? =>', val));
sensor.on('error', err => console.log('Error:', err));
Options
| Name | Type | Description |
|--------------------------|--------------|--------------------------------------------------------------------------------------------------------|
| autoRead
| boolean | Automatically opens the port and read sensor data. Default is true
. |
| customSerialPortModule
| SerialPort
| Custom serial port module. Check out here. |
Events
| Name | data | Description |
|---------|------------|-------------------------------------------------------------------------------------------------------------------------------|
| open
| - | Called when the sensor's port is opened and ready for writing. |
| close
| - | Called when the sensor's port is closed. |
| data
| 1
or 0
| Called when the sersor's status changed. If the data returns 1
, the target is near from sensor. And 0
, the target is far. |
| error
| Error
| Called when the error occurred. |
Test
yarn run test
License
This is MIT licensed and all it's dependencies are MIT or BSD licensed.