Raspberry-pi plugin to easily fetch data from GPIO and i2c sensors
Nodejs C++ plugin, allowing to easily read data from raspberryPi's sensors.
For now, those sensors are supported :
Nodejs, npm and node-gyp are required. This actual version uses the 4.2.1 version of Nodejs, and may or may not be compatible with newer or older versions (but should be with newer versions).
To use i2c sensors, the i2c driver should be loaded, usually using raspi-config. The file (usually
/dev/i2c-1) used to communicate with the bus will be asked during the installation.
If you wish to use GPIO sensors, an existing installation of wiringPi is required. The shared library of wiringPi should be generated, and present in the default location, i.e.
Finally, node-gyp, g++/gcc 4.8.2 and Make are also needed to compile and generate the plugin. You can install node-gyp with npm, and g++/gcc and Make with your favorite package manager.
You should also look at the tests files (located in the test sub directory) and modify the pins and addresses according to your own configuration, using WiringPi own notation form GPIO sensors. If any sensor isn't connected, feel free to comment its initialization.
npm will run the
install.sh script during the installation of the plugin. If all the requierments are met, all should go seamless and be ready to use right after!
Note : this is only for manual installation, npm users are not concerned.
Once everything is installed, simply run :
# To use i2c sensorsnode-gyp configure --gpio=falsenode-gyp build --release# To use i2c and gpio sensorsnode-gyp configurenode-gyp build--release
You should now be able to run the sensor test 'test.js' :
sudo node test/test_i2c.js # Test some i2c sensorssudo node test/test_gpio.js # Test a GPIO sensorsudo node test/test_all.js # Test both GPIO and i2c sensors
If your configuration is correct, you'll see some data from your sensors.
You can also build the plugin using the provided shell script :
Contrary to existing WiringPi binding to Nodejs, we aimed to provide the easiest way to use common GPIO and i2c sensors. First, you'll need to load the plugin :
var RaspiSensors = ;
Creating a sensor object is also pretty straight forward. The only needed informations are the sensor's type, and either its address (for i2c sensors) or its pin address (for GPIO sensors) :
var TSL2561 =type : "TSL2561"address : 0X39"light_sensor"; // An additional name can be provided after the sensor's configuration
Once your sensor is created, you'll be able to asynchronously fetch data from it :
The data will always have this structure :
type: 'Light' // The type of the value of the sensorunit: 'Lux' // The unit usedunit_display: 'Lux' // The displayable unitvalue: 819 // The raw value, exprimed in the specified unitdate: 'Sun Feb 14 2016 15:22:00 GMT+0000 (UTC)' // The js date of the fetchtimestamp: 1455463320449 // The timestamp of the previous datesensor_name: 'light_sensor' // The name of the sensor (so you can use the same callback for multiple sensors)sensor_type: 'TSL2561' // The type of the sensor
You can also bind a callback to fetch data at a provided interval :
BMP180; // Fetch data every 5 seconds
Intervals can be cleaned with the
|Sensor name||Sensor type||Value type|
|PIR Motion Sensor||PIR||Boolean|
|Value type||Value unit||Value unit display|
A working project using this plugin can be found here : https://github.com/Vuzi/MeteoNode
This project provides a web interface to monitor any raspberry pi sensor used, and stores data in a mongoDB database.
Note that, for now, root credentials are needed for any GPIO sensors because wiringPi needs it to access the GPIO bus, and because we need to access the i2c located in
Every library used is the property of their respective owners and/or collaborators.