Skip to content

Add join back-off #546

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ bool lastWasTxStart;
uint32_t lastTxStartTime;

void myEventCb(void *pUserData, ev_t ev) {
LMIC_complianceEvent(ev);

eventQueue.putEvent(ev);

if (ev == EV_TXSTART) {
Expand Down
24 changes: 22 additions & 2 deletions src/lmic/lmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ static void stateJustJoined (void) {
LMIC.rejoinCnt = 0;
LMIC.dnConf = LMIC.lastDnConf = LMIC.adrChanged = 0;
LMIC.upRepeatCount = LMIC.upRepeat = 0;
LMIC.globalDutyRate = 0;
#if !defined(DISABLE_MCMD_RXParamSetupReq)
LMIC.dn2Ans = 0;
#endif
Expand Down Expand Up @@ -1719,6 +1720,21 @@ static bit_t processJoinAccept_nojoinframe(void) {
LMIC.opmode &= ~OP_TXRXPEND;
reportEventNoUpdate(EV_JOIN_TXCOMPLETE);
int failed = LMICbandplan_nextJoinState();

if(LMIC.globalDutyRate != 0 && (LMIC.txend - LMIC.globalDutyAvail) < 0) {
LMIC.txend = LMIC.globalDutyAvail;
// Add random delay 10s is arbitrary
LMIC.txend += LMICcore_rndDelay(10);
}

// Adjust dutyrate to respect retransmissions back-off during join
// Duty rate of 2^14 is enought to respect the max 8.7s by 24h (5.7s / 24h)
// Divide the rate by 2 every 4000s respect the limit of 36s during hours 1 to 11
if (LMIC.globalDutyRate < 14 && os_getTime() - LMIC.lastDutyRateBackOff > sec2osticks(4000)) {
LMIC.globalDutyRate++;
LMIC.lastDutyRateBackOff = os_getTime();
}

EV(devCond, DEBUG, (e_.reason = EV::devCond_t::NO_JACC,
e_.eui = MAIN::CDEV->getEui(),
e_.info = LMIC.datarate|DR_PAGE,
Expand Down Expand Up @@ -2164,8 +2180,12 @@ bit_t LMIC_startJoining (void) {
// There should be no TX/RX going on
// ASSERT((LMIC.opmode & (OP_POLL|OP_TXRXPEND)) == 0);
LMIC.opmode &= ~OP_POLL;
// Lift any previous duty limitation
LMIC.globalDutyRate = 0;
// Reset Duty rate limitation to respect retransmission backoff
// (max 28s < 36s during first hour)
LMIC.globalDutyRate = 7;
LMIC.globalDutyAvail = os_getTime();
LMIC.lastDutyRateBackOff = os_getTime();

// Cancel scanning
LMIC.opmode &= ~(OP_SCAN|OP_UNJOIN|OP_REJOIN|OP_LINKDEAD|OP_NEXTCHNL);
// Setup state
Expand Down
2 changes: 2 additions & 0 deletions src/lmic/lmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ struct lmic_t {

u1_t txChnl; // channel for next TX
u1_t globalDutyRate; // max rate: 1/2^k
ostime_t lastDutyRateBackOff;

u1_t upRepeat; // configured up repeat
s1_t adrTxPow; // ADR adjusted TX power
Expand Down Expand Up @@ -715,6 +716,7 @@ enum lmic_compliance_rx_action_e {
LMIC_COMPLIANCE_RX_ACTION_END // exit compliance mode, discard this message
};

void LMIC_complianceEvent(ev_t ev);
lmic_compliance_rx_action_t LMIC_complianceRxMessage(u1_t port, const u1_t *pMessage, size_t nMessage);

// Declare onEvent() function, to make sure any definition will have the
Expand Down
41 changes: 41 additions & 0 deletions src/lmic/lmic_compliance.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,47 @@ lmic_compliance_t LMIC_Compliance;

/*

Name: LMIC_complianceEvent()

Function:
Modify join state during compliance test.

Definition:
void LMIC_complianceEvent(ev_t ev);

Description:
Clients who want to handle the LoRaWAN compliance protocol on
port 224 should call this routine in the event callback.
This function will update the LMIC duty rate to allow the test
to run in a raisonnable time.

Returns:
nothing.

*/


void LMIC_complianceEvent(ev_t ev) {
lmic_compliance_state_t const complianceState = LMIC_Compliance.state;

// only handle event during compliance test.
if(!lmic_compliance_state_IsActive(complianceState))
return;

switch (ev)
{
case EV_JOINING:
case EV_JOIN_TXCOMPLETE:
// Remove duty rate during join test.
LMIC.globalDutyRate = 0;
break;
default:
break;
}
}

/*

Name: LMIC_complianceRxMessage()

Function:
Expand Down