From 73382c293347480509bce6276f66b6028f74fc42 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 20 Aug 2023 19:16:38 +0200 Subject: [PATCH] [LoRaWAN] Fixed output power configuration (#814) --- src/protocols/LoRaWAN/LoRaWAN.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/protocols/LoRaWAN/LoRaWAN.cpp b/src/protocols/LoRaWAN/LoRaWAN.cpp index 75266256..568abbca 100644 --- a/src/protocols/LoRaWAN/LoRaWAN.cpp +++ b/src/protocols/LoRaWAN/LoRaWAN.cpp @@ -806,8 +806,14 @@ int16_t LoRaWANNode::setPhyProperties() { state = this->configureChannel(channelId, this->band->defaultChannels[0].joinRequestDataRate); } RADIOLIB_ASSERT(state); - - state = this->phyLayer->setOutputPower(this->band->powerMax); + + // set the maximum power supported by both the module and the band + int8_t pwr = this->band->powerMax; + state = RADIOLIB_ERR_INVALID_OUTPUT_POWER; + while(state == RADIOLIB_ERR_INVALID_OUTPUT_POWER) { + // go from the highest power in band and lower it until we hit one supported by the module + state = this->phyLayer->setOutputPower(pwr--); + } RADIOLIB_ASSERT(state); uint8_t syncWord[3] = { 0 };