adafruit / DHT-sensor-library

Arduino library for DHT11, DHT22, etc Temperature & Humidity Sensors
https://learn.adafruit.com/dht
MIT License
1.97k stars 1.43k forks source link

Improvement: Add a public getRawData() function #179

Open redbart opened 3 years ago

redbart commented 3 years ago

I am currently doing a project with an ESP32 where I need to store and transmit data over the internet from a DHT22, it would be nice to be able to use the 4-byte raw data from the sensor, as that is a smaller size that unnecessarily storing the floats. I propose a public function that simply allows a programmer to read the raw data of the sensor. Something like:

const byte* getRawData() const { return data; }

The programmer would be responsible for calling read() prior to this (or I suppose it could be integrated into the function and a nullptr returned if it fails).

Adrian-Samoticha commented 1 year ago

I had a similar complaint a few years ago when I was using this library. I was storing the read values in integer format anyway so I needed to convert the floats back to integers. On Arduino boards with no FPU and limited program memory, this may needlessly increase program size, along with decreasing performance and overall being “less elegant”.