Skip to content

Commit

Permalink
Fix #21: change AppEUI and rejoin
Browse files Browse the repository at this point in the history
  • Loading branch information
dhineshkumarmcci committed Jul 1, 2021
1 parent 70ba2fb commit 8f98697
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/Catena4430_Sensor/Catena4430_cMeasurementLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
65 changes: 65 additions & 0 deletions examples/Catena4430_Sensor/Catena4430_cMeasurementLoop_SDcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Module: Catena4430_cMeasurementLoop_SDcard.cpp

#include <Catena_Download.h>

#include <Catena_Fram.h>

#include <Arduino_LoRaWAN_lmic.h>

#include <SD.h>
#include <mcciadk_baselib.h>

Expand Down Expand Up @@ -363,6 +367,20 @@ cMeasurementLoop::handleSdFirmwareUpdate(
if (fResult)
{
fResult = this->handleSdFirmwareUpdateCardUp();

#if ARDUINO_LMIC_CFG_NETWORK_TTN

This comment has been minimized.

Copy link
@terrillmoore

terrillmoore Jul 2, 2021

Member

There's no need to condition this on TTN. I hate conditional compiles, please don't use them unless absolutely necessary.

This comment has been minimized.

Copy link
@dhineshkumarmcci

dhineshkumarmcci Jul 2, 2021

Author Member

Have removed the condition

bool fMigrate = this->handleSdTTNv3MigrateCardUp();

This comment has been minimized.

Copy link
@terrillmoore

terrillmoore Jul 2, 2021

Member

It is very confusing to put this in the same function as handleSdFirmwareUpdate. Instead, please add a call where handleSdFirmwareupdate() is added. This also allows you to avoid clobbering the result of handleSdFirmwareUpated() with something else irrelevant.

This comment has been minimized.

Copy link
@dhineshkumarmcci

dhineshkumarmcci Jul 2, 2021

Author Member

have made call from where handleSdFirmwareupdate() is being called

case State::stTryToUpdate:
if (this->handleSdFirmwareUpdate())
newState = State::stRebootForUpdate;
else
newState = State::stSleeping;
this->handleSdTTNv3Migrate();
break;


if (fMigrate)
{
bool fFramUpdate = this->updateFramAppEui();

if (fFramUpdate)
this->reJoinNetwork();
else
gLog.printf(gLog.kBug, "cFramStorage::kAppEUI: not updated\n");

This comment has been minimized.

Copy link
@terrillmoore

terrillmoore Jul 2, 2021

Member

this should be gLog.kError, not .kBug.

This comment has been minimized.

Copy link
@dhineshkumarmcci

dhineshkumarmcci Jul 2, 2021

Author Member

have changed to gLog.kError

}
#endif
}
this->sdFinish();
return fResult;
Expand Down Expand Up @@ -571,4 +589,51 @@ cMeasurementLoop::updateFromSd(
}
}

bool
cMeasurementLoop::handleSdTTNv3MigrateCardUp(
void
)
{
static const char * const sMigrate[] = { "MIGRATE.V3" };
bool result;

for (auto s : sMigrate)

This comment has been minimized.

Copy link
@terrillmoore

terrillmoore Jul 2, 2021

Member

This is wrong. It iterates over each character in sMigrate. You don't need a for loop at all.

This comment has been minimized.

Copy link
@dhineshkumarmcci

dhineshkumarmcci Jul 2, 2021

Author Member

have removed the for loop

{
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();

This comment has been minimized.

Copy link
@terrillmoore

terrillmoore Jul 2, 2021

Member

You also need to zero out the devAddr in FRAM. Otherwise if device is reset before the join succeeds, it will forget that it needed to rejoin.

This comment has been minimized.

Copy link
@dhineshkumarmcci

dhineshkumarmcci Jul 2, 2021

Author Member

cleared the devAddr by writing zero

LMIC_startJoining();
}

#undef FUNCTION

0 comments on commit 8f98697

Please sign in to comment.