Code Monkey home page Code Monkey logo

node-sensortag's Introduction

node-sensortag

Gitter

Node.js lib for the TI SensorTag and TI CC2650 SensorTag

Prerequisites

Install

npm install sensortag

Examples

See test.js or sensorTag folder in Tom Igoe's BluetoothLE-Examples repo

Usage

var SensorTag = require('sensortag');

Discover

One

SensorTag.discover(callback(sensorTag));

All

function onDiscover(sensorTag) {
  // ...
}

SensorTag.discoverAll(onDiscover);

SensorTag.stopDiscoverAll(onDiscover);

By id

SensorTag.discoverById(id, callback(sensorTag));

By address

SensorTag.discoverByAddress(address, callback(sensorTag));

Properties:

sensorTag = {
  id: "<peripheral id>",
  type: "cc2540" | "cc2650"
}

Connect and Set Up

sensorTag.connectAndSetUp(callback(error));

Disconnect

sensorTag.disconnect(callback);

Disconnect event

Add listener for when SensorTag is disconnected:

sensorTag.once('disconnect', callback);

Device Info

sensorTag.readDeviceName(callback(error, deviceName));

sensorTag.readSystemId(callback(error, systemId));

sensorTag.readSerialNumber(callback(error, serialNumber));

sensorTag.readFirmwareRevision(callback(error, firmwareRevision));

sensorTag.readHardwareRevision(callback(error, hardwareRevision));

sensorTag.readSoftwareRevision(callback(error, softwareRevision));

sensorTag.readManufacturerName(callback(error, manufacturerName));

IR Temperature Sensor

Enable/disable

sensorTag.enableIrTemperature(callback(error));

sensorTag.disableIrTemperature(callback(error));

sensorTag.setIrTemperaturePeriod(period, callback(error)); // period min 300ms, default period is 1000 ms

Read

sensorTag.readIrTemperature(callback(error, objectTemperature, ambientTemperature));

Notify/Unnotify

sensorTag.notifyIrTemperature(callback(error));

sensorTag.unnotifyIrTemperature(callback(error));

sensorTag.on('irTemperatureChange', callback(objectTemperature, ambientTemperature));

Accelerometer

Enable/disable/configure

sensorTag.enableAccelerometer(callback(error));

sensorTag.disableAccelerometer(callback(error));

// CC2540: period 1 - 2550 ms, default period is 2000 ms
// CC2650: period 100 - 2550 ms, default period is 1000 ms
sensorTag.setAccelerometerPeriod(period, callback(error));

Read

sensorTag.readAccelerometer(callback(error, x, y, z));

Notify/Unnotify

sensorTag.notifyAccelerometer(callback(error));

sensorTag.unnotifyAccelerometer(callback(error));

sensorTag.on('accelerometerChange', callback(x, y, z));

Humidity Sensor

Enable/disable

sensorTag.enableHumidity(callback(error));

sensorTag.disableHumidity(callback(error));

sensorTag.setHumidityPeriod(period, callback(error));

Read

sensorTag.readHumidity(callback(error, temperature, humidity));

Notify/Unnotify

sensorTag.notifyHumidity(callback(error));

sensorTag.unnotifyHumidity(callback(error));

sensorTag.on('humidityChange', callback(temperature, humidity));

Magnetometer

Enable/disable

sensorTag.enableMagnetometer(callback(error));

sensorTag.disableMagnetometer(callback(error));

// CC2540: period 1 - 2550 ms, default period is 2000 ms
// CC2650: period 100 - 2550 ms, default period is 1000 ms
sensorTag.setMagnetometerPeriod(period, callback(error));

Read

sensorTag.readMagnetometer(callback(error, x, y, z));

Notify/Unnotify

sensorTag.notifyMagnetometer(callback(error));

sensorTag.unnotifyMagnetometer(callback(error));

sensorTag.on('magnetometerChange', callback(x, y, z));

Barometric Pressure Sensor

Enable/disable

sensorTag.enableBarometricPressure(callback(error));

sensorTag.disableBarometricPressure(callback(error));

sensorTag.setBarometricPressurePeriod(period, callback(error)); // period 100 - 2550 ms

Read

sensorTag.readBarometricPressure(callback(error, pressure));

Notify/Unnotify

sensorTag.notifyBarometricPressure(callback(error));

sensorTag.unnotifyBarometricPressure(callback(error));

sensorTag.on('barometricPressureChange', callback(pressure));

Gyroscope

Enable/disable/configure

sensorTag.enableGyroscope(callback(error));

sensorTag.disableGyroscope(callback(error));

// period 100 - 2550 ms, default period is 1000 ms
sensorTag.setGyroscopePeriod(period, callback(error));

Read

sensorTag.readGyroscope(callback(error, x, y, z));

Notify/Unnotify

sensorTag.notifyGyroscope(callback(error));

sensorTag.unnotifyGyroscope(callback(error));

sensorTag.on('gyroscopeChange', callback(x, y, z));

IO (CC2650 only)

Data read/write

sensorTag.readIoData(callback(error, value));
sensorTag.writeIoData(value, callback(error));

Config read/write

sensorTag.readIoConfig(callback(error, value));
sensorTag.writeIoConfig(value, callback(error));

Luxometer (CC2650 only)

Enable/disable/configure

sensorTag.enableLuxometer(callback(error));

sensorTag.disableLuxometer(callback(error));

sensorTag.setLuxometerPeriod(period, callback(error));

Read

sensorTag.readLuxometer(callback(error, lux));

Notify/Unnotify

sensorTag.notifyLuxometer(callback(error));

sensorTag.unnotifyLuxometer(callback(error));

sensorTag.on('luxometerChange', callback(lux));

Battery Level (CC2650 only)

Read

sensorTag.readBatteryLevel(callback(error, batteryLevel));

Simple Key

Notify/Unnotify

sensorTag.notifySimpleKey(callback(error));

sensorTag.unnotifySimpleKey(callback(error));

CC2540:

sensorTag.on('simpleKeyChange', callback(left, right));

CC2650:

sensorTag.on('simpleKeyChange', callback(left, right, reedRelay));

node-sensortag's People

Contributors

sandeepmistry avatar hardillb avatar alnikk avatar martin-doyle avatar bchiquet avatar bl4z avatar adrai avatar chrisrichards avatar micahnyc avatar arubenis avatar julianoaffonso avatar muddydixon avatar

Watchers

James Cloos avatar Jelte Lagendijk avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.