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:
parent
090fe65108
commit
75caa6ba00
10
API.md
10
API.md
@ -194,7 +194,7 @@ The `onReceive` callback will be called when a packet is received.
|
|||||||
int rssi = LoRa.packetRssi();
|
int rssi = LoRa.packetRssi();
|
||||||
```
|
```
|
||||||
|
|
||||||
Returns the RSSI of the received packet.
|
Returns the averaged RSSI of the last received packet (dBm).
|
||||||
|
|
||||||
### Packet SNR
|
### Packet SNR
|
||||||
|
|
||||||
@ -204,6 +204,14 @@ float snr = LoRa.packetSnr();
|
|||||||
|
|
||||||
Returns the estimated SNR of the received packet in dB.
|
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
|
### Packet Frequency Error
|
||||||
|
|
||||||
```arduino
|
```arduino
|
||||||
|
@ -23,6 +23,8 @@ packetRssi KEYWORD2
|
|||||||
packetSnr KEYWORD2
|
packetSnr KEYWORD2
|
||||||
packetFrequencyError KEYWORD2
|
packetFrequencyError KEYWORD2
|
||||||
|
|
||||||
|
rssi KEYWORD2
|
||||||
|
|
||||||
write KEYWORD2
|
write KEYWORD2
|
||||||
|
|
||||||
available KEYWORD2
|
available KEYWORD2
|
||||||
|
12
src/LoRa.cpp
12
src/LoRa.cpp
@ -20,6 +20,7 @@
|
|||||||
#define REG_RX_NB_BYTES 0x13
|
#define REG_RX_NB_BYTES 0x13
|
||||||
#define REG_PKT_SNR_VALUE 0x19
|
#define REG_PKT_SNR_VALUE 0x19
|
||||||
#define REG_PKT_RSSI_VALUE 0x1a
|
#define REG_PKT_RSSI_VALUE 0x1a
|
||||||
|
#define REG_RSSI_VALUE 0x1b
|
||||||
#define REG_MODEM_CONFIG_1 0x1d
|
#define REG_MODEM_CONFIG_1 0x1d
|
||||||
#define REG_MODEM_CONFIG_2 0x1e
|
#define REG_MODEM_CONFIG_2 0x1e
|
||||||
#define REG_PREAMBLE_MSB 0x20
|
#define REG_PREAMBLE_MSB 0x20
|
||||||
@ -55,6 +56,10 @@
|
|||||||
#define IRQ_PAYLOAD_CRC_ERROR_MASK 0x20
|
#define IRQ_PAYLOAD_CRC_ERROR_MASK 0x20
|
||||||
#define IRQ_RX_DONE_MASK 0x40
|
#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
|
#define MAX_PKT_LENGTH 255
|
||||||
|
|
||||||
#if (ESP8266 || ESP32)
|
#if (ESP8266 || ESP32)
|
||||||
@ -258,7 +263,7 @@ int LoRaClass::parsePacket(int size)
|
|||||||
|
|
||||||
int LoRaClass::packetRssi()
|
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()
|
float LoRaClass::packetSnr()
|
||||||
@ -285,6 +290,11 @@ long LoRaClass::packetFrequencyError()
|
|||||||
return static_cast<long>(fError);
|
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)
|
size_t LoRaClass::write(uint8_t byte)
|
||||||
{
|
{
|
||||||
return write(&byte, sizeof(byte));
|
return write(&byte, sizeof(byte));
|
||||||
|
@ -45,6 +45,8 @@ public:
|
|||||||
float packetSnr();
|
float packetSnr();
|
||||||
long packetFrequencyError();
|
long packetFrequencyError();
|
||||||
|
|
||||||
|
int rssi();
|
||||||
|
|
||||||
// from Print
|
// from Print
|
||||||
virtual size_t write(uint8_t byte);
|
virtual size_t write(uint8_t byte);
|
||||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user