Is there an elegant way to detect an unplugged sensor using the Dallas Temperature Control library? Multiple calls to getDeviceCount() always return the value from the very first call....subsequent calls do not seem to actually force a recheck. I have been querying each device to see if it answers but it is just a workaround solution and far from ideal. The next step is to mess with the source but I thought I'd put it out there first.
Devices are counted in the begin() statement and thereafter you get a cached value.. SO if you call begin again you get a proper recount
relevant snippet of the lib
// initialize the bus
void DallasTemperature::begin(void)
{
DeviceAddress deviceAddress;
_wire->reset_search();
devices = 0; // Reset the number of devices when we enumerate wire devices
while (_wire->search(deviceAddress))
{
if (validAddress(deviceAddress))
{
if (!parasite && readPowerSupply(deviceAddress)) parasite = true;
// ScratchPad scratchPad;
readScratchPad(deviceAddress, scratchPad);
bitResolution = max(bitResolution, getResolution(deviceAddress));
devices++;
}
}
}
// returns the number of devices found on the bus
uint8_t DallasTemperature::getDeviceCount(void)
{
return devices;
}