Skip to content

Commit 3836d8a

Browse files
committed
Merge pull request arduino#125 from tbowmo/master
Updated sensebender Micro sketch, for better transmition handling
2 parents b482a8e + 872f694 commit 3836d8a

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

libraries/MySensors/examples/SensebenderMicro/SensebenderMicro.ino

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
// When MEASURE_INTERVAL is 60000 and FORCE_TRANSMIT_INTERVAL is 30, we force a transmission every 30 minutes.
4141
// Between the forced transmissions a tranmission will only occur if the measured value differs from the previous measurement
4242

43+
// HUMI_TRANSMIT_THRESHOLD tells how much the humidity should have changed since last time it was transmitted. Likewise with
44+
// TEMP_TRANSMIT_THRESHOLD for temperature threshold.
45+
#define HUMI_TRANSMIT_THRESHOLD 0.5
46+
#define TEMP_TRANSMIT_THRESHOLD 0.5
47+
4348
// Pin definitions
4449
#define TEST_PIN A0
4550
#define LED_PIN A2
@@ -73,7 +78,6 @@ int lastHumidity = -100;
7378
long lastBattery = -100;
7479

7580
RunningAverage raHum(AVERAGES);
76-
RunningAverage raTemp(AVERAGES);
7781

7882
/****************************************************
7983
*
@@ -109,6 +113,20 @@ void setup() {
109113
gw.begin(NULL,AUTO,false);
110114
#endif
111115

116+
// --- following code will heat up the sensor element, and wait until the temperature is
117+
// within 0.3 degrees celcius of the initial temperature (measured at startup).
118+
// This is to try and burn away residue humidity from manufacturing process.
119+
int temperature = humiditySensor.getCelsiusHundredths();
120+
121+
humiditySensor.setHeater(true);
122+
delay(500);
123+
humiditySensor.setHeater(false);
124+
125+
int t = 0;
126+
do {
127+
t = humiditySensor.getCelsiusHundredths() - temperature;
128+
} while (abs(t) >30);
129+
// ---
112130
digitalWrite(LED_PIN, LOW);
113131

114132
humiditySensor.begin();
@@ -123,10 +141,10 @@ void setup() {
123141
gw.present(BATT_SENSOR, S_POWER);
124142
#endif
125143

144+
126145
isMetric = gw.getConfig().isMetric;
127146
Serial.print(F("isMetric: ")); Serial.println(isMetric);
128147
raHum.clear();
129-
raTemp.clear();
130148
sendTempHumidityMeasurements(false);
131149
sendBattLevel(false);
132150
}
@@ -179,10 +197,8 @@ void sendTempHumidityMeasurements(bool force)
179197
bool tx = force;
180198

181199
si7021_env data = humiditySensor.getHumidityAndTemperature();
182-
float oldAvgTemp = raTemp.getAverage();
183200
float oldAvgHum = raHum.getAverage();
184201

185-
raTemp.addValue(data.celsiusHundredths);
186202
raHum.addValue(data.humidityPercent);
187203

188204
float diffTemp = abs(lastTemperature - data.celsiusHundredths/100);
@@ -192,8 +208,8 @@ void sendTempHumidityMeasurements(bool force)
192208
Serial.print(F("HumDiff :"));Serial.println(diffHum);
193209

194210
if (isnan(diffTemp)) tx = true;
195-
if (diffTemp > 0.3) tx = true;
196-
if (diffHum >= 0.5) tx = true;
211+
if (diffTemp > TEMP_TRANSMIT_THRESHOLD) tx = true;
212+
if (diffHum >= HUMI_TRANSMIT_THRESHOLD) tx = true;
197213

198214
if (tx) {
199215
measureCount = 0;

0 commit comments

Comments
 (0)