Skip to content

Commit

Permalink
Merge pull request #8 from Sensirion/my-co2-fix
Browse files Browse the repository at this point in the history
MyCo2 detection fix
  • Loading branch information
qfisch authored Oct 28, 2024
2 parents f1cf4ab + 574fbbc commit 4880fee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
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

0 comments on commit 4880fee

Please sign in to comment.