Skip to content

Commit d0e47be

Browse files
committed
Add join back-off
Get in transmission limit for join request using the globalDutyRate. The limitation is made without summing time on air during the period to be simple. Limit for hour 1 is 36s, so select duty rate fo 2^7 which limit to 28s Limit between hour 1 and 11 is 36s, divide by 2 the duty rate every 4000s, this limit to 35s Limit after hour 11 is 8.7s/24h duty rate of 2^14 which limit to 5.7s/24.
1 parent 4eb195e commit d0e47be

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/lmic/lmic.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ static void stateJustJoined (void) {
597597
LMIC.rejoinCnt = 0;
598598
LMIC.dnConf = LMIC.lastDnConf = LMIC.adrChanged = 0;
599599
LMIC.upRepeatCount = LMIC.upRepeat = 0;
600+
LMIC.globalDutyRate = 0;
600601
#if !defined(DISABLE_MCMD_RXParamSetupReq)
601602
LMIC.dn2Ans = 0;
602603
#endif
@@ -1709,6 +1710,21 @@ static bit_t processJoinAccept_nojoinframe(void) {
17091710
LMIC.opmode &= ~OP_TXRXPEND;
17101711
reportEventNoUpdate(EV_JOIN_TXCOMPLETE);
17111712
int failed = LMICbandplan_nextJoinState();
1713+
1714+
if((LMIC.txend - LMIC.globalDutyAvail) < 0) {
1715+
LMIC.txend = LMIC.globalDutyAvail;
1716+
// Add random delay 10s is arbitrary
1717+
LMIC.txend += LMICcore_rndDelay(10);
1718+
}
1719+
1720+
// Adjust dutyrate to respect retransmissions back-off during join
1721+
// Duty rate of 2^14 is enought to respect the max 8.7s by 24h (5.7s / 24h)
1722+
// Divide the rate by 2 every 4000s respect the limit of 36s during hours 1 to 11
1723+
if (LMIC.globalDutyRate < 14 && os_getTime() - LMIC.lastDutyRateBackOff > sec2osticks(4000)) {
1724+
LMIC.globalDutyRate++;
1725+
LMIC.lastDutyRateBackOff = os_getTime();
1726+
}
1727+
17121728
EV(devCond, DEBUG, (e_.reason = EV::devCond_t::NO_JACC,
17131729
e_.eui = MAIN::CDEV->getEui(),
17141730
e_.info = LMIC.datarate|DR_PAGE,
@@ -2153,8 +2169,12 @@ bit_t LMIC_startJoining (void) {
21532169
// There should be no TX/RX going on
21542170
// ASSERT((LMIC.opmode & (OP_POLL|OP_TXRXPEND)) == 0);
21552171
LMIC.opmode &= ~OP_POLL;
2156-
// Lift any previous duty limitation
2157-
LMIC.globalDutyRate = 0;
2172+
// Reset Duty rate limitation to respect retransmission backoff
2173+
// (max 28s < 36s during first hour)
2174+
LMIC.globalDutyRate = 7;
2175+
LMIC.globalDutyAvail = os_getTime();
2176+
LMIC.lastDutyRateBackOff = os_getTime();
2177+
21582178
// Cancel scanning
21592179
LMIC.opmode &= ~(OP_SCAN|OP_UNJOIN|OP_REJOIN|OP_LINKDEAD|OP_NEXTCHNL);
21602180
// Setup state

src/lmic/lmic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ struct lmic_t {
569569

570570
u1_t txChnl; // channel for next TX
571571
u1_t globalDutyRate; // max rate: 1/2^k
572+
ostime_t lastDutyRateBackOff;
572573

573574
u1_t upRepeat; // configured up repeat
574575
s1_t adrTxPow; // ADR adjusted TX power

0 commit comments

Comments
 (0)