node-usb232-pir
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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

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.

Package Sidebar

Install

npm i node-usb232-pir

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

16.4 kB

Total Files

7

Last publish

Collaborators

  • doublestat