Skip to content

Commit dffec69

Browse files
committed
Non-blocking Dallas sensors temperature conversion => lower power usage
1 parent e47e596 commit dffec69

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

libraries/MySensors/examples/DallasTemperatureSensor/DallasTemperatureSensor.ino

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ void setup()
2121
{
2222
// Startup OneWire
2323
sensors.begin();
24+
// requestTemperatures() will not block current thread
25+
sensors.setWaitForConversion(false);
2426

2527
// Startup and initialize MySensors library. Set callback for incoming messages.
2628
gw.begin();
@@ -44,7 +46,12 @@ void loop()
4446
gw.process();
4547

4648
// Fetch temperatures from Dallas sensors
47-
sensors.requestTemperatures();
49+
sensors.requestTemperatures();
50+
51+
// query conversion time and sleep until conversion completed
52+
int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
53+
// sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
54+
gw.sleep(conversionTime);
4855

4956
// Read temperatures and send them to controller
5057
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
@@ -62,6 +69,3 @@ void loop()
6269
}
6370
gw.sleep(SLEEP_TIME);
6471
}
65-
66-
67-

0 commit comments

Comments
 (0)