1
0
mirror of https://github.com/sandeepmistry/arduino-LoRa.git synced 2025-04-19 13:02:14 +03:00

fix mid band threshold and add function to get current RSSI value (#288)

* correct mid band threshold on rssi calculatio
* add function to get current rssi value from RegRssiValue
This commit is contained in:
Sergio 2020-11-19 02:10:58 +01:00 committed by GitHub
parent 090fe65108
commit 75caa6ba00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 2 deletions

10
API.md
View File

@ -194,7 +194,7 @@ The `onReceive` callback will be called when a packet is received.
int rssi = LoRa.packetRssi();
```
Returns the RSSI of the received packet.
Returns the averaged RSSI of the last received packet (dBm).
### Packet SNR
@ -204,6 +204,14 @@ float snr = LoRa.packetSnr();
Returns the estimated SNR of the received packet in dB.
## RSSI
```arduino
int rssi = LoRa.rssi();
```
Returns the current RSSI of the radio (dBm). RSSI can be read at any time (during packet reception or not)
### Packet Frequency Error
```arduino

View File

@ -23,6 +23,8 @@ packetRssi KEYWORD2
packetSnr KEYWORD2
packetFrequencyError KEYWORD2
rssi KEYWORD2
write KEYWORD2
available KEYWORD2

View File

@ -20,6 +20,7 @@
#define REG_RX_NB_BYTES 0x13
#define REG_PKT_SNR_VALUE 0x19
#define REG_PKT_RSSI_VALUE 0x1a
#define REG_RSSI_VALUE 0x1b
#define REG_MODEM_CONFIG_1 0x1d
#define REG_MODEM_CONFIG_2 0x1e
#define REG_PREAMBLE_MSB 0x20
@ -55,6 +56,10 @@
#define IRQ_PAYLOAD_CRC_ERROR_MASK 0x20
#define IRQ_RX_DONE_MASK 0x40
#define RF_MID_BAND_THRESHOLD 525E6
#define RSSI_OFFSET_HF_PORT 157
#define RSSI_OFFSET_LF_PORT 164
#define MAX_PKT_LENGTH 255
#if (ESP8266 || ESP32)
@ -258,7 +263,7 @@ int LoRaClass::parsePacket(int size)
int LoRaClass::packetRssi()
{
return (readRegister(REG_PKT_RSSI_VALUE) - (_frequency < 868E6 ? 164 : 157));
return (readRegister(REG_PKT_RSSI_VALUE) - (_frequency < RF_MID_BAND_THRESHOLD ? RSSI_OFFSET_LF_PORT : RSSI_OFFSET_HF_PORT));
}
float LoRaClass::packetSnr()
@ -285,6 +290,11 @@ long LoRaClass::packetFrequencyError()
return static_cast<long>(fError);
}
int LoRaClass::rssi()
{
return (readRegister(REG_RSSI_VALUE) - (_frequency < RF_MID_BAND_THRESHOLD ? RSSI_OFFSET_LF_PORT : RSSI_OFFSET_HF_PORT));
}
size_t LoRaClass::write(uint8_t byte)
{
return write(&byte, sizeof(byte));

View File

@ -45,6 +45,8 @@ public:
float packetSnr();
long packetFrequencyError();
int rssi();
// from Print
virtual size_t write(uint8_t byte);
virtual size_t write(const uint8_t *buffer, size_t size);