Skip to content

Commit

Permalink
use serial number to determine hash
Browse files Browse the repository at this point in the history
  • Loading branch information
kahrendt committed Oct 25, 2023
1 parent e80bd8e commit 8585e93
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 5 additions & 2 deletions esphome/components/sen5x/sen5x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,12 @@ void SEN5XComponent::setup() {
ESP_LOGD(TAG, "Firmware version %d", this->firmware_version_);

if (this->voc_sensor_ && this->store_baseline_) {
// Hash with compilation time
uint32_t combined_serial = (uint32_t(this->serial_number_[0]) << 24) |
(uint32_t(this->serial_number_[1]) << 16) | (uint32_t(this->serial_number_[2]));
// Hash with compilation time and serial number
// This ensures the baseline storage is cleared after OTA
uint32_t hash = fnv1_hash(App.get_compilation_time());
// Serial numbers are unique to each sensor, so mulitple sensors can be used without conflict
uint32_t hash = fnv1_hash(App.get_compilation_time() + std::to_string(combined_serial));
this->pref_ = global_preferences->make_preference<Sen5xBaselines>(hash, true);

if (this->pref_.load(&this->voc_baselines_storage_)) {
Expand Down
5 changes: 3 additions & 2 deletions esphome/components/sgp30/sgp30.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ void SGP30Component::setup() {
return;
}

// Hash with compilation time
// Hash with compilation time and serial number
// This ensures the baseline storage is cleared after OTA
uint32_t hash = fnv1_hash(App.get_compilation_time());
// Serial numbers are unique to each sensor, so mulitple sensors can be used without conflict
uint32_t hash = fnv1_hash(App.get_compilation_time() + std::to_string(this->serial_number_));
this->pref_ = global_preferences->make_preference<SGP30Baselines>(hash, true);

if (this->pref_.load(&this->baselines_storage_)) {
Expand Down
5 changes: 3 additions & 2 deletions esphome/components/sgp4x/sgp4x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ void SGP4xComponent::setup() {
ESP_LOGD(TAG, "Product version: 0x%0X", uint16_t(this->featureset_ & 0x1FF));

if (this->store_baseline_) {
// Hash with compilation time
// Hash with compilation time and serial number
// This ensures the baseline storage is cleared after OTA
uint32_t hash = fnv1_hash(App.get_compilation_time());
// Serial numbers are unique to each sensor, so mulitple sensors can be used without conflict
uint32_t hash = fnv1_hash(App.get_compilation_time() + std::to_string(this->serial_number_));
this->pref_ = global_preferences->make_preference<SGP4xBaselines>(hash, true);

if (this->pref_.load(&this->voc_baselines_storage_)) {
Expand Down

0 comments on commit 8585e93

Please sign in to comment.