diff --git a/tools/esp8266/config.h b/tools/esp8266/config.h index d33865c1..e6a019f5 100644 --- a/tools/esp8266/config.h +++ b/tools/esp8266/config.h @@ -45,9 +45,6 @@ #define DEF_RF24_CE_PIN 2 #define DEF_RF24_IRQ_PIN 0 -/// default radio ID (the ending 01ULL NEEDS to remain unmodified!) -#define DTU_RADIO_ID ((uint64_t)0x1234567801ULL) - // default NRF24 power, possible values (0 - 3) #define DEF_AMPLIFIERPOWER 1 diff --git a/tools/esp8266/config_override_example.h b/tools/esp8266/config_override_example.h index 304a88f4..5fa73f3d 100644 --- a/tools/esp8266/config_override_example.h +++ b/tools/esp8266/config_override_example.h @@ -24,8 +24,4 @@ #undef DEF_RF24_IRQ_PIN #define DEF_RF24_IRQ_PIN 16 -// default radio ID (the ending 01ULL NEEDS to remain unmodified!) -#undef DTU_RADIO_ID -#define DTU_RADIO_ID ((uint64_t)0x1234567901ULL) - #endif /*__CONFIG_OVERRIDE_H__*/ diff --git a/tools/esp8266/hmRadio.h b/tools/esp8266/hmRadio.h index a41d738b..72cebb58 100644 --- a/tools/esp8266/hmRadio.h +++ b/tools/esp8266/hmRadio.h @@ -54,7 +54,7 @@ const char* const rf24AmpPowerNames[] = {"MIN", "LOW", "HIGH", "MAX"}; //----------------------------------------------------------------------------- // HM Radio class //----------------------------------------------------------------------------- -template +template class HmRadio { public: HmRadio() : mNrf24(CE_PIN, CS_PIN, SPI_SPEED) { @@ -90,6 +90,24 @@ class HmRadio { mBufCtrl = ctrl; mSerialDebug = config->serialDebug; + + uint32_t DTU_SN = 0x87654321; + uint32_t chipID = 0; // will be filled with last 3 bytes of MAC +#ifdef ESP32 + uint64_t MAC = ESP.getEfuseMac(); + chipID = ((MAC >> 8) & 0xFF0000) | ((MAC >> 24) & 0xFF00) | ((MAC >> 40) & 0xFF); +#else + chipID = ESP.getChipId(); +#endif + if(chipID) { + DTU_SN = 0x80000000; // the first digit is an 8 for DTU production year 2022, the rest is filled with the ESP chipID in decimal + for(int i = 0; i < 7; i++) { + DTU_SN |= (chipID % 10) << (i * 4); + chipID /= 10; + } + } + // change the byte order of the DTU serial number and append the required 0x01 at the end + DTU_RADIO_ID = ((uint64_t)(((DTU_SN >> 24) & 0xFF) | ((DTU_SN >> 8) & 0xFF00) | ((DTU_SN << 8) & 0xFF0000) | ((DTU_SN << 24) & 0xFF000000)) << 8) | 0x01; mNrf24.begin(config->pinCe, config->pinCs); mNrf24.setRetries(0, 0); @@ -215,7 +233,7 @@ class HmRadio { memset(mTxBuf, 0, MAX_RF_PAYLOAD_SIZE); mTxBuf[0] = mid; // message id CP_U32_BigEndian(&mTxBuf[1], (invId >> 8)); - CP_U32_BigEndian(&mTxBuf[5], (DTU_ID >> 8)); + CP_U32_BigEndian(&mTxBuf[5], (DTU_RADIO_ID >> 8)); mTxBuf[9] = pid; if(calcCrc) { mTxBuf[10] = Ahoy::crc8(mTxBuf, 10); @@ -327,6 +345,8 @@ class HmRadio { return mRfChLst[mRxChIdx]; } + uint64_t DTU_RADIO_ID; + uint8_t mTxCh; uint8_t mTxChIdx;