Skip to content

Commit 51f92b0

Browse files
author
Hasnain Virk
committed
LoRaWAN: Handling re-joining when already Joined
This is a remedy for the issue #7230. While the device is joining, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned. However, if the device is already joined, we will return LORAWAN_STATUS_ALREADY_CONNECTED.
1 parent 69d8c0b commit 51f92b0

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

features/lorawan/LoRaWANStack.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ lorawan_status_t LoRaWANStack::connect()
155155
return LORAWAN_STATUS_NOT_INITIALIZED;
156156
}
157157

158+
if (_loramac.nwk_joined()) {
159+
return LORAWAN_STATUS_ALREADY_CONNECTED;
160+
}
161+
158162
lorawan_status_t status = _loramac.prepare_join(NULL, MBED_CONF_LORA_OVER_THE_AIR_ACTIVATION);
159163

160164
if (LORAWAN_STATUS_OK != status) {
@@ -170,6 +174,10 @@ lorawan_status_t LoRaWANStack::connect(const lorawan_connect_t &connect)
170174
return LORAWAN_STATUS_NOT_INITIALIZED;
171175
}
172176

177+
if (_loramac.nwk_joined()) {
178+
return LORAWAN_STATUS_ALREADY_CONNECTED;
179+
}
180+
173181
if (!(connect.connect_type == LORAWAN_CONNECTION_OTAA)
174182
&& !(connect.connect_type == LORAWAN_CONNECTION_ABP)) {
175183
return LORAWAN_STATUS_PARAMETER_INVALID;
@@ -1170,7 +1178,7 @@ void LoRaWANStack::process_connecting_state(lorawan_status_t &op_status)
11701178

11711179
if (_ctrl_flags & CONNECTED_FLAG) {
11721180
tr_debug("Already connected");
1173-
op_status = LORAWAN_STATUS_OK;
1181+
op_status = LORAWAN_STATUS_ALREADY_CONNECTED;
11741182
return;
11751183
}
11761184

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,11 @@ lorawan_status_t LoRaMac::send_join_request()
814814
status = prepare_frame(&mac_hdr, &fctrl, 0, NULL, 0);
815815

816816
if (status == LORAWAN_STATUS_OK) {
817-
status = schedule_tx();
817+
if (schedule_tx() == LORAWAN_STATUS_OK) {
818+
status = LORAWAN_STATUS_CONNECT_IN_PROGRESS;
819+
}
818820
} else {
819-
tr_error("Retransmission: error %d", status);
821+
tr_error("Couldn't send a JoinRequest: error %d", status);
820822
}
821823

822824
return status;

features/lorawan/lorawan_types.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ typedef enum lorawan_status {
9898
#if defined(LORAWAN_COMPLIANCE_TEST)
9999
LORAWAN_STATUS_COMPLIANCE_TEST_ON = -1019, /**< Compliance test - is on-going */
100100
#endif
101-
LORAWAN_STATUS_DUTYCYCLE_RESTRICTED = -1020,
102-
LORAWAN_STATUS_NO_CHANNEL_FOUND = -1021,
103-
LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND = -1022,
104-
LORAWAN_STATUS_METADATA_NOT_AVAILABLE = -1023
101+
LORAWAN_STATUS_DUTYCYCLE_RESTRICTED = -1020, /**< Transmission will continue after duty cycle backoff*/
102+
LORAWAN_STATUS_NO_CHANNEL_FOUND = -1021, /**< None of the channels is enabled at the moment*/
103+
LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND = -1022, /**< None of the enabled channels is ready for another TX (duty cycle limited)*/
104+
LORAWAN_STATUS_METADATA_NOT_AVAILABLE = -1023, /**< Meta-data after an RX or TX is stale*/
105+
LORAWAN_STATUS_ALREADY_CONNECTED = -1024 /**< The device has already joined a network*/
105106
} lorawan_status_t;
106107

107108
/** The lorawan_connect_otaa structure.

0 commit comments

Comments
 (0)