From ba9c28e038fb3d2cf6a07f928a08e644a7caa5a1 Mon Sep 17 00:00:00 2001 From: vrees Date: Fri, 29 May 2020 11:26:13 +0200 Subject: [PATCH] add shutdown_method to ttn in order reduce power consumption while in deep sleep --- include/TheThingsNetwork.h | 6 ++++++ src/TheThingsNetwork.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/TheThingsNetwork.h b/include/TheThingsNetwork.h index f579244..7115604 100644 --- a/include/TheThingsNetwork.h +++ b/include/TheThingsNetwork.h @@ -72,6 +72,12 @@ public: */ void reset(); + /** + * @brief Shutdown the LoRaWAN radio and reduce power consumption + * + */ + void shutdown(); + /** * @brief Configures the pins used to communicate with the LoRaWAN radio chip. * diff --git a/src/TheThingsNetwork.cpp b/src/TheThingsNetwork.cpp index 070bd3d..ff5d9b6 100644 --- a/src/TheThingsNetwork.cpp +++ b/src/TheThingsNetwork.cpp @@ -118,6 +118,18 @@ void TheThingsNetwork::reset() ttn_hal.leaveCriticalSection(); } +void TheThingsNetwork::shutdown() +{ + ttn_hal.enterCriticalSection(); + LMIC_shutdown(); + waitingReason = eWaitingNone; + if (lmicEventQueue != nullptr) + { + xQueueReset(lmicEventQueue); + } + ttn_hal.leaveCriticalSection(); +} + bool TheThingsNetwork::provision(const char *devEui, const char *appEui, const char *appKey) { if (!provisioning.decodeKeys(devEui, appEui, appKey))