Skip to content

Commit

Permalink
send last 2 bytes of mac as device id
Browse files Browse the repository at this point in the history
instead of only sending the last byte
this fixes mismatch of logged device id on Serial output
of the ESP and device id which appears in MyAmbience (as mentioned in issue #44
  • Loading branch information
LeonieFierz committed Oct 22, 2024
1 parent 7cb5d93 commit e0993f1
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 e0993f1

Please sign in to comment.