CanAirIO Sensors Library  0.7.3
Generic sensor manager, abstratctions and bindings of multiple air sensors libraries
Sensors Class Reference

CanAirIO Sensors Manager main class. More...

#include <Sensors.hpp>

Public Member Functions

void init (u_int pms_type=0, int pms_rx=PMS_RX, int pms_tx=PMS_TX)
 All sensors init. More...
 
void loop ()
 Main sensors loop. All sensors are read here, please call it on main loop.
 
bool readAllSensors ()
 Read all sensors but use only one time or use loop() instead. All sensors are read here. Use it carefully, better use sensors.loop()
 
bool isDataReady ()
 get the sensor status
 
void setSampleTime (int seconds)
 set loop time interval for each sensor sample
 
void setOnDataCallBack (voidCbFn cb)
 Get sensor data. More...
 
void setOnErrorCallBack (errorCbFn cb)
 Optional callback for get the sensors errors. More...
 
void setTemperatureUnit (TEMPUNIT tunit)
 set the temperature type unit More...
 
void setDebugMode (bool enable)
 Optional for increase the debug level. More...
 
bool isUARTSensorConfigured ()
 UART only: check if the UART sensor is registered. More...
 
int getUARTDeviceTypeSelected ()
 UART only: get the UART sensor type. See SENSORS enum. Also getDeviceName() More...
 
uint16_t getPM1 ()
 get PM1.0 ug/m3 value
 
uint16_t getPM25 ()
 get PM2.5 ug/m3 value
 
uint16_t getPM4 ()
 get PM4 ug/m3 value
 
uint16_t getPM10 ()
 get PM10 ug/m3 value
 
uint16_t getCO2 ()
 get CO2 ppm value
 
float getCO2humi ()
 get humidity % value of CO2 sensor device
 
float getCO2temp ()
 get temperature value from the CO2 sensor device
 
float getTemperature ()
 get temperature value from environment sensor
 
float getHumidity ()
 get humidity % value of environment sensor
 
float getPressure ()
 get Pressure value in hPa
 
float getAltitude ()
 get Altitude value in meters
 
float getGas ()
 get Gas resistance value of BMP680 sensor
 
float getNH3 ()
 get NH3 value in ppm
 
float getCO ()
 get CO value in ppm
 
float getNO2 ()
 get NO2 value in ppm
 
void enableGeigerSensor (int gpio)
 Enable Geiger sensor on specific pin. More...
 
uint32_t getGeigerCPM (void)
 get Geiger count. Tics in the last 60secs More...
 
float getGeigerMicroSievertHour (void)
 get Geiger count in uSv/h units More...
 
void setTempOffset (float offset)
 Set temperature offset for all temperature sensors. More...
 
void setCO2AltitudeOffset (float altitude)
 set CO2 altitude offset (m) More...
 
void setSeaLevelPressure (float hpa)
 set the sea level pressure (hPa) More...
 
void setCO2RecalibrationFactor (int ppmValue)
 set CO2 recalibration PPM value (400 to 2000) More...
 
void detectI2COnly (bool enable)
 Forced to enable I2C sensors only. Recommended to use only if you are using a I2C sensor and improve the performance.
 
String getLibraryVersion ()
 returns the CanAirIO Sensorslib version
 
int16_t getLibraryRevision ()
 return the current revision code number
 
bool isSensorRegistered (SENSORS sensor)
 Read and check the sensors status on initialization. More...
 
uint8_t * getSensorsRegistered ()
 get the sensor registry for retrieve the sensor names More...
 
uint8_t getSensorsRegisteredCount ()
 get device sensors detected count
 
String getSensorName (SENSORS sensor)
 get the sensor name More...
 
SensorGroup getSensorGroup (SENSORS sensor)
 get the sensor group type More...
 
uint8_t getUnitsRegisteredCount ()
 get device sensors units detected count
 
bool isUnitRegistered (UNIT unit)
 get the sensor unit status on the registry More...
 
String getUnitName (UNIT unit)
 get the sensor unit name More...
 
String getUnitSymbol (UNIT unit)
 get the sensor unit symbol More...
 
UNIT getNextUnit ()
 get the next sensor unit available More...
 
void resetUnitsRegister ()
 reset the sensor units registry. More...
 
void resetSensorsRegister ()
 reset the sensor registry. More...
 
void resetNextUnit ()
 reset the next sensor unit counter. More...
 
void resetAllVariables ()
 reset all library variables (generic sensors units)
 
float getUnitValue (UNIT unit)
 get the sensor unit value (float) More...
 
void printUnitsRegistered (bool debug=false)
 print the sensor units names available More...
 
void printSensorsRegistered (bool debug=false)
 print the sensor names detected More...
 

Public Attributes

struct sps_values val
 SPS30 values. Only for Sensirion SPS30 sensor.
 
bool devmode
 Debug mode for increase verbose.
 
int sample_time = 10
 Initial sample time for all sensors.
 
float toffset = 0.0
 Temperature offset (for final temp output)
 
float altoffset = 0.0
 Altitud compensation variable.
 
float sealevel = 1013.25
 Sea level pressure (hPa)
 
float hpa = 0.0
 Altitud hpa calculation.
 
SPS30 sps30
 Sensirion library.
 
bool i2conly
 only detect i2c sensors flag
 
AM232X am2320
 AM2320 object (Humidity and temperature)
 
Adafruit_BME280 bme280
 BME280 object (Humidity, Pressure, Altitude and Temperature)
 
Adafruit_BMP280 bmp280
 BMP280 object (Humidity, Pressure, Altitude and Temperature)
 
Adafruit_BME680 bme680
 BME680 object (Humidity, Gas, IAQ, Pressure, Altitude and Temperature)
 
AHTxx aht10
 AHTXX sensors object.
 
Adafruit_SHT31 sht31
 SHT31 object (Humidity and temperature)
 
MHZ19 mhz19
 Mhz19 object sensor.
 
Adafruit_SCD30 scd30
 SCD30 object sensor.
 
CM1106_UART * cm1106
 CM1106 UART main object sensor.
 
CM1106_sensor cm1106sensor
 CM1106 UART main variable.
 
CM1106_ABC abc
 CM1106 UART calibration object.
 
SFE_PARTICLE_SENSOR pmGCJA5
 Panasonic SN-GCJA5 object sensor.
 
S8_UART * s8
 SenseAir S8 CO2 object sensor.
 
S8_sensor s8sensor
 SenseAir S8 CO2 object sensor.
 
SensirionI2CScd4x scd4x
 SCD4x object sensor.
 
SensirionI2CSen5x sen5x
 
PM1006 * pm1006
 IKEA Vindriktn object sensor.
 
DFRobot_GAS_I2C dfrCO
 DFRobot gravity CO object sensor addr 0x78.
 
DFRobot_GAS_I2C dfrNH3
 DFRobot gravity NH3 object sensor addr 0x7A.
 
DFRobot_GAS_I2C dfrNO2
 DFRobot gravity NO2 object sensor add 0x7B.
 
GEIGER * rad
 Geiger CAJOE object sensor.
 

Detailed Description

CanAirIO Sensors Manager main class.

Authors
@hpsaturn and CanAir.IO contributers

Member Function Documentation

◆ enableGeigerSensor()

void Sensors::enableGeigerSensor ( int  gpio)

Enable Geiger sensor on specific pin.

Parameters
gpionumber or pin.

◆ getGeigerCPM()

uint32_t Sensors::getGeigerCPM ( void  )

get Geiger count. Tics in the last 60secs

Returns
CPM

◆ getGeigerMicroSievertHour()

float Sensors::getGeigerMicroSievertHour ( void  )

get Geiger count in uSv/h units

Returns
CPM * J305 conversion factor

◆ getNextUnit()

UNIT Sensors::getNextUnit ( )

get the next sensor unit available

Returns
UNIT enum value.

◆ getSensorGroup()

SensorGroup Sensors::getSensorGroup ( SENSORS  sensor)

get the sensor group type

Parameters
sensor(mandatory) SENSORS enum value.
Returns
Sensor group int with the sensor type.

if the sensor is not in a group, return 0. if the sensor is in a group, return 1 (PM), 2 (CO2), 3 (ENV).

◆ getSensorName()

String Sensors::getSensorName ( SENSORS  sensor)

get the sensor name

Parameters
sensor(mandatory) SENSORS enum value.
Returns
String with the sensor name.

◆ getSensorsRegistered()

uint8_t * Sensors::getSensorsRegistered ( )

get the sensor registry for retrieve the sensor names

Returns
pointer to the sensor registry.

See the Advanced Multivariable example

◆ getUARTDeviceTypeSelected()

int Sensors::getUARTDeviceTypeSelected ( )

UART only: get the UART sensor type. See SENSORS enum. Also getDeviceName()

Returns
SENSORS enum value.

◆ getUnitName()

String Sensors::getUnitName ( UNIT  unit)

get the sensor unit name

Parameters
unit(mandatory) UNIT enum value.
Returns
String with the unit name.

◆ getUnitSymbol()

String Sensors::getUnitSymbol ( UNIT  unit)

get the sensor unit symbol

Parameters
unit(mandatory) UNIT enum value.
Returns
String with the unit symbol.

◆ getUnitValue()

float Sensors::getUnitValue ( UNIT  unit)

get the sensor unit value (float)

Parameters
unit(mandatory) UNIT enum value.
Returns
float value of the each unit (RAW).

Also you can use the specific primitive like getTemperature(), getHumidity(), getGas(), getAltitude(), getPressure()

◆ init()

void Sensors::init ( u_int  pms_type = 0,
int  pms_rx = PMS_RX,
int  pms_tx = PMS_TX 
)

All sensors init.

Parameters
pms_type(optional) UART PMS type, please see DEVICE_TYPE enum.
pms_rx(optional) UART PMS RX pin.
pms_tx(optional) UART PMS TX pin.

◆ isSensorRegistered()

bool Sensors::isSensorRegistered ( SENSORS  sensor)

Read and check the sensors status on initialization.

Parameters
sensor(mandatory) SENSORS enum value.
Returns
True if the sensor is registered, false otherwise.

◆ isUARTSensorConfigured()

bool Sensors::isUARTSensorConfigured ( )

UART only: check if the UART sensor is registered.

Returns
bool true if the UART sensor is registered, false otherwise.

◆ isUnitRegistered()

bool Sensors::isUnitRegistered ( UNIT  unit)

get the sensor unit status on the registry

Returns
True if the sensor unit is available, false otherwise.

See the Advanced Multivariable example

◆ printSensorsRegistered()

void Sensors::printSensorsRegistered ( bool  debug = false)

print the sensor names detected

Parameters
debugoptional boolean to set the debug mode flag.

◆ printUnitsRegistered()

void Sensors::printUnitsRegistered ( bool  debug = false)

print the sensor units names available

Parameters
debugoptional boolean to set the debug mode flag.

◆ resetNextUnit()

void Sensors::resetNextUnit ( )

reset the next sensor unit counter.

This function is useful to reset the counter to review the sensor units again. but it is not necessary to call this function.

◆ resetSensorsRegister()

void Sensors::resetSensorsRegister ( )

reset the sensor registry.

This function is useful to reset the sensors registry after a sensor is removed. It should be called before the initialization of the sensors but it is Not necessary to call this function.

◆ resetUnitsRegister()

void Sensors::resetUnitsRegister ( )

reset the sensor units registry.

This function is useful to reset the units registry after a sensor unit is removed. but it is Not necessary to call this function.

◆ setCO2AltitudeOffset()

void Sensors::setCO2AltitudeOffset ( float  altitude)

set CO2 altitude offset (m)

Parameters
altitude(m).

This method is used to compensate the CO2 value with the altitude. Recommended on high altitude.

◆ setCO2RecalibrationFactor()

void Sensors::setCO2RecalibrationFactor ( int  ppmValue)

set CO2 recalibration PPM value (400 to 2000)

Parameters
ppmValuethe ppm value to set, normally 400.

This method is used to set the CO2 recalibration value, please use it only on outdoor conditions. Please see the documentation of each sensor for more information.

◆ setDebugMode()

void Sensors::setDebugMode ( bool  enable)

Optional for increase the debug level.

Parameters
enabletrue to enable debug mode, false to disable debug mode.

◆ setOnDataCallBack()

void Sensors::setOnDataCallBack ( voidCbFn  cb)

Get sensor data.

Parameters
cb(mandatory) callback function to be called when data is ready.

◆ setOnErrorCallBack()

void Sensors::setOnErrorCallBack ( errorCbFn  cb)

Optional callback for get the sensors errors.

Parameters
cbcallback function to be called when any warnning or error happens.

◆ setSeaLevelPressure()

void Sensors::setSeaLevelPressure ( float  hpa)

set the sea level pressure (hPa)

Parameters
hpa(hPa).

This method is used to set the sea level pressure for some sensors that need it.

◆ setTemperatureUnit()

void Sensors::setTemperatureUnit ( TEMPUNIT  tunit)

set the temperature type unit

Parameters
tunitcelciuse, kelvin or fahrenheit.

◆ setTempOffset()

void Sensors::setTempOffset ( float  offset)

Set temperature offset for all temperature sensors.

Parameters
offsettemperature offset in °C (default 0).

Positive value for offset to be subtracetd to the temperature.


The documentation for this class was generated from the following files: