Skip to content

Commit 75caa6b

Browse files
authored
fix mid band threshold and add function to get current RSSI value (sandeepmistry#288)
* correct mid band threshold on rssi calculatio * add function to get current rssi value from RegRssiValue
1 parent 090fe65 commit 75caa6b

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

API.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ The `onReceive` callback will be called when a packet is received.
194194
int rssi = LoRa.packetRssi();
195195
```
196196

197-
Returns the RSSI of the received packet.
197+
Returns the averaged RSSI of the last received packet (dBm).
198198

199199
### Packet SNR
200200

@@ -204,6 +204,14 @@ float snr = LoRa.packetSnr();
204204

205205
Returns the estimated SNR of the received packet in dB.
206206

207+
## RSSI
208+
209+
```arduino
210+
int rssi = LoRa.rssi();
211+
```
212+
213+
Returns the current RSSI of the radio (dBm). RSSI can be read at any time (during packet reception or not)
214+
207215
### Packet Frequency Error
208216

209217
```arduino

keywords.txt

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ packetRssi KEYWORD2
2323
packetSnr KEYWORD2
2424
packetFrequencyError KEYWORD2
2525

26+
rssi KEYWORD2
27+
2628
write KEYWORD2
2729

2830
available KEYWORD2

src/LoRa.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define REG_RX_NB_BYTES 0x13
2121
#define REG_PKT_SNR_VALUE 0x19
2222
#define REG_PKT_RSSI_VALUE 0x1a
23+
#define REG_RSSI_VALUE 0x1b
2324
#define REG_MODEM_CONFIG_1 0x1d
2425
#define REG_MODEM_CONFIG_2 0x1e
2526
#define REG_PREAMBLE_MSB 0x20
@@ -55,6 +56,10 @@
5556
#define IRQ_PAYLOAD_CRC_ERROR_MASK 0x20
5657
#define IRQ_RX_DONE_MASK 0x40
5758

59+
#define RF_MID_BAND_THRESHOLD 525E6
60+
#define RSSI_OFFSET_HF_PORT 157
61+
#define RSSI_OFFSET_LF_PORT 164
62+
5863
#define MAX_PKT_LENGTH 255
5964

6065
#if (ESP8266 || ESP32)
@@ -258,7 +263,7 @@ int LoRaClass::parsePacket(int size)
258263

259264
int LoRaClass::packetRssi()
260265
{
261-
return (readRegister(REG_PKT_RSSI_VALUE) - (_frequency < 868E6 ? 164 : 157));
266+
return (readRegister(REG_PKT_RSSI_VALUE) - (_frequency < RF_MID_BAND_THRESHOLD ? RSSI_OFFSET_LF_PORT : RSSI_OFFSET_HF_PORT));
262267
}
263268

264269
float LoRaClass::packetSnr()
@@ -285,6 +290,11 @@ long LoRaClass::packetFrequencyError()
285290
return static_cast<long>(fError);
286291
}
287292

293+
int LoRaClass::rssi()
294+
{
295+
return (readRegister(REG_RSSI_VALUE) - (_frequency < RF_MID_BAND_THRESHOLD ? RSSI_OFFSET_LF_PORT : RSSI_OFFSET_HF_PORT));
296+
}
297+
288298
size_t LoRaClass::write(uint8_t byte)
289299
{
290300
return write(&byte, sizeof(byte));

src/LoRa.h

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class LoRaClass : public Stream {
4545
float packetSnr();
4646
long packetFrequencyError();
4747

48+
int rssi();
49+
4850
// from Print
4951
virtual size_t write(uint8_t byte);
5052
virtual size_t write(const uint8_t *buffer, size_t size);

0 commit comments

Comments
 (0)