Skip to content
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

Optionally disable downlinks to save power (Caution: renders device non-compliant) #312

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
**This fork was specifically created for those developpers wanting to build real low-power applications. Unlike the mainstream version and other forks, this version allows us to disable downlinks completely. Calling LMIC_setDownlinks(false) turns downlinks off anytime dynamically, reducing active times down to the minimum necessary to transmit uplink messages. As an example, typical uplink+downlink intervals at SF7 vary around 6-9 seconds. With downlinks deactivated, uplinks only take ~50 msec to complete.**

# Important note

This version of Arduino-lmic does not comply with LoRaWAN™ Specification v1.1 since downlinks should never be disabled.

From LoRaWAN™ Specification v1.1:

> 3.3.6 Important notice on receive windows
> An end-device SHALL NOT transmit another uplink message before it either has received a
> downlink message in the first or second receive window of the previous transmission, or the
> second receive window of the previous transmission is expired.

# Arduino-LMIC library

This repository contains the IBM LMIC (LoRaWAN-MAC-in-C) library, slightly
Expand Down
4 changes: 2 additions & 2 deletions project_config/lmic_project_config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// project-specific definitions
//#define CFG_eu868 1
#define CFG_us915 1
#define CFG_eu868 1
//#define CFG_us915 1
//#define CFG_au915 1
//#define CFG_as923 1
// #define LMIC_COUNTRY_CODE LMIC_COUNTRY_CODE_JP /* for as923-JP */
Expand Down
4 changes: 2 additions & 2 deletions src/lmic/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@
// define this in lmic_project_config.h to disable all code related to joining
//#define DISABLE_JOIN
// define this in lmic_project_config.h to disable all code related to ping
//#define DISABLE_PING
#define DISABLE_PING
// define this in lmic_project_config.h to disable all code related to beacon tracking.
// Requires ping to be disabled too
//#define DISABLE_BEACONS
#define DISABLE_BEACONS

// define these in lmic_project_config.h to disable the corresponding MAC commands.
// Class A
Expand Down
14 changes: 11 additions & 3 deletions src/lmic/lmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1818,8 +1818,8 @@ static void setupRx2DnData (xref2osjob_t osjob) {
static void processRx1DnData (xref2osjob_t osjob) {
LMIC_API_PARAMETER(osjob);

if( LMIC.dataLen == 0 || !processDnData() )
schedRx12(sec2osticks(LMIC.rxDelay +(int)DELAY_EXTDNW2), FUNC_ADDR(setupRx2DnData), LMIC.dn2Dr);
if( LMIC.dataLen == 0 || !processDnData() )
schedRx12(sec2osticks(LMIC.rxDelay +(int)DELAY_EXTDNW2), FUNC_ADDR(setupRx2DnData), LMIC.dn2Dr);
}


Expand All @@ -1833,7 +1833,13 @@ static void setupRx1DnData (xref2osjob_t osjob) {
static void updataDone (xref2osjob_t osjob) {
LMIC_API_PARAMETER(osjob);

txDone(sec2osticks(LMIC.rxDelay), FUNC_ADDR(setupRx1DnData));
if (LMIC.downlinkEnabled == 0)
{
LMIC.opmode &= ~(OP_TXDATA|OP_TXRXPEND);
reportEventAndUpdate(EV_TXCOMPLETE);
}
else
txDone(sec2osticks(LMIC.rxDelay), FUNC_ADDR(setupRx1DnData));
}

// ========================================
Expand Down Expand Up @@ -2817,6 +2823,8 @@ void LMIC_reset (void) {
LMIC.netDeviceTime = 0; // the "invalid" time.
LMIC.netDeviceTimeFrac = 0;
#endif // LMIC_ENABLE_DeviceTimeReq

LMIC.downlinkEnabled = 1;
}


Expand Down
8 changes: 8 additions & 0 deletions src/lmic/lmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,8 @@ struct lmic_t {

u1_t noRXIQinversion;
u1_t saveIrqFlags; // last LoRa IRQ flags

u1_t downlinkEnabled;
};

//! \var struct lmic_t LMIC
Expand Down Expand Up @@ -723,6 +725,12 @@ lmic_compliance_rx_action_t LMIC_complianceRxMessage(u1_t port, const u1_t *pMes
DECL_ON_LMIC_EVENT;
#endif /* LMIC_ENABLE_onEvent */

// Disable downlinks
inline void LMIC_setDownlinks(bit_t enabled)
{
LMIC.downlinkEnabled = enabled;
}

// Special APIs - for development or testing
// !!!See implementation for caveats!!!

Expand Down