diff --git a/lib/RN2483-Arduino-Library/src/rn2xx3.cpp b/lib/RN2483-Arduino-Library/src/rn2xx3.cpp index e6c9cdf46..80bd9f7dd 100644 --- a/lib/RN2483-Arduino-Library/src/rn2xx3.cpp +++ b/lib/RN2483-Arduino-Library/src/rn2xx3.cpp @@ -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) diff --git a/lib/RN2483-Arduino-Library/src/rn2xx3_handler.cpp b/lib/RN2483-Arduino-Library/src/rn2xx3_handler.cpp index aed5eaffc..1479ccbd7 100644 --- a/lib/RN2483-Arduino-Library/src/rn2xx3_handler.cpp +++ b/lib/RN2483-Arduino-Library/src/rn2xx3_handler.cpp @@ -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; diff --git a/lib/RN2483-Arduino-Library/src/rn2xx3_handler.h b/lib/RN2483-Arduino-Library/src/rn2xx3_handler.h index 04d1714c2..bc2b1ea67 100644 --- a/lib/RN2483-Arduino-Library/src/rn2xx3_handler.h +++ b/lib/RN2483-Arduino-Library/src/rn2xx3_handler.h @@ -40,7 +40,7 @@ public: bool shouldEncode, uint8_t port); - bool exec_join(bool useOTAA); + bool prepare_join(bool useOTAA); RN_state async_loop();