-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add intermediate class "SensorNode" Add helper function to fix value ranges Add helper function to calculate absolute humidity Derive DHT22/BME280/DS18B20 from SensorNode Add absolute humidity for DHT22/BME280 to reported values
- Loading branch information
Showing
10 changed files
with
172 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* SensorNode.hpp | ||
* Homie Node for genric sensors. | ||
* Provides a limit method for measurement values | ||
* | ||
* Version: 1.0 | ||
* Author: Lübbe Onken (http://github.com/luebbe) | ||
*/ | ||
|
||
#include "SensorNode.hpp" | ||
|
||
SensorNode::SensorNode(const char *name, const char *type) | ||
: HomieNode(name, type, "sensor") | ||
{ | ||
} | ||
|
||
float SensorNode::computeAbsoluteHumidity(float temperature, float percentHumidity) { | ||
// Calculate the absolute humidity in g/m³ | ||
// https://carnotcycle.wordpress.com/2012/08/04/how-to-convert-relative-humidity-to-absolute-humidity/ | ||
|
||
float absHumidity; | ||
float absTemperature; | ||
absTemperature = temperature + 273.15; | ||
|
||
absHumidity = 6.112; | ||
absHumidity *= exp((17.67 * temperature) / (243.5 + temperature)); | ||
absHumidity *= percentHumidity; | ||
absHumidity *= 2.1674; | ||
absHumidity /= absTemperature; | ||
|
||
return absHumidity; | ||
} | ||
|
||
void SensorNode::fixRange(float *value, float min, float max) | ||
{ | ||
if (isnan(*value)) | ||
{ | ||
return; | ||
} | ||
else if (*value < min) | ||
{ | ||
*value = min; | ||
} | ||
else if (*value > max) | ||
{ | ||
*value = max; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* SensorNode.hpp | ||
* Homie Node for genric sensors. | ||
* Provides a limit method for measurement values | ||
* | ||
* Version: 1.0 | ||
* Author: Lübbe Onken (http://github.com/luebbe) | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <Homie.hpp> | ||
|
||
class SensorNode : public HomieNode | ||
{ | ||
protected: | ||
const float cMinHumid = 0.0; | ||
const float cMaxHumid = 100.0; | ||
static const int MEASUREMENT_INTERVAL = 300; | ||
|
||
float computeAbsoluteHumidity(float temperature, float percentHumidity); | ||
void fixRange(float *value, float min, float max); | ||
|
||
public: | ||
SensorNode(const char *name, const char *type); | ||
}; |
Oops, something went wrong.