...
 
Commits (4)
## v2.3.0 - 2020-05-16
- Added config option to disable battery readings
## v2.2.0 - 2020-05-13
- Added temperature-dependent switch to control a fan or heating
......
......@@ -121,7 +121,7 @@ const translations = {
wateringTimesInfo: 'Zeit in Sekunden pro Kanal, die beim Überschreiten des jeweiligen <em>ADC Treiggerwertes</em> bewässert wird.',
seconds: 'Sekunden',
milliseconds: 'Millisekunden',
ownAddress: 'Eigene adresse',
ownAddress: 'Eigene Adresse',
ownAddressInfo: 'Dies ist die Adresse des Bewässerungssystems im RadioHead-Netzwerk.\nDie Adresse kann in Hexadezimal- oder Dezimalschreibweise angegeben werden.\nBeispiel: <code>0xDC</code> oder <code>220</code>',
pushDataToAddress: 'Sende Daten an Adresse',
pushDataToAddressInfo: 'Zieladresse für automatisch gesendete Daten.\nDie Adresse kann in Hexadezimal- oder Dezimalschreibweise angegeben werden.\nBeispiel: <code>0x01</code> oder <code>1</code>',
......
......@@ -66,6 +66,7 @@ class Watering {
this.softwareVersionControl = require('./package.json').version;
this.logData = [];
this.lastPingData = Buffer.alloc(4);
this.versionInterval = null;
// bind own methods to 'this'
this.apiCheckNow = this.apiCheckNow.bind(this);
......@@ -213,6 +214,11 @@ class Watering {
return;
}
if (this.versionInterval !== null) {
clearInterval(this.versionInterval);
this.versionInterval = null;
}
this.rhs.close()
.then(() => {
this.rhs = null;
......@@ -608,6 +614,7 @@ class Watering {
case RH_MSG_VERSION:
clearInterval(this.versionInterval);
this.versionInterval = null;
this.softwareVersion = `v${msg.data[1]}.${msg.data[2]}.${msg.data[3]}`;
this.log('got software version ' + this.softwareVersion);
break;
......
{
"name": "auto-watering-control",
"version": "2.2.0",
"version": "2.3.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
{
"name": "auto-watering-control",
"version": "2.2.0",
"version": "2.3.0",
"description": "Control tool for the automatic watering system",
"main": "index.js",
"scripts": {
......
......@@ -16,5 +16,5 @@ lib_deps =
DallasTemperature@3.8.1
DHTStable@0.2.4
PinChangeInterrupt@1.2.6
RadioHead@1.82
RadioHead@1.89
SPI
......@@ -77,9 +77,13 @@
#define RH_SEND_TIMEOUT 200
/*
* Battery adc values
* Battery
*/
#define BAT_ADC_LOW 511 // 2,5V
#define BAT_ADC_FULL 859 // 4,2V
// Enable battery readings (1 enabled, 0 disabled)
#define BAT_ENABLED 1
// Battery adc values
#define BAT_ADC_LOW 593 // 2.9V # 1023 * 2.9V / 5V
#define BAT_ADC_FULL 859 // 4.2V # 1023 * 4.2V / 5V
#endif
......@@ -21,7 +21,11 @@ volatile bool channelOn[4];
uint16_t adcValues[4] = {0, 0, 0, 0};
float temperature = -99;
float humidity = -99;
uint16_t batteryRaw;
#if BAT_ENABLED == 1
uint16_t batteryRaw;
#endif
bool tempSwitchOn = false;
float tempSwitchTriggerValueHigh = 32;
float tempSwitchTriggerValueLow = 28;
......
......@@ -20,7 +20,7 @@
// version number of the software
#define SOFTWARE_VERSION_MAJOR 2
#define SOFTWARE_VERSION_MINOR 2
#define SOFTWARE_VERSION_MINOR 3
#define SOFTWARE_VERSION_PATCH 0
// version of the eeporm data model; must be increased if the data model changes
......@@ -73,7 +73,10 @@ extern volatile bool channelOn[4];
extern uint16_t adcValues[4];
extern float temperature;
extern float humidity;
extern uint16_t batteryRaw;
#if BAT_ENABLED == 1
extern uint16_t batteryRaw;
#endif
extern bool tempSwitchOn;
extern float tempSwitchTriggerValueHigh;
......
......@@ -132,8 +132,10 @@ void loop () {
digitalWrite(SENSORS_ACTIVE_PIN, LOW);
// read battery voltage
batteryRaw = analogRead(BATTERY_ADC);
rhSendData(RH_MSG_BATTERY);
#if BAT_ENABLED == 1
batteryRaw = analogRead(BATTERY_ADC);
rhSendData(RH_MSG_BATTERY);
#endif
// disable the adc
ADCSRA &= ~(1<<ADEN);
......
......@@ -197,7 +197,9 @@ void rhRecv () {
// poll with data
switch (rhBufRx[1]) {
case RH_MSG_BATTERY:
rhSendData(RH_MSG_BATTERY, RH_FORCE_SEND, rhRxFrom);
#if BAT_ENABLED == 1
rhSendData(RH_MSG_BATTERY, RH_FORCE_SEND, rhRxFrom);
#endif
break;
case RH_MSG_CHANNEL_STATE:
rhSendData(RH_MSG_CHANNEL_STATE, RH_FORCE_SEND, rhRxFrom);
......@@ -210,14 +212,18 @@ void rhRecv () {
break;
default:
// no known poll request... send all
rhSendData(RH_MSG_BATTERY, RH_FORCE_SEND, rhRxFrom);
#if BAT_ENABLED == 1
rhSendData(RH_MSG_BATTERY, RH_FORCE_SEND, rhRxFrom);
#endif
rhSendData(RH_MSG_CHANNEL_STATE, RH_FORCE_SEND, rhRxFrom);
rhSendData(RH_MSG_TEMP_SENSOR_DATA, RH_FORCE_SEND, rhRxFrom);
rhSendData(RH_MSG_SENSOR_VALUES, RH_FORCE_SEND, rhRxFrom);
}
} else {
// poll without data... send all
rhSendData(RH_MSG_BATTERY, RH_FORCE_SEND, rhRxFrom);
#if BAT_ENABLED == 1
rhSendData(RH_MSG_BATTERY, RH_FORCE_SEND, rhRxFrom);
#endif
rhSendData(RH_MSG_CHANNEL_STATE, RH_FORCE_SEND, rhRxFrom);
rhSendData(RH_MSG_TEMP_SENSOR_DATA, RH_FORCE_SEND, rhRxFrom);
rhSendData(RH_MSG_SENSOR_VALUES, RH_FORCE_SEND, rhRxFrom);
......@@ -324,18 +330,23 @@ bool rhSendData(uint8_t msgType, bool forceSend, uint8_t sendTo, uint16_t delayA
break;
case RH_MSG_BATTERY:
// calc battery percent value
if (batteryRaw <= BAT_ADC_LOW) {
rhBufTx[1] = 0;
} else if (batteryRaw >= BAT_ADC_FULL) {
rhBufTx[1] = 100;
} else {
rhBufTx[1] = 100 * (batteryRaw - BAT_ADC_LOW) / (BAT_ADC_FULL - BAT_ADC_LOW);
}
#if BAT_ENABLED == 1
// calc battery percent value
if (batteryRaw <= BAT_ADC_LOW) {
rhBufTx[1] = 0;
} else if (batteryRaw >= BAT_ADC_FULL) {
rhBufTx[1] = 100;
} else {
rhBufTx[1] = 100 * (batteryRaw - BAT_ADC_LOW) / (BAT_ADC_FULL - BAT_ADC_LOW);
}
// store battery raw value into buffer
memcpy(&rhBufTx[2], &batteryRaw, 2);
len = 4;
// store battery raw value into buffer
memcpy(&rhBufTx[2], &batteryRaw, 2);
len = 4;
#else
// battey not enabled
return true;
#endif
break;
case RH_MSG_VERSION:
......
......@@ -14,5 +14,5 @@
* - DallasTemperature@3.8.1 (https://platformio.org/lib/show/54/DallasTemperature/installation)
* - DHTStable@0.2.4 (https://platformio.org/lib/show/1337/DHTStable/installation)
* - PinChangeInterrupt@1.2.6 (https://platformio.org/lib/show/725/PinChangeInterrupt/installation)
* - RadioHead@1.82 (https://platformio.org/lib/show/124/RadioHead/installation)
* - RadioHead@1.89 (https://platformio.org/lib/show/124/RadioHead/installation)
*/