From 26d01ab0b643baeefc6996b6efaa05609e713d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=B8rch?= Date: Thu, 14 May 2015 21:12:35 +0200 Subject: [PATCH 1/2] Added GW device to MySensors HW profile (not complete yet!) --- hardware/MySensors/avr/boards.txt | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/hardware/MySensors/avr/boards.txt b/hardware/MySensors/avr/boards.txt index 349cf25..2a3c638 100644 --- a/hardware/MySensors/avr/boards.txt +++ b/hardware/MySensors/avr/boards.txt @@ -1,5 +1,8 @@ menu.cpu=Processor +###################################### +## Sensebender Micro + MysensorsMicro.name=Sensebender Micro MysensorsMicro.upload.tool=arduino:avrdude @@ -26,4 +29,29 @@ MysensorsMicro.menu.cpu.8Mhz=Atmega328 8Mhz MysensorsMicro.menu.cpu.8Mhz.build.f_cpu=8000000L MysensorsMicro.menu.cpu.1Mhz=Atmega328 1Mhz -MysensorsMicro.menu.cpu.1Mhz.build.f_cpu=1000000L \ No newline at end of file +MysensorsMicro.menu.cpu.1Mhz.build.f_cpu=1000000L + + +######################################## +## Gateway settings + +MysensorsGW.name=Sensebender Gateway +MysensorsGW.build.core=arduino:arduino +MysensorsGW.build.variant=GW +MysensorsGW.build.board=AVR_1284 +MysensorsGW.build.mcu=atmega1284p +MysensorsGW.build.f_cpu=20000000L + +MysensorsGW.upload.tool=arduino:avrdude +MysensorsGW.upload.protocol=arduino +MysensorsGW.upload.maximum_size=123720 +MysensorsGW.upload.maximum_data_size=16384 +MysensorsGW.upload.speed=115200 + +MysensorsGW.bootloader.tool=arduino:avrdude +MysensorsGW.bootloader.unlock_bits=0x3F +MysensorsGW.bootloader.lock_bits=0x0F +MysensorsGW.bootloader.low_fuses=0xE2 +MysensorsGW.bootloader.high_fuses=0xD2 +MysensorsGW.bootloader.extended_fuses=0xFE +MysensorsGW.bootloader.file=DualOptiboot/optiboot_atmega1284.hex From 6288c8997ea5fb6a907cf124e9886d66f94ed687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=B8rch?= Date: Sun, 7 Jun 2015 20:49:21 +0200 Subject: [PATCH 2/2] Added possibility to add battery voltage measurements as sensor value (to log battery voltages) --- .../SensebenderMicro/SensebenderMicro.ino | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/libraries/MySensors/examples/SensebenderMicro/SensebenderMicro.ino b/libraries/MySensors/examples/SensebenderMicro/SensebenderMicro.ino index acc92ba..1cb0c7a 100644 --- a/libraries/MySensors/examples/SensebenderMicro/SensebenderMicro.ino +++ b/libraries/MySensors/examples/SensebenderMicro/SensebenderMicro.ino @@ -3,7 +3,7 @@ // // 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 @@ -20,6 +20,9 @@ // Define a static node address, remove if you want auto address assignment //#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 AVERAGES 2 @@ -54,6 +57,10 @@ MySensor gw; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); +#ifdef BATT_SENSOR +MyMessage msgBatt(BATT_SENSOR, V_VOLTAGE); +#endif + // Global settings int measureCount = 0; int sendBattery = 0; @@ -112,6 +119,10 @@ void setup() { gw.present(CHILD_ID_TEMP,S_TEMP); gw.present(CHILD_ID_HUM,S_HUM); +#ifdef BATT_SENSOR + gw.present(BATT_SENSOR, S_POWER); +#endif + isMetric = gw.getConfig().isMetric; Serial.print(F("isMetric: ")); Serial.println(isMetric); raHum.clear(); @@ -171,18 +182,18 @@ void sendTempHumidityMeasurements(bool force) float oldAvgTemp = raTemp.getAverage(); float oldAvgHum = raHum.getAverage(); - raTemp.addValue(data.celsiusHundredths / 100); + raTemp.addValue(data.celsiusHundredths); raHum.addValue(data.humidityPercent); - float diffTemp = abs(oldAvgTemp - raTemp.getAverage()); + float diffTemp = abs(lastTemperature - data.celsiusHundredths/100); float diffHum = abs(oldAvgHum - raHum.getAverage()); - Serial.println(diffTemp); - Serial.println(diffHum); + Serial.print(F("TempDiff :"));Serial.println(diffTemp); + Serial.print(F("HumDiff :"));Serial.println(diffHum); if (isnan(diffTemp)) tx = true; - if (diffTemp > 0.2) tx = true; - if (diffHum > 0.5) tx = true; + if (diffTemp > 0.3) tx = true; + if (diffHum >= 0.5) tx = true; if (tx) { measureCount = 0; @@ -213,6 +224,11 @@ void sendBattLevel(bool force) long vcc = readVcc(); if (vcc != lastBattery) { lastBattery = vcc; + +#ifdef BATT_SENSOR + gw.send(msgBatt.set(vcc)); +#endif + // Calculate percentage vcc = vcc - 1900; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at