function to compare floats, should fix #3
This commit is contained in:
parent
6813ec03b9
commit
be6944d831
10
things.ino
10
things.ino
@ -52,6 +52,10 @@ void configModeCallback (WiFiManager *myWiFiManager) {
|
||||
ticker.attach(0.1, toggle_led);
|
||||
}
|
||||
|
||||
bool isEqual(float a, float b, float epsilon=0.001) {
|
||||
return fabs(a - b) <= epsilon * fabs(a);
|
||||
}
|
||||
|
||||
void read_sensor() {
|
||||
// wait at least 2 seconds seconds between measurements
|
||||
unsigned long currentMillis = millis();
|
||||
@ -78,13 +82,13 @@ void read_sensor() {
|
||||
dtostrf(temperature, 1, 2, str_temperature);
|
||||
dtostrf(heatindex, 1, 2, str_heatindex);
|
||||
|
||||
if (humidity != previousHumidity) {
|
||||
if (!isEqual(humidity, previousHumidity)) {
|
||||
client.publish("nodemcu/humidity", str_humidity);
|
||||
}
|
||||
if (temperature != previousTemperature) {
|
||||
if (!isEqual(temperature, previousTemperature)) {
|
||||
client.publish("nodemcu/temperature", str_temperature);
|
||||
}
|
||||
if (heatindex != previousHeatindex) {
|
||||
if (!isEqual(heatindex, previousHeatindex)) {
|
||||
client.publish("nodemcu/heatindex", str_heatindex);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user