Skip to content

Commit f8c8875

Browse files
projectgusdpgeorge
authored andcommitted
lora: Fix SNR value in SX126x received packets.
Wasn't being treated as a signed value. Fixes issue #999. Signed-off-by: Angus Gratton <[email protected]>
1 parent 5b496e9 commit f8c8875

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

micropython/lora/lora-sx126x/lora/sx126x.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,9 @@ def _read_packet(self, rx_packet, flags):
596596
pkt_status = self._cmd("B", _CMD_GET_PACKET_STATUS, n_read=4)
597597

598598
rx_packet.ticks_ms = ticks_ms
599-
rx_packet.snr = pkt_status[2] # SNR, units: dB *4
600-
rx_packet.rssi = 0 - pkt_status[1] // 2 # RSSI, units: dBm
599+
# SNR units are dB * 4 (signed)
600+
rx_packet.rssi, rx_packet.snr = struct.unpack("xBbx", pkt_status)
601+
rx_packet.rssi //= -2 # RSSI, units: dBm
601602
rx_packet.crc_error = (flags & _IRQ_CRC_ERR) != 0
602603

603604
return rx_packet
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
metadata(version="0.1.4")
1+
metadata(version="0.1.5")
22
require("lora")
33
package("lora")

0 commit comments

Comments
 (0)