From af742f9811c994f06b2c85f719920c54795d0e01 Mon Sep 17 00:00:00 2001 From: Martin Schuster Date: Wed, 27 Nov 2024 19:26:25 +0100 Subject: [PATCH] Give application access to RSSI and SNR values of downlink packets. --- src/STM32LoRaWAN.cpp | 2 ++ src/STM32LoRaWAN.h | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/STM32LoRaWAN.cpp b/src/STM32LoRaWAN.cpp index 433acb9..a2fcbab 100644 --- a/src/STM32LoRaWAN.cpp +++ b/src/STM32LoRaWAN.cpp @@ -1305,6 +1305,8 @@ void STM32LoRaWAN::MacMcpsIndication(McpsIndication_t* i, LoRaMacRxStatus_t* sta if ((i->McpsIndication == MCPS_CONFIRMED || i->McpsIndication == MCPS_UNCONFIRMED) && i->Status == LORAMAC_EVENT_INFO_STATUS_OK) { instance->add_rx(i->Buffer, i->BufferSize); instance->rx_port = i->Port; + instance->rx_rssi = status->Rssi; + instance->rx_snr = status->Snr; } } diff --git a/src/STM32LoRaWAN.h b/src/STM32LoRaWAN.h index 04af62e..5b56ff0 100644 --- a/src/STM32LoRaWAN.h +++ b/src/STM32LoRaWAN.h @@ -299,6 +299,16 @@ class STM32LoRaWAN : public Stream { * Returns the port number of the most recently received packet. */ uint8_t getDownlinkPort() { return rx_port; } + + /** + * Returns the RSSI of the most recently received packet. + */ + int16_t getDownlinkRssi() { return rx_rssi; } + + /** + * Returns the SNR of the most recently received packet. + */ + int8_t getDownlinkSnr() { return rx_snr; } /// @} @@ -1045,6 +1055,12 @@ class STM32LoRaWAN : public Stream { /** Port for most recently received packet */ uint8_t rx_port = 0; + /** RSSI for most recently received packet */ + int16_t rx_rssi = 0; + + /** SNR for most recently received packet */ + int8_t rx_snr = 0; + bool nwk_key_set = false; // Buffer sizes match LORAMAC_PHY_MAXPAYLOAD (but that is not