1.0.0 • Published 6 years ago

node-usb232-pir v1.0.0

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

node-usb232-pir

npm version Build Status Coverage Status

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

NameTypeDescription
autoReadbooleanAutomatically opens the port and read sensor data. Default is true.
customSerialPortModuleSerialPortCustom serial port module. Check out here.

Events

NamedataDescription
open-Called when the sensor's port is opened and ready for writing.
close-Called when the sensor's port is closed.
data1 or 0Called when the sersor's status changed. If the data returns 1, the target is near from sensor. And 0, the target is far.
errorErrorCalled when the error occurred.

Test

yarn run test

License

This is MIT licensed and all it's dependencies are MIT or BSD licensed.