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

migrate device from TTN V2 to TTN V3 #22

Merged
merged 11 commits into from
Aug 25, 2021
1 change: 1 addition & 0 deletions examples/Catena4430_Sensor/Catena4430_cMeasurementLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ cMeasurementLoop::fsmDispatch(
newState = State::stRebootForUpdate;
else
newState = State::stSleeping;
this->handleSdTTNv3Migrate();
dhineshkumarmcci marked this conversation as resolved.
Show resolved Hide resolved
dhineshkumarmcci marked this conversation as resolved.
Show resolved Hide resolved
break;

// no SD card....
Expand Down
4 changes: 4 additions & 0 deletions examples/Catena4430_Sensor/Catena4430_cMeasurementLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ class cMeasurementLoop : public McciCatena::cPollableObject
bool handleSdFirmwareUpdate();
bool handleSdFirmwareUpdateCardUp();
bool updateFromSd(const char *sFile, McciCatena::cDownload::DownloadRq_t rq);
void handleSdTTNv3Migrate();
bool handleSdTTNv3MigrateCardUp(const char *sFile);
dhineshkumarmcci marked this conversation as resolved.
Show resolved Hide resolved
bool updateFramAppEui();
void reJoinNetwork();
void sdPowerUp(bool fOn);
void sdPrep();

Expand Down
75 changes: 75 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 @@ -571,4 +575,75 @@ cMeasurementLoop::updateFromSd(
}
}

void
cMeasurementLoop::handleSdTTNv3Migrate(
void
)
{
static const char * const sMigrate = "MIGRATE.V3";
dhineshkumarmcci marked this conversation as resolved.
Show resolved Hide resolved
bool fMigrate;
bool fResult = this->checkSdCard();

if (fResult)
{
fMigrate = this->handleSdTTNv3MigrateCardUp(sMigrate);
}

if (fMigrate)
dhineshkumarmcci marked this conversation as resolved.
Show resolved Hide resolved
{
bool fFramUpdate = this->updateFramAppEui();

if (fFramUpdate)
{
this->reJoinNetwork();
gSD.remove(sMigrate);
gLog.printf(gLog.kInfo, "cFramStorage::kAppEUI: update: success\n");
}
dhineshkumarmcci marked this conversation as resolved.
Show resolved Hide resolved
else
gLog.printf(gLog.kError, "cFramStorage::kAppEUI: not updated\n");
}
}

bool
cMeasurementLoop::handleSdTTNv3MigrateCardUp(
const char *sMigrate
)
{
if (! gSD.exists(sMigrate))
{
if (gLog.isEnabled(gLog.kTrace))
gLog.printf(gLog.kAlways, "%s: not found: %s\n", FUNCTION, sMigrate);
dhineshkumarmcci marked this conversation as resolved.
Show resolved Hide resolved

return false;
}
return true;
}

bool
cMeasurementLoop::updateFramAppEui(
void
)
{
auto const pFram = gCatena.getFram();
uint8_t AppEUI[] = { 1, 0, 0, 0, 0, 0, 0, 0 };
dhineshkumarmcci marked this conversation as resolved.
Show resolved Hide resolved

if (pFram == nullptr)
return false;

pFram->saveField(cFramStorage::kAppEUI, AppEUI);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check error status.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I have planned to check return value, unfortunately API saveField is of datatype void.

In this case, I believe we can use API getField to read the value written in FRAM, and then compare to check for error.

Please advice on this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous.

return true;
}

void
cMeasurementLoop::reJoinNetwork(
dhineshkumarmcci marked this conversation as resolved.
Show resolved Hide resolved
void
)
{
auto const pFram = gCatena.getFram();
pFram->saveField(cFramStorage::kDevAddr, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can return an error. Check return value. As a consequence, rejoinNetwork can return an error.

Copy link
Member Author

@dhineshkumarmcci dhineshkumarmcci Jul 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I have planned to check return value, unfortunately API saveField is of datatype void.

In this case, I believe we can use API getField to read the value written in FRAM, and then compare to check for error.

@terrillmoore Please advice on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I filed a bug report but didn't make the change. No, don't use getField(); the saveField() API is going to change to be bool, and we'll deal with it then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created a pull-request for changes with McciCatena::cFram::saveField() - Catena-Arduino-Platform PR-317


LMIC_unjoin();
LMIC_startJoining();
}

#undef FUNCTION