Gbertaz / NonBlockingDallas

Arduino library for the DS18B20 temperature sensor. Avoid blocking the sketch while reading the sensor.
MIT License
11 stars 4 forks source link

How to make a fixed relationship between device index and the real device? #15

Open Pepito-design opened 4 months ago

Pepito-design commented 4 months ago

Hi, great work and it works fine ( ESP32 S3 ). I have a bunch of temp sensors on specific places around a engine ( oil, water on different places ). I want to give each sensor a specific (fixed) name ( e.g. oil ) to index mapping ..... should be valid after reboot / power of-on. So I have to save the mapping in EEProm, SD card or LittleFS. But ... index is not always the same for each sensor. So currently it mixed up a little bit.

Question is, what is the easiest way to make that happen? Need some kind of first time learn procedure I think. Thinking about the following:

only ones ( learning phase )
remove all sensors from bus
for each temp sensor
     output sensor position on engine
     connect that sensor to the bus
     map sensor name / position / id  to the device address we have got
     save on EEProm , SD card or LittleFS

For the normal use afterwards:

load the saved data ( name / position /index to device address mapping )
use the saved data, report missing and new devices ( request new learn procedure in that case )

At the moment I'm struggling with that, think I'm not alone ...... :-)

How to make it simple with given functionality ...... at the moment I'm thinking too complex I think ....

oopen commented 4 months ago

Hi,

Yes what you describe is the next step.

We need a mechanism to describe the expected sensors named list, for etch sensor/item minimum elements are :

  1. DeviceAddress or DeviceAddressString (depend on storage format, I suggest using DeviceAddressString)
  2. Human readable name

Storing in this list "sensor index" si not required, and not usefull because this index can change (adding/replacing sensor ...) Using DeviceAddressString or Human-readable-name in place of index.

We need to implement a "learning procedure" & "editing procedure" by using :

I have write the base functions, in prevision for this functionality :

### Apply on real sensors

uint8_t getSensorsCount();
bool validateAddressesRange(DeviceAddress addressesRangeToValidate[], uint8_t numberOfAddresses, bool exclusiveListSet = true);
bool validateAddressesRange(String addressesStrings[], uint8_t numberOfAddresses, bool exclusiveListSet = true);
void mapIndexPositionOfDeviceAddressRange(DeviceAddress addressesRangeToValidate[], uint8_t numberOfAddresses, int8_t mapedPositions[]);

The mapIndexPositionOfDeviceAddressRange() function was written for this purpose.

I have no time for now to write the missing functions to implement a learning & a modification procedure.

But it can't be difficult, the base is done.

See file examples/AdditionalFunctions/AdditionalFunctions.ino it is a draft to test all functions, and show usage of it.

-

Do to want to monitor a car ? a electric generator ?

Pepito-design commented 4 months ago

Hi, thanks, you understand my requirement exactly :-) Thanks Concerning your question, motorbike and electric generator, 2 projects with ESP32 S3. I agree, a learning phase per serial monitor is a good step. Based on that .... everybody can do his own stuff, LCD, WEB, BlueTooth or whatever. House automation may have similar requirements. Thanks again for your excellent solution. :-)