Skip to content

Commit

Permalink
Merge pull request #45 from Sensirion/fix-device-id-in-ble-ad
Browse files Browse the repository at this point in the history
send last 2 bytes of mac as device id
  • Loading branch information
LeonieFierz authored Oct 22, 2024
2 parents 7cb5d93 + e0993f1 commit 165d9d4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Allow to request only the last X samples when doing a data download (implement Requested Samples Characterisitc on Download Service)

### Fixed
- use the last 2 Bytes of Mac Address as Device ID in BLE Advertisment (fixes mismatch of logged id and id appearing in MyAmbience as mentiond in https://github.com/Sensirion/arduino-ble-gadget/issues/44)

## [1.3.2] - 2024-06-19

### Fixed
Expand Down
5 changes: 3 additions & 2 deletions src/AdvertisementHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void AdvertisementHeader::writeSampleType(uint8_t sampleType) {
_writeByte(sampleType, 3);
}

void AdvertisementHeader::writeDeviceId(uint16_t deviceID) {
_write16BitBigEndian(deviceID, 4);
void AdvertisementHeader::writeDeviceId(uint8_t deviceIDHigh, uint8_t deviceIDLow) {
_writeByte(deviceIDHigh, 4);
_writeByte(deviceIDLow, 5);
}
2 changes: 1 addition & 1 deletion src/AdvertisementHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AdvertisementHeader: public ByteArray<ADVERTISEMENT_HEADER_SIZE_BYTES> {
void writeCompanyId(uint16_t companyID);
void writeSensirionAdvertisementType(uint8_t advType);
void writeSampleType(uint8_t sampleType);
void writeDeviceId(uint16_t deviceID);
void writeDeviceId(uint8_t deviceIDHigh, uint8_t deviceIDLow);
};

#endif /* _ADVERTISEMENT_HEADER_H_ */
4 changes: 3 additions & 1 deletion src/DataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ void DataProvider::begin() {
// Use part of MAC address as device id
std::string macAddress = _BLELibrary.getDeviceAddress();
_advertisementHeader.writeDeviceId(
strtol(macAddress.substr(12, 17).c_str(), NULL, 16));
static_cast<uint8_t>(strtol(macAddress.substr(12, 14).c_str(), NULL, 16)),
static_cast<uint8_t>(strtol(macAddress.substr(15, 17).c_str(), NULL, 16))
);

_BLELibrary.setAdvertisingData(_buildAdvertisementData());
_BLELibrary.startAdvertising();
Expand Down

0 comments on commit 165d9d4

Please sign in to comment.