Merge pull request #125 from tbowmo/master
Updated sensebender Micro sketch, for better transmition handling
This commit is contained in:
@@ -40,6 +40,11 @@
|
||||
// When MEASURE_INTERVAL is 60000 and FORCE_TRANSMIT_INTERVAL is 30, we force a transmission every 30 minutes.
|
||||
// Between the forced transmissions a tranmission will only occur if the measured value differs from the previous measurement
|
||||
|
||||
// HUMI_TRANSMIT_THRESHOLD tells how much the humidity should have changed since last time it was transmitted. Likewise with
|
||||
// TEMP_TRANSMIT_THRESHOLD for temperature threshold.
|
||||
#define HUMI_TRANSMIT_THRESHOLD 0.5
|
||||
#define TEMP_TRANSMIT_THRESHOLD 0.5
|
||||
|
||||
// Pin definitions
|
||||
#define TEST_PIN A0
|
||||
#define LED_PIN A2
|
||||
@@ -73,7 +78,6 @@ int lastHumidity = -100;
|
||||
long lastBattery = -100;
|
||||
|
||||
RunningAverage raHum(AVERAGES);
|
||||
RunningAverage raTemp(AVERAGES);
|
||||
|
||||
/****************************************************
|
||||
*
|
||||
@@ -109,6 +113,20 @@ void setup() {
|
||||
gw.begin(NULL,AUTO,false);
|
||||
#endif
|
||||
|
||||
// --- following code will heat up the sensor element, and wait until the temperature is
|
||||
// within 0.3 degrees celcius of the initial temperature (measured at startup).
|
||||
// This is to try and burn away residue humidity from manufacturing process.
|
||||
int temperature = humiditySensor.getCelsiusHundredths();
|
||||
|
||||
humiditySensor.setHeater(true);
|
||||
delay(500);
|
||||
humiditySensor.setHeater(false);
|
||||
|
||||
int t = 0;
|
||||
do {
|
||||
t = humiditySensor.getCelsiusHundredths() - temperature;
|
||||
} while (abs(t) >30);
|
||||
// ---
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
|
||||
humiditySensor.begin();
|
||||
@@ -123,10 +141,10 @@ void setup() {
|
||||
gw.present(BATT_SENSOR, S_POWER);
|
||||
#endif
|
||||
|
||||
|
||||
isMetric = gw.getConfig().isMetric;
|
||||
Serial.print(F("isMetric: ")); Serial.println(isMetric);
|
||||
raHum.clear();
|
||||
raTemp.clear();
|
||||
sendTempHumidityMeasurements(false);
|
||||
sendBattLevel(false);
|
||||
}
|
||||
@@ -179,10 +197,8 @@ void sendTempHumidityMeasurements(bool force)
|
||||
bool tx = force;
|
||||
|
||||
si7021_env data = humiditySensor.getHumidityAndTemperature();
|
||||
float oldAvgTemp = raTemp.getAverage();
|
||||
float oldAvgHum = raHum.getAverage();
|
||||
|
||||
raTemp.addValue(data.celsiusHundredths);
|
||||
raHum.addValue(data.humidityPercent);
|
||||
|
||||
float diffTemp = abs(lastTemperature - data.celsiusHundredths/100);
|
||||
@@ -192,8 +208,8 @@ void sendTempHumidityMeasurements(bool force)
|
||||
Serial.print(F("HumDiff :"));Serial.println(diffHum);
|
||||
|
||||
if (isnan(diffTemp)) tx = true;
|
||||
if (diffTemp > 0.3) tx = true;
|
||||
if (diffHum >= 0.5) tx = true;
|
||||
if (diffTemp > TEMP_TRANSMIT_THRESHOLD) tx = true;
|
||||
if (diffHum >= HUMI_TRANSMIT_THRESHOLD) tx = true;
|
||||
|
||||
if (tx) {
|
||||
measureCount = 0;
|
||||
|
||||
Reference in New Issue
Block a user