@@ -723,22 +723,27 @@ int32_t DallasTemperature::calculateTemperature(const uint8_t* deviceAddress,
723
723
// the numeric value of DEVICE_DISCONNECTED_RAW is defined in
724
724
// DallasTemperature.h. It is a large negative number outside the
725
725
// operating range of the device
726
- int32_t DallasTemperature::getTemp (const uint8_t * deviceAddress) {
726
+ int32_t DallasTemperature::getTemp (const uint8_t * deviceAddress, byte retryCount = 0 ) {
727
727
728
728
ScratchPad scratchPad;
729
- if (isConnected (deviceAddress, scratchPad))
730
- return calculateTemperature (deviceAddress, scratchPad);
731
- return DEVICE_DISCONNECTED_RAW;
732
-
729
+
730
+ byte retries = 0 ;
731
+
732
+ while (retries++ <= retryCount) {
733
+ if (isConnected (deviceAddress, scratchPad))
734
+ return calculateTemperature (deviceAddress, scratchPad);
735
+ }
736
+
737
+ return DEVICE_DISCONNECTED_RAW;
733
738
}
734
739
735
740
// returns temperature in degrees C or DEVICE_DISCONNECTED_C if the
736
741
// device's scratch pad cannot be read successfully.
737
742
// the numeric value of DEVICE_DISCONNECTED_C is defined in
738
743
// DallasTemperature.h. It is a large negative number outside the
739
744
// operating range of the device
740
- float DallasTemperature::getTempC (const uint8_t * deviceAddress) {
741
- return rawToCelsius (getTemp (deviceAddress));
745
+ float DallasTemperature::getTempC (const uint8_t * deviceAddress, byte retryCount = 0 ) {
746
+ return rawToCelsius (getTemp (deviceAddress, retryCount ));
742
747
}
743
748
744
749
// returns temperature in degrees F or DEVICE_DISCONNECTED_F if the
0 commit comments