Skip to content

Commit 04530c6

Browse files
committed
Merge pull request #122 from tbowmo/master
Added battery reporting as a sensor value
2 parents 54aafaa + 05b1dc8 commit 04530c6

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

hardware/MySensors/avr/boards.txt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
menu.cpu=Processor
22

3+
######################################
4+
## Sensebender Micro
5+
36
MysensorsMicro.name=Sensebender Micro
47

58
MysensorsMicro.upload.tool=arduino:avrdude
@@ -26,4 +29,29 @@ MysensorsMicro.menu.cpu.8Mhz=Atmega328 8Mhz
2629
MysensorsMicro.menu.cpu.8Mhz.build.f_cpu=8000000L
2730

2831
MysensorsMicro.menu.cpu.1Mhz=Atmega328 1Mhz
29-
MysensorsMicro.menu.cpu.1Mhz.build.f_cpu=1000000L
32+
MysensorsMicro.menu.cpu.1Mhz.build.f_cpu=1000000L
33+
34+
35+
########################################
36+
## Gateway settings
37+
38+
MysensorsGW.name=Sensebender Gateway
39+
MysensorsGW.build.core=arduino:arduino
40+
MysensorsGW.build.variant=GW
41+
MysensorsGW.build.board=AVR_1284
42+
MysensorsGW.build.mcu=atmega1284p
43+
MysensorsGW.build.f_cpu=20000000L
44+
45+
MysensorsGW.upload.tool=arduino:avrdude
46+
MysensorsGW.upload.protocol=arduino
47+
MysensorsGW.upload.maximum_size=123720
48+
MysensorsGW.upload.maximum_data_size=16384
49+
MysensorsGW.upload.speed=115200
50+
51+
MysensorsGW.bootloader.tool=arduino:avrdude
52+
MysensorsGW.bootloader.unlock_bits=0x3F
53+
MysensorsGW.bootloader.lock_bits=0x0F
54+
MysensorsGW.bootloader.low_fuses=0xE2
55+
MysensorsGW.bootloader.high_fuses=0xD2
56+
MysensorsGW.bootloader.extended_fuses=0xFE
57+
MysensorsGW.bootloader.file=DualOptiboot/optiboot_atmega1284.hex

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)