Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions adafruit_rfm9x.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@

* Author(s): Tony DiCola, Jerry Needell
"""
import time
import random
from micropython import const

import time

import adafruit_bus_device.spi_device as spidev

from micropython import const

__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_RFM9x.git"


# Internal constants:
# Register names (FSK Mode even though we use LoRa instead, from table 85)
_RH_RF95_REG_00_FIFO = const(0x00)
Expand Down Expand Up @@ -289,6 +286,11 @@ def __init__(
The instantaneous RSSI value may not be accurate once the
operating mode has been changed.
"""
self.last_snr = 0.0
"""The SNR of the last received packet. Stored when the packet was received.
The instantaneous SNR value may not be accurate once the
operating mode has been changed.
"""
# initialize timeouts and delays delays
self.ack_wait = 0.5
"""The delay time before attempting a retry after not receiving an ACK"""
Expand Down Expand Up @@ -497,6 +499,16 @@ def rssi(self):
raw_rssi -= 164
return raw_rssi

@property
def snr(self):
"""The SNR (in dB) of the last received message."""
# Read SNR 0x19 register and convert to value using formula in datasheet.
# SNR(dB) = PacketSnr [twos complement] / 4
snr_byte = self._read_u8(_RH_RF95_REG_19_PKT_SNR_VALUE)
if snr_byte > 127:
snr_byte = (256 - snr_byte) * -1
return snr_byte / 4

@property
def signal_bandwidth(self):
"""The signal bandwidth used by the radio (try setting to a higher
Expand Down Expand Up @@ -775,6 +787,10 @@ def receive(
packet = None
# save last RSSI reading
self.last_rssi = self.rssi

# save the last SNR reading
self.last_snr = self.snr

# Enter idle mode to stop receiving other packets.
self.idle()
if not timed_out:
Expand Down