From 8f98697c28924d05a5e424d2f01ee93271d7006b Mon Sep 17 00:00:00 2001 From: dhineshkumarmcci Date: Fri, 2 Jul 2021 03:58:57 +0530 Subject: [PATCH] Fix #21: change AppEUI and rejoin --- .../Catena4430_cMeasurementLoop.h | 3 + .../Catena4430_cMeasurementLoop_SDcard.cpp | 65 +++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/examples/Catena4430_Sensor/Catena4430_cMeasurementLoop.h b/examples/Catena4430_Sensor/Catena4430_cMeasurementLoop.h index 532a009..aad64e5 100644 --- a/examples/Catena4430_Sensor/Catena4430_cMeasurementLoop.h +++ b/examples/Catena4430_Sensor/Catena4430_cMeasurementLoop.h @@ -382,6 +382,9 @@ class cMeasurementLoop : public McciCatena::cPollableObject bool handleSdFirmwareUpdate(); bool handleSdFirmwareUpdateCardUp(); bool updateFromSd(const char *sFile, McciCatena::cDownload::DownloadRq_t rq); + bool handleSdTTNv3MigrateCardUp(); + bool updateFramAppEui(); + void reJoinNetwork(); void sdPowerUp(bool fOn); void sdPrep(); diff --git a/examples/Catena4430_Sensor/Catena4430_cMeasurementLoop_SDcard.cpp b/examples/Catena4430_Sensor/Catena4430_cMeasurementLoop_SDcard.cpp index a98d4c3..d328808 100644 --- a/examples/Catena4430_Sensor/Catena4430_cMeasurementLoop_SDcard.cpp +++ b/examples/Catena4430_Sensor/Catena4430_cMeasurementLoop_SDcard.cpp @@ -19,6 +19,10 @@ Module: Catena4430_cMeasurementLoop_SDcard.cpp #include +#include + +#include + #include #include @@ -363,6 +367,20 @@ cMeasurementLoop::handleSdFirmwareUpdate( if (fResult) { fResult = this->handleSdFirmwareUpdateCardUp(); + +#if ARDUINO_LMIC_CFG_NETWORK_TTN + bool fMigrate = this->handleSdTTNv3MigrateCardUp(); + + if (fMigrate) + { + bool fFramUpdate = this->updateFramAppEui(); + + if (fFramUpdate) + this->reJoinNetwork(); + else + gLog.printf(gLog.kBug, "cFramStorage::kAppEUI: not updated\n"); + } +#endif } this->sdFinish(); return fResult; @@ -571,4 +589,51 @@ cMeasurementLoop::updateFromSd( } } +bool +cMeasurementLoop::handleSdTTNv3MigrateCardUp( + void + ) + { + static const char * const sMigrate[] = { "MIGRATE.V3" }; + bool result; + + for (auto s : sMigrate) + { + if (! gSD.exists(s)) + { + if (gLog.isEnabled(gLog.kTrace)) + gLog.printf(gLog.kAlways, "%s: not found: %s\n", FUNCTION, s); + + result = false; + return result; + } + result = true; + return result; + } + } + +bool +cMeasurementLoop::updateFramAppEui( + void + ) + { + auto const pFram = gCatena.getFram(); + uint8_t AppEUI[] = { 1, 0, 0, 0, 0, 0, 0, 0 }; + + if (pFram == nullptr) + return false; + + pFram->saveField(cFramStorage::kAppEUI, AppEUI); + return true; + } + +void +cMeasurementLoop::reJoinNetwork( + void + ) + { + LMIC_unjoin(); + LMIC_startJoining(); + } + #undef FUNCTION