29
29
#include < DallasTemperature.h>
30
30
#include < OneWire.h>
31
31
32
+ #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
33
+
32
34
#define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected
33
35
#define MAX_ATTACHED_DS18B20 16
34
36
unsigned long SLEEP_TIME = 30000 ; // Sleep time between reads (in milliseconds)
35
- OneWire oneWire (ONE_WIRE_BUS);
36
- DallasTemperature sensors (&oneWire);
37
+ OneWire oneWire (ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
38
+ DallasTemperature sensors (&oneWire); // Pass the oneWire reference to Dallas Temperature.
37
39
MySensor gw;
38
40
float lastTemperature[MAX_ATTACHED_DS18B20];
39
41
int numSensors=0 ;
@@ -44,14 +46,14 @@ MyMessage msg(0,V_TEMP);
44
46
45
47
void setup ()
46
48
{
47
- // Startup OneWire
49
+ // Startup up the OneWire library
48
50
sensors.begin ();
49
51
50
52
// Startup and initialize MySensors library. Set callback for incoming messages.
51
- gw.begin ();
53
+ gw.begin ();
52
54
53
55
// Send the sketch version information to the gateway and Controller
54
- gw.sendSketchInfo (" Temperature Sensor" , " 1.0 " );
56
+ gw.sendSketchInfo (" Temperature Sensor" , " 1.1 " );
55
57
56
58
// Fetch the number of attached temperature sensors
57
59
numSensors = sensors.getDeviceCount ();
@@ -78,10 +80,15 @@ void loop()
78
80
float temperature = static_cast <float >(static_cast <int >((gw.getConfig ().isMetric ?sensors.getTempCByIndex (i):sensors.getTempFByIndex (i)) * 10 .)) / 10 .;
79
81
80
82
// Only send data if temperature has changed and no error
81
- if (lastTemperature[i] != temperature && temperature != -127.00 ) {
83
+ #if COMPARE_TEMP == 1
84
+ if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00 ) {
85
+ #else
86
+ if (temperature != -127.00 && temperature != 85.00 ) {
87
+ #endif
82
88
83
89
// Send in the new temperature
84
90
gw.send (msg.setSensor (i).set (temperature,1 ));
91
+ // Save new temperatures for next compare
85
92
lastTemperature[i]=temperature;
86
93
}
87
94
}
0 commit comments