Skip to content

Commit 6288c89

Browse files
committed
Added possibility to add battery voltage measurements as sensor value (to log battery voltages)
1 parent 26d01ab commit 6288c89

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

libraries/MySensors/examples/SensebenderMicro/SensebenderMicro.ino

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// If A0 is held low while powering on, it will enter testmode, which verifies all on-board peripherals
55
//
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)
77

88

99
#include <MySensor.h>
@@ -20,6 +20,9 @@
2020
// Define a static node address, remove if you want auto address assignment
2121
//#define NODE_ADDRESS 3
2222

23+
// Uncomment the line below, to transmit battery voltage as a normal sensor value
24+
//#define BATT_SENSOR 199
25+
2326
#define RELEASE "1.2"
2427

2528
#define AVERAGES 2
@@ -54,6 +57,10 @@ MySensor gw;
5457
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
5558
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
5659

60+
#ifdef BATT_SENSOR
61+
MyMessage msgBatt(BATT_SENSOR, V_VOLTAGE);
62+
#endif
63+
5764
// Global settings
5865
int measureCount = 0;
5966
int sendBattery = 0;
@@ -112,6 +119,10 @@ void setup() {
112119
gw.present(CHILD_ID_TEMP,S_TEMP);
113120
gw.present(CHILD_ID_HUM,S_HUM);
114121

122+
#ifdef BATT_SENSOR
123+
gw.present(BATT_SENSOR, S_POWER);
124+
#endif
125+
115126
isMetric = gw.getConfig().isMetric;
116127
Serial.print(F("isMetric: ")); Serial.println(isMetric);
117128
raHum.clear();
@@ -171,18 +182,18 @@ void sendTempHumidityMeasurements(bool force)
171182
float oldAvgTemp = raTemp.getAverage();
172183
float oldAvgHum = raHum.getAverage();
173184

174-
raTemp.addValue(data.celsiusHundredths / 100);
185+
raTemp.addValue(data.celsiusHundredths);
175186
raHum.addValue(data.humidityPercent);
176187

177-
float diffTemp = abs(oldAvgTemp - raTemp.getAverage());
188+
float diffTemp = abs(lastTemperature - data.celsiusHundredths/100);
178189
float diffHum = abs(oldAvgHum - raHum.getAverage());
179190

180-
Serial.println(diffTemp);
181-
Serial.println(diffHum);
191+
Serial.print(F("TempDiff :"));Serial.println(diffTemp);
192+
Serial.print(F("HumDiff :"));Serial.println(diffHum);
182193

183194
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;
186197

187198
if (tx) {
188199
measureCount = 0;
@@ -213,6 +224,11 @@ void sendBattLevel(bool force)
213224
long vcc = readVcc();
214225
if (vcc != lastBattery) {
215226
lastBattery = vcc;
227+
228+
#ifdef BATT_SENSOR
229+
gw.send(msgBatt.set(vcc));
230+
#endif
231+
216232
// Calculate percentage
217233

218234
vcc = vcc - 1900; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at

0 commit comments

Comments
 (0)