Vuzi / raspi-sensors

Deprecated - Nodejs C++ plugin, allowing to easily read data from raspberryPi's sensors.
https://www.npmjs.com/package/raspi-sensors
Apache License 2.0
26 stars 3 forks source link

Parsing result data BMP180 #10

Closed survivingwithandroid closed 7 years ago

survivingwithandroid commented 7 years ago

Hello!!

Thanks for your great work! I'm using your library to access to BMP180 sensor in raspberry pi. It works smoothly but i've a small problem. The data returned is like: { type:.. Unit:... (temperature data) } { type:... Unit:... (pressure data) } How can I parse the result and retrieve only the pressure object or the temperature? Using data.value it returns always a couple of results. Can you help me?! Thanks in advance! Best Regards.

Vuzi commented 7 years ago

The returned data should be pretty much like :

{
  type: 'Light',                                    // The type of the value of the sensor
  unit: 'Lux',                                      // The unit used
  unit_display: 'Lux',                              // The displayable unit
  value: 819,                                       // The raw value, exprimed in the specified unit
  date: 'Sun Feb 14 2016 15:22:00 GMT+0000 (UTC)',  // The js date of the fetch
  timestamp: 1455463320449,                         // The timestamp of the previous date
  sensor_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
}

with the value field only containing either the temperature or the pressure (for the BMP180). If you need to known which type of value is currently in your handler, you can test the type of the resul :

   if(data.type === "Temperature") {
     ....
   } else if(data.type === "Humidity") {
     ...
   }
survivingwithandroid commented 7 years ago

Thank you very much!! It works!!