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

send last 2 bytes of mac as device id #45

Merged
merged 1 commit into from
Oct 22, 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
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