Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Incorporate unique serial number in preference's hash for multiple Sensirion sensors #5479

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]));
kahrendt marked this conversation as resolved.
Show resolved Hide resolved
// 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