milesburton / Arduino-Temperature-Control-Library

Arduino Temperature Library
https://www.milesburton.com/w/index.php/Dallas_Temperature_Control_Library
969 stars 487 forks source link

What is the exact purpose of the getAddress() function? #196

Closed marclefevre closed 3 years ago

marclefevre commented 3 years ago

I have a bus with 3 DS18B20s on it. Getting temperatures by index gets different sensor's values after reboots so I want to use addresses rather than indices to fetch temperatures. To do this, it seems like I have to discover the address to index relationship and then use getTempCByIndex().

There is a tutorial here that uses getAddress() by passing an index and pointer to an uninitialized DeviceAddress and expects getAddress() to fill in the device address. If this use of getAddress is valid, it would seem that the return value boolean would indicate whether there is a device at that index.

If I copy and paste that example into my ESP8266 code, I find that getDeviceCount() returns 3 but if I call getAddress with indices 0, 1, and 2, the device address I pass does not get changed and the return value is 0.

Issue 166 discusses a similar question but, to me, suggests that the getAddress() function is used to test whether a known device address is present at a given index and should be called with an initialized deviceAddress argument.

Can you clear this up? In other words, what functions should I use to access sensors' values using their device addresses?