|
3 | 3 | //
|
4 | 4 | // If A0 is held low while powering on, it will enter testmode, which verifies all on-board peripherals
|
5 | 5 | //
|
6 |
| -// Battery voltage is repported as child sensorId 199, as well as battery percentage (Internal message) |
| 6 | +// Battery voltage is as battery percentage (Internal message), and optionally as a sensor value (See defines below) |
7 | 7 |
|
8 | 8 |
|
9 | 9 | #include <MySensor.h>
|
|
20 | 20 | // Define a static node address, remove if you want auto address assignment
|
21 | 21 | //#define NODE_ADDRESS 3
|
22 | 22 |
|
| 23 | +// Uncomment the line below, to transmit battery voltage as a normal sensor value |
| 24 | +//#define BATT_SENSOR 199 |
| 25 | + |
23 | 26 | #define RELEASE "1.2"
|
24 | 27 |
|
25 | 28 | #define AVERAGES 2
|
@@ -54,6 +57,10 @@ MySensor gw;
|
54 | 57 | MyMessage msgHum(CHILD_ID_HUM, V_HUM);
|
55 | 58 | MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
|
56 | 59 |
|
| 60 | +#ifdef BATT_SENSOR |
| 61 | +MyMessage msgBatt(BATT_SENSOR, V_VOLTAGE); |
| 62 | +#endif |
| 63 | + |
57 | 64 | // Global settings
|
58 | 65 | int measureCount = 0;
|
59 | 66 | int sendBattery = 0;
|
@@ -112,6 +119,10 @@ void setup() {
|
112 | 119 | gw.present(CHILD_ID_TEMP,S_TEMP);
|
113 | 120 | gw.present(CHILD_ID_HUM,S_HUM);
|
114 | 121 |
|
| 122 | +#ifdef BATT_SENSOR |
| 123 | + gw.present(BATT_SENSOR, S_POWER); |
| 124 | +#endif |
| 125 | + |
115 | 126 | isMetric = gw.getConfig().isMetric;
|
116 | 127 | Serial.print(F("isMetric: ")); Serial.println(isMetric);
|
117 | 128 | raHum.clear();
|
@@ -171,18 +182,18 @@ void sendTempHumidityMeasurements(bool force)
|
171 | 182 | float oldAvgTemp = raTemp.getAverage();
|
172 | 183 | float oldAvgHum = raHum.getAverage();
|
173 | 184 |
|
174 |
| - raTemp.addValue(data.celsiusHundredths / 100); |
| 185 | + raTemp.addValue(data.celsiusHundredths); |
175 | 186 | raHum.addValue(data.humidityPercent);
|
176 | 187 |
|
177 |
| - float diffTemp = abs(oldAvgTemp - raTemp.getAverage()); |
| 188 | + float diffTemp = abs(lastTemperature - data.celsiusHundredths/100); |
178 | 189 | float diffHum = abs(oldAvgHum - raHum.getAverage());
|
179 | 190 |
|
180 |
| - Serial.println(diffTemp); |
181 |
| - Serial.println(diffHum); |
| 191 | + Serial.print(F("TempDiff :"));Serial.println(diffTemp); |
| 192 | + Serial.print(F("HumDiff :"));Serial.println(diffHum); |
182 | 193 |
|
183 | 194 | if (isnan(diffTemp)) tx = true;
|
184 |
| - if (diffTemp > 0.2) tx = true; |
185 |
| - if (diffHum > 0.5) tx = true; |
| 195 | + if (diffTemp > 0.3) tx = true; |
| 196 | + if (diffHum >= 0.5) tx = true; |
186 | 197 |
|
187 | 198 | if (tx) {
|
188 | 199 | measureCount = 0;
|
@@ -213,6 +224,11 @@ void sendBattLevel(bool force)
|
213 | 224 | long vcc = readVcc();
|
214 | 225 | if (vcc != lastBattery) {
|
215 | 226 | lastBattery = vcc;
|
| 227 | + |
| 228 | +#ifdef BATT_SENSOR |
| 229 | + gw.send(msgBatt.set(vcc)); |
| 230 | +#endif |
| 231 | + |
216 | 232 | // Calculate percentage
|
217 | 233 |
|
218 | 234 | vcc = vcc - 1900; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at
|
|
0 commit comments