finitespace / BME280

Provides an Arduino library for reading and interpreting Bosch BME280 data over I2C, SPI or Sw SPI.
GNU General Public License v3.0
212 stars 105 forks source link

Unique fingerprint BME280 #98

Open Bolukan opened 6 years ago

Bolukan commented 6 years ago

Expected behavior

I would like to fingerprint each BME280 using the hash of the individual trimming parameters. I need a function that returns a copy of uint8_t m_dig[32].

Actual behavior

Individual trimming parameters are not public.

finitespace commented 6 years ago

Fell free to make a change and submit and pull request! I am not sure this is functionality the library should support, but, it never hurts to have it out there.

Thanks!

On Oct 28, 2018, at 12:56 PM, Bollie notifications@github.com wrote:

Expected behavior

I would like to fingerprint each BME280 using the hash of the individual trimming parameters. I need a function that returns a copy of uint8_t m_dig[32].

Actual behavior

Individual trimming parameter are not public.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Bolukan commented 6 years ago

Took right a shot: Changes

The receiving array has to be supplied by reference. The function returns the reference to this array (so not void, see below an example). Alternative was to return a struct. The advantage would be the parameters (dig_T1 - dig_T3, dig_P1 - dig_P9 and dig_H1 - dig_H6) could be added. But I don't need them now, so I prefer keeping it simple.

Please comment, I am not proud on the long function name, but thought it should be descriptive.

Example use:

uint8_t parameters[32];
CRC32 crc;
uint32_t checksum = CRC32::calculate(bme.compensationParameters(parameters), 32);

Serial.printf("SensorID: 0x%08X\nHash(CRC32) of ", checksum);  
for (int i=0; i<32; i++) Serial.printf("%02X ", parameters[i]);  
Serial.print("\n");

Output:

SensorID: 0x27F4DEF5
Hash(CRC32) of CF 6C AF 65 32 00 54 91 5F D6 D0 0B 66 1D BC FF F9 FF 0C 30 20 D1 88 13 4B 47 01 00 1A 20 03 1E
Bolukan commented 6 years ago

Little bump as your first reaction was so quick.

zoomx commented 5 years ago

I believe that the simplest way is to add this in the library. If I have understand first you have to call the ReadTrim private function and then you have all data in m_dig private array. Then you can have a pointer to this array (so I believe it should be public) and calculate the CRC or calculate the CRC inside the library.

Internetwurm commented 4 years ago

BME280_ID Hello Bolukan,

in the past i discovered this and it really works as suggested by Bosch. https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/Unique-IDs-in-Bosch-Sensors/td-p/6012

This is how you read the unique ID in any BME sensor. As suggested it should work same way for BMP and also the 680 sensor.

Edit: I added example screen for two BME280 sensors. Here is my code for grabbing and building the ID.

uid_regs0[0] = BME0.readRegister(0x83); uid_regs0[1] = BME0.readRegister(0x84); uid_regs0[2] = BME0.readRegister(0x85); uid_regs0[3] = BME0.readRegister(0x86); unique_id0 = ((((uint32_t)uid_regs0[3] + ((uint32_t)uid_regs0[2] << 8)) & 0x7fff) << 16) + (((uint32_t)uid_regs0[1]) << 8)+ (uint32_t)uid_regs0[0]; Serial.print("BME0 ID: "); Serial.println(unique_id0, HEX); Serial.println("");

Bolukan commented 4 years ago

Fantastic. Let’s have this implemented !

Bolukan commented 4 years ago

Implementation: https://github.com/Bolukan/BME280/ Example for use is added

zoomx commented 4 years ago

Example show an error here (IDE 1.8.10 and AVR core 1.8.2) Serial.printf("Unique ID: 0x%08X\n", uniqueID); 'class HardwareSerial' has no member named 'printf'; print doesn't work too no matching function for call to 'print(const char [19], uint32_t&)'

this compile but not tested

  uint32_t uniqueID = bme.UniqueId();
  char buffer[19];
  sprintf("Unique ID: 0x%08X\n", uniqueID);
  Serial.print(buffer);
Bolukan commented 4 years ago

You are right: printf is not available for all Arduino family members. I will use your code to adapt the example. Thanks for testing! For me (using esp8266) it worked: I got different numbers for different BME280's

zoomx commented 4 years ago

I thought it was ESP8266 code, that's the reason I specified the AVR core. Thank you for your unique ID add, it is very useful when you calibrate this sensor so you can easily associate calibration data with sensor as one can do with DS18B20.

Bolukan commented 4 years ago

Example updated (Btw, 19 would be too small)

finitespace commented 3 years ago

Has a pull request been created for this?