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

MyCo2 detection fix #8

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use unit64_t for address (device id) instead of std::string
- Fix several clang tidy issues
- Update example to call keepAlive regularly. This ensures scanning does not stop due to errors.
- Fixed detection of 'Sensirion MyCO2' gadgets.

## [0.1.0]
### Added
Expand Down
22 changes: 18 additions & 4 deletions src/Sensirion_upt_ble_auto_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,31 @@ uint16_t SensiScan::getDeviceId(const std::string& data) {
* @brief decode chunk of Advertisement containing encoded samples
*
* @returns 0 on success
* 1 if the Frame is too short or if the SampleType is unknown
* 1 if the SampleType is unknown
* 2 if the received data length is too short for the sample type
*/
uint8_t SensiScan::decodeData(const MetaData& metaData, const std::string& data,
std::vector<Measurement>& samples) {
auto sampleType = static_cast<uint8_t>(data[3]);

DataType dataType = getDataTypeFromSampleType(sampleType);
SampleConfig sampleConfig = sampleConfigSelector[dataType];
std::map<DataType, SampleConfig>::iterator sampleConfigIt = sampleConfigSelector.find(dataType);

if (data.length() < 6 + sampleConfig.sampleSizeBytes) {
return 1; // Frame too short or no config found
if (sampleConfigIt == sampleConfigSelector.end()) {
return 1; // No config found for data type
}

SampleConfig sampleConfig = sampleConfigIt->second;

if (data.length() < 6 + sampleConfig.sampleSizeBytes ) {
/*
NOTE: Here we ignore frames that are too short for T_RH_CO2_ALT data types
because the MyCO2 gadget is actually not sending the 2 reserved Bytes (ALT)
*/
bool is_a_myco2_gadget = metaData.deviceType.bleGadgetType == BLEGadgetType::MYCO2 && data.length() == 6 + sampleConfig.sampleSizeBytes - 2;
if (! is_a_myco2_gadget){
return 2; // Frame too short
}
}

unsigned long timestamp = millis();
Expand Down