a library for nodeJS to talk to a phidget interface kit
A node.js library for interacting with a Phidget board
Phidget boards are a great prototyping tool which can handle digital inputs and outputs, along with a great array of analog sensors (RFID, temperature, etc). node.js is a fantastic networking library which makes it easy to create fast networked applications. This project aims to make it simple to interact with them both. Synergy!
This project assumes you have the Phidget server up and running. For most "regular" (USB) Phidget boards, that assumes that the computer you have connected to the Phidget board via USB has the server up and running. For stand-alone Phidget micro-computers (phidgetsbc), this assumes you have configured the server via the web portal. You will be connecting to the Phidget server via TCP, so be sure you can access the server from the machine running this project.
This package can interact with multiple phidget boards connected to a single phidgetWebService
npm install phidgets
Phidget makes a line of phidget boards which themselves are small ARM Debian comptuers. It it possble to run node.js on them, and use this package locally. Here's a gist with the steps and a Blog Post about hot to get this up and running.
The Phidgets package exposes a few different ways of interacting with your Phidget board:
var phidgetsPrototype = require'phidgets';var options =host: "phidgetsbc.local"var phidgets = options;// eventsphidgetson'state' console.log"[state] " + state; ;phidgetson'error' console.log"[error] " + error; ;phidgetson'input' console.log"[" + boardId + "][input] " + id + " @ " + value; ;phidgetson'sensor' console.log"[" + boardId + "][sensor] " + id + " @ " + value; ;phidgetson'output' console.log"[" + boardId + "][output] " + id + " @ " + value; ;phidgetsconnectconsole.log'connected to PhidgetBoards:';console.logphidgetsids;
You can also read the state of your board from
phidget.data which will be an object like below:
1234:inputs: '0': 0 '1': 0 '3': 0 '4': 0 '5': 0 '6': 0 '7': 0outputs: '0': 0 '1': 0 '2': 0 '3': 0 '4': 0 '5': 0 '6': 0 '7': 0sensors: '0': 371 '1': 0 '2': 0 '3': 0 '4': 0 '5': 0 '6': 0 '7': 259
The number of inputs, sensors, and outputs will vary depending on your phidget board. DO NOT set the output values via this object, as it won't work.
phidgets.setOutput(boardId, id, value) This method is used to set the digital outputs of the phidget board.
id is a number from 0 to n, and value is
true for on, and
false for off. There will be some lag (~0.5 seconds) when sending the set command to seeing the change reflected via the server and associated node event. This is normal. Keep this in mind, and try not to send
set commands too fast.
If your phidgetWebService is connected to more than 1 board, you will need to provide a boardId. Otherwise, you can send
null, and we will look up the boardId for you.
phidgets.connect can be passed an a JSON object of options. Here are the options and their defaults:
host: "127.0.0.1"port: 5001version: "1.0.10"password: nulldelimiter: '\r\n'readyWaitTimeout: 200
version: version in this case is the version of the phidget server and associated API. You should check your phidget server to learn the version in use. The good news is that the APIs we are using here have not changed for the bast 3 years, and appear to be unlikely to do so in the future. If you run into errors with newer versions, let me know.
- Support for phidget authentication