[RN2483] Make OTAA join work async

It does take about 7 seconds to perform OTAA, so make sure we don't have to wait for it to finish now we can do all in async mode.
This commit is contained in:
Gijs Noorlander
2020-02-16 02:02:34 +01:00
parent 24b6364d08
commit 3c5e9389fa
3 changed files with 13 additions and 19 deletions
+1 -1
View File
@@ -221,7 +221,7 @@ bool rn2xx3::init()
// }
// Disabled for now because an OTAA join seems to work fine without.
return _rn2xx3_handler.exec_join(_otaa);
return _rn2xx3_handler.prepare_join(_otaa);
}
bool rn2xx3::initOTAA(const String& AppEUI, const String& AppKey, const String& DevEUI)
@@ -83,25 +83,14 @@ bool rn2xx3_handler::prepare_tx_command(const String& command, const String& dat
return true;
}
bool rn2xx3_handler::exec_join(bool useOTAA) {
if (!command_finished()) {
// What to return here, whether a join is executed, or if the join was successful?
bool rn2xx3_handler::prepare_join(bool useOTAA) {
updateStatus();
if (!prepare_raw_command(useOTAA ? F("mac join otaa") : F("mac join abp"))) {
return false;
}
updateStatus();
if (prepare_raw_command(useOTAA ? F("mac join otaa") : F("mac join abp"))) {
_processing_cmd = Active_cmd::join;
Status.Joined = false;
if (wait_command_finished() == rn2xx3_handler::RN_state::join_accepted)
{
Status.Joined = true;
saveUpdatedStatus();
}
}
return Status.Joined;
_processing_cmd = Active_cmd::join;
Status.Joined = false;
return true;
}
rn2xx3_handler::RN_state rn2xx3_handler::async_loop()
@@ -370,7 +359,12 @@ void rn2xx3_handler::set_state(rn2xx3_handler::RN_state state) {
case RN_state::tx_success:
case RN_state::tx_success_with_rx:
case RN_state::reply_received_finished:
_processing_cmd = Active_cmd::none;
break;
case RN_state::join_accepted:
Status.Joined = true;
saveUpdatedStatus();
_processing_cmd = Active_cmd::none;
break;
@@ -40,7 +40,7 @@ public:
bool shouldEncode,
uint8_t port);
bool exec_join(bool useOTAA);
bool prepare_join(bool useOTAA);
RN_state async_loop();