From 30a07a32cecd324c03c04896a63b560cb29d93ca Mon Sep 17 00:00:00 2001 From: Matt Corallo <649246+TheBlueMatt@users.noreply.github.com> Date: Thu, 26 Sep 2019 22:22:05 +0000 Subject: [PATCH 1/2] Fix RSSI offset for pre-msg RSSI notification last_rssi is a large negative number, with rssi_offset being +292, intended to be added to put the value inside the range of a single byte uint. Before sending the data message, a RSSI message is automatically sent, which is quite nice, but the value ends up overflowing the 8-bit uint, giving a bogus value. --- RNode_Firmware.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index 4928529..6bf3bfb 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -144,7 +144,7 @@ void receiveCallback(int packet_size) { // recieved packet to the host. Serial.write(FEND); Serial.write(CMD_STAT_RSSI); - Serial.write((uint8_t)(last_rssi-rssi_offset)); + Serial.write((uint8_t)(last_rssi+rssi_offset)); Serial.write(FEND); // And then write the entire packet @@ -170,7 +170,7 @@ void receiveCallback(int packet_size) { // recieved packet to the host. Serial.write(FEND); Serial.write(CMD_STAT_RSSI); - Serial.write((uint8_t)(last_rssi-rssi_offset)); + Serial.write((uint8_t)(last_rssi+rssi_offset)); Serial.write(FEND); // And then write the entire packet From 68f403bf849933f1f22aa91d63dab78168565523 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 26 Sep 2019 18:50:04 -0400 Subject: [PATCH 2/2] Use Packet RSSI formula from datasheet section 5.5.5 --- LoRa.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/LoRa.cpp b/LoRa.cpp index eb3ec2a..64d5fec 100644 --- a/LoRa.cpp +++ b/LoRa.cpp @@ -219,6 +219,12 @@ uint8_t LoRaClass::packetRssiRaw() { int LoRaClass::packetRssi() { int pkt_rssi = (int)readRegister(REG_PKT_RSSI_VALUE); + int8_t pkt_snr = ((int8_t)readRegister(REG_PKT_SNR_VALUE)); + if pkt_snr < 0 { + pkt_rssi = pkt_rssi * 16 / 15; + } else { + pkt_rssi += pkt_snr / 4; + } // TODO: change this to look at the actual model code if (_frequency < 820E6) pkt_rssi -= 7; pkt_rssi -= 157;