From 938ade88232b12e364368e6004e2cf4d31008154 Mon Sep 17 00:00:00 2001 From: Kolbi Date: Wed, 17 Jun 2015 14:33:37 +0200 Subject: [PATCH 1/4] Update DallasTemperatureSensor.ino Small code improvements --- .../DallasTemperatureSensor.ino | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino b/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino index 5ac41b4..0c2878b 100644 --- a/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino +++ b/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino @@ -32,8 +32,8 @@ #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) -OneWire oneWire(ONE_WIRE_BUS); -DallasTemperature sensors(&oneWire); +OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) +DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature. MySensor gw; float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; @@ -44,8 +44,8 @@ MyMessage msg(0,V_TEMP); void setup() { - // Startup OneWire - sensors.begin(); + // Startup up the OneWire library + sensors.begin(); // Startup and initialize MySensors library. Set callback for incoming messages. gw.begin(); @@ -78,10 +78,11 @@ void loop() float temperature = static_cast(static_cast((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error - if (lastTemperature[i] != temperature && temperature != -127.00) { + if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { // Send in the new temperature gw.send(msg.setSensor(i).set(temperature,1)); + // Save new temperatures for next compare lastTemperature[i]=temperature; } } From 8d7d63dfd9322a91bdf743fef6aeff39f78933cc Mon Sep 17 00:00:00 2001 From: Kolbi Date: Wed, 17 Jun 2015 14:34:43 +0200 Subject: [PATCH 2/4] Update DallasTemperatureSensor.ino --- .../DallasTemperatureSensor/DallasTemperatureSensor.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino b/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino index 0c2878b..05da63e 100644 --- a/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino +++ b/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino @@ -33,7 +33,7 @@ #define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) -DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature. +DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. MySensor gw; float lastTemperature[MAX_ATTACHED_DS18B20]; int numSensors=0; @@ -45,10 +45,10 @@ MyMessage msg(0,V_TEMP); void setup() { // Startup up the OneWire library - sensors.begin(); + sensors.begin(); // Startup and initialize MySensors library. Set callback for incoming messages. - gw.begin(); + gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Temperature Sensor", "1.0"); From d90e2d9aac642604f89960845fd4fbca744de72b Mon Sep 17 00:00:00 2001 From: Kolbi Date: Wed, 17 Jun 2015 14:59:37 +0200 Subject: [PATCH 3/4] Update DallasTemperatureSensor.ino Updated version number to 1.1 since minor changes... --- .../DallasTemperatureSensor/DallasTemperatureSensor.ino | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino b/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino index 05da63e..dd74739 100644 --- a/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino +++ b/libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino @@ -29,6 +29,8 @@ #include #include +#define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No + #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected #define MAX_ATTACHED_DS18B20 16 unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) @@ -51,7 +53,7 @@ void setup() gw.begin(); // Send the sketch version information to the gateway and Controller - gw.sendSketchInfo("Temperature Sensor", "1.0"); + gw.sendSketchInfo("Temperature Sensor", "1.1"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); @@ -78,7 +80,11 @@ void loop() float temperature = static_cast(static_cast((gw.getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.; // Only send data if temperature has changed and no error + #if COMPARE_TEMP == 1 if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) { + #else + if (temperature != -127.00 && temperature != 85.00) { + #endif // Send in the new temperature gw.send(msg.setSensor(i).set(temperature,1)); From ed939e7efd3be3bfad8ac72778da844f5962a165 Mon Sep 17 00:00:00 2001 From: Kolbi Date: Wed, 17 Jun 2015 15:42:50 +0200 Subject: [PATCH 4/4] Update BatteryPoweredSensor.ino Made debugging informations (Serial Print) optionally through setting --- .../examples/BatteryPoweredSensor/BatteryPoweredSensor.ino | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/MySensors/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino b/libraries/MySensors/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino index 7dbd93b..40c51da 100644 --- a/libraries/MySensors/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino +++ b/libraries/MySensors/examples/BatteryPoweredSensor/BatteryPoweredSensor.ino @@ -30,6 +30,8 @@ #include #include +#define DEBUG 1 // Debug enables Serial.print 1 = Yes 0 = No + int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point MySensor gw; @@ -50,7 +52,9 @@ void loop() { // get the battery Voltage int sensorValue = analogRead(BATTERY_SENSE_PIN); + #if DEBUG > 0 Serial.println(sensorValue); + #endif // 1M, 470K divider across battery and using internal ADC ref of 1.1V // Sense point is bypassed with 0.1 uF cap to reduce noise at that point @@ -59,6 +63,7 @@ void loop() float batteryV = sensorValue * 0.003363075; int batteryPcnt = sensorValue / 10; + #if DEBUG > 0 Serial.print("Battery Voltage: "); Serial.print(batteryV); Serial.println(" V"); @@ -66,6 +71,7 @@ void loop() Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); + #endif if (oldBatteryPcnt != batteryPcnt) { // Power up radio after sleep