Added possibility to add battery voltage measurements as sensor value (to log battery voltages)
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
// If A0 is held low while powering on, it will enter testmode, which verifies all on-board peripherals
|
// If A0 is held low while powering on, it will enter testmode, which verifies all on-board peripherals
|
||||||
//
|
//
|
||||||
// Battery voltage is repported as child sensorId 199, as well as battery percentage (Internal message)
|
// Battery voltage is as battery percentage (Internal message), and optionally as a sensor value (See defines below)
|
||||||
|
|
||||||
|
|
||||||
#include <MySensor.h>
|
#include <MySensor.h>
|
||||||
@@ -20,6 +20,9 @@
|
|||||||
// Define a static node address, remove if you want auto address assignment
|
// Define a static node address, remove if you want auto address assignment
|
||||||
//#define NODE_ADDRESS 3
|
//#define NODE_ADDRESS 3
|
||||||
|
|
||||||
|
// Uncomment the line below, to transmit battery voltage as a normal sensor value
|
||||||
|
//#define BATT_SENSOR 199
|
||||||
|
|
||||||
#define RELEASE "1.2"
|
#define RELEASE "1.2"
|
||||||
|
|
||||||
#define AVERAGES 2
|
#define AVERAGES 2
|
||||||
@@ -54,6 +57,10 @@ MySensor gw;
|
|||||||
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
|
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
|
||||||
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
|
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
|
||||||
|
|
||||||
|
#ifdef BATT_SENSOR
|
||||||
|
MyMessage msgBatt(BATT_SENSOR, V_VOLTAGE);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Global settings
|
// Global settings
|
||||||
int measureCount = 0;
|
int measureCount = 0;
|
||||||
int sendBattery = 0;
|
int sendBattery = 0;
|
||||||
@@ -112,6 +119,10 @@ void setup() {
|
|||||||
gw.present(CHILD_ID_TEMP,S_TEMP);
|
gw.present(CHILD_ID_TEMP,S_TEMP);
|
||||||
gw.present(CHILD_ID_HUM,S_HUM);
|
gw.present(CHILD_ID_HUM,S_HUM);
|
||||||
|
|
||||||
|
#ifdef BATT_SENSOR
|
||||||
|
gw.present(BATT_SENSOR, S_POWER);
|
||||||
|
#endif
|
||||||
|
|
||||||
isMetric = gw.getConfig().isMetric;
|
isMetric = gw.getConfig().isMetric;
|
||||||
Serial.print(F("isMetric: ")); Serial.println(isMetric);
|
Serial.print(F("isMetric: ")); Serial.println(isMetric);
|
||||||
raHum.clear();
|
raHum.clear();
|
||||||
@@ -171,18 +182,18 @@ void sendTempHumidityMeasurements(bool force)
|
|||||||
float oldAvgTemp = raTemp.getAverage();
|
float oldAvgTemp = raTemp.getAverage();
|
||||||
float oldAvgHum = raHum.getAverage();
|
float oldAvgHum = raHum.getAverage();
|
||||||
|
|
||||||
raTemp.addValue(data.celsiusHundredths / 100);
|
raTemp.addValue(data.celsiusHundredths);
|
||||||
raHum.addValue(data.humidityPercent);
|
raHum.addValue(data.humidityPercent);
|
||||||
|
|
||||||
float diffTemp = abs(oldAvgTemp - raTemp.getAverage());
|
float diffTemp = abs(lastTemperature - data.celsiusHundredths/100);
|
||||||
float diffHum = abs(oldAvgHum - raHum.getAverage());
|
float diffHum = abs(oldAvgHum - raHum.getAverage());
|
||||||
|
|
||||||
Serial.println(diffTemp);
|
Serial.print(F("TempDiff :"));Serial.println(diffTemp);
|
||||||
Serial.println(diffHum);
|
Serial.print(F("HumDiff :"));Serial.println(diffHum);
|
||||||
|
|
||||||
if (isnan(diffTemp)) tx = true;
|
if (isnan(diffTemp)) tx = true;
|
||||||
if (diffTemp > 0.2) tx = true;
|
if (diffTemp > 0.3) tx = true;
|
||||||
if (diffHum > 0.5) tx = true;
|
if (diffHum >= 0.5) tx = true;
|
||||||
|
|
||||||
if (tx) {
|
if (tx) {
|
||||||
measureCount = 0;
|
measureCount = 0;
|
||||||
@@ -213,6 +224,11 @@ void sendBattLevel(bool force)
|
|||||||
long vcc = readVcc();
|
long vcc = readVcc();
|
||||||
if (vcc != lastBattery) {
|
if (vcc != lastBattery) {
|
||||||
lastBattery = vcc;
|
lastBattery = vcc;
|
||||||
|
|
||||||
|
#ifdef BATT_SENSOR
|
||||||
|
gw.send(msgBatt.set(vcc));
|
||||||
|
#endif
|
||||||
|
|
||||||
// Calculate percentage
|
// Calculate percentage
|
||||||
|
|
||||||
vcc = vcc - 1900; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at
|
vcc = vcc - 1900; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at
|
||||||
|
|||||||
Reference in New Issue
Block a user