[SOLVED] GrovePI NodeJS implementation for reading data on demand and not just 'onchange'

Hi

Is it possible to read data from GrovePI sensors on demand in NodeJS, currently I have to watch data using some thing like follows.
which is fine for testing individual sensors but my application requires location based gathering of sensor data i.e. I need to get sensor data based on gps readings and then log those values together with current location. I want to be able to just call something logically similar to the following code i.e. the var SensorReading gets the sensor reading when i call the function and i do not have to continuously watch for sensor readings when i do not need them,
are there any other event options i can use i.e. besides Sensor.on(‘change’,) to achieve this ?

var lightSensor = new LightAnalogSensor(3);
lightSensor.on('change', function (res) {
            console.log('Light onChange value=' + res);
             log(res)
          })
lightSensor.watch(1000)
*  ```


// i need something similar to this
var sensorReading = new LightAnalogSensor(3);

never mind found what i was looking for in the documentation basically
lightSensor.read() instead of lightSensor.watch() solves all my issues.
Sorry for jumping the gun on this and posting before i completely read the documentation.

Hi @rameez.saleem,

That’s no problem. We’ll mark this topic as solved then.

Thank you!

1 Like