upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes
RHUSB Class Reference

UPM API for the Omega RH-USB Temperature and Humidity Sensor. More...

Detailed Description

This module implements support for the Omega RH-USB Temperature and Humidity Sensor Probe. It connects via an integrated USB cable, and is accessed via a serial port. It is suitable for wall or duct mounting.

string defaultDev = "/dev/ttyUSB0";
// if an argument was specified, use it as the device instead
if (argc > 1)
defaultDev = string(argv[1]);
cout << "Using device " << defaultDev << endl;
cout << "Initializing..." << endl;
// Instantiate an RHUSB instance on defaultDev
upm::RHUSB sensor(defaultDev);
// output the firmware ID
cout << "Firmware ID: " << sensor.getFirmwareID() << endl;
cout << endl;
// update and print available values every second
while (shouldRun)
{
// update our values from the sensor
sensor.update();
// we show both C and F for temperature
cout << "Temperature: " << sensor.getTemperature()
<< " C / " << sensor.getTemperature(true) << " F"
<< endl;
cout << "Humidity: " << sensor.getHumidity()
<< " %" << endl;
cout << endl;
sleep(1);
}
cout << "Exiting..." << endl;

Public Member Functions

 RHUSB (std::string device)
 
 ~RHUSB ()
 
void update ()
 
float getTemperature (bool fahrenheit=false)
 
float getHumidity ()
 
std::string getFirmwareID ()
 

Protected Member Functions

bool dataAvailable (unsigned int millis)
 
int writeStr (std::string data)
 
std::string readStr (int len)
 
std::string sendCommand (std::string cmd)
 

Protected Attributes

mraa::Uart m_uart
 

Constructor & Destructor Documentation

RHUSB ( std::string  device)

RHUSB constructor

Parameters
devicePath to the serial device
~RHUSB ( )

RHUSB Destructor

Member Function Documentation

void update ( void  )

Read current values from the sensor and update internal stored values. This method must be called prior to querying any values, such as temperature or humidity.

float getTemperature ( bool  fahrenheit = false)

Get the current temperature. update() must have been called prior to calling this method.

Parameters
fahrenheittrue to return the temperature in degrees fahrenheit, false to return the temperature in degrees celcius. The default is false (degrees Celcius).
Returns
The last temperature reading in Celcius or Fahrenheit
float getHumidity ( void  )

Get the current relative humidity. update() must have been called prior to calling this method.

Returns
The last humidity reading
string getFirmwareID ( )

Get the firmware identification string.

Returns
The firmware identification

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