Description
The functions *ByIndex() work correctly only when all expected sensors work correctly. If one of sensors becomes faulty (not connected), the resulting gap is filled by the next available sensor. Indexation crashes. The temperature sensors (and data) are mismatched. The last sensor(s) in the chain is falsely presented as faulty. This behavior could cause fatal problem in HVAC, engine control etc. (e.g. Inlet/Outlet Water/Oil/Air Temp …)
The root of the problem I see in the usage of getAddress() function. This function looks for sensors available ad hoc instead of the sensors really installed and defined in technology and assigned by a table.
The problem begins by begin() function which detects available sensors ad hoc. The application can compare the detected number of sensors with expected number only. And probably without *ByAddress() there is no chance to detect which of sensors disappeared.
The replacing of a faulty sensor can bring next difficult problem because the order of reading (indexation) may be different in comparison with the previous state. (I do not know rules for the order of sensor detection/reading).
For above mentioned reasons the use of actual getAddress() and *ByIndex() is very hazardous. The best solution would be to avoid the use of *ByIndex() functions (even to exclude them from the library). Apart from the fact that *ByIndex() are redundant to *ByAddress() functions.
Note: Sensors will be usually placed into a common table which assigns sensors to controlled technology. Position in the table is equal to the index. This indexation is likely “external” controlled by programmer instead of “internal”.
I imagine only one reliable solution:
- Use *ByAddress() functions only (with respecting the Note above).
- The DeviceList (i.e. identification) of expected sensors must be defined in application. The best solution would be to store the DeviceList in PROGMEM for practical reasons (Minimum space of RAM occupied by DeviceList)
- The function begin() should compare identifiers of sensors listed in DeviceList with really existing sensors instead of getting count_dev value.
- Mentioned DeviceList data should be obtained using simple example detecting the sensor identification code. The actual version of getAddress() is good enough to get sensors addresses one after another (but for nothing else).
I guess the price for reliability of sensors identification is acceptable.
I am unexperienced newbie in this forum. Perhaps Miles or Rob could implement presented idea..?