From 8d01586a5a87e9a57f038ac66d86958cd021322b Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 12 Oct 2021 18:04:55 +0200 Subject: [PATCH] Added RSSI and SNR to echo example --- Examples/Echo.py | 41 +++++++++++++++++++++++++++++++++++++++- RNS/Utilities/rnprobe.py | 2 +- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Examples/Echo.py b/Examples/Echo.py index e8e5901..8b1c300 100644 --- a/Examples/Echo.py +++ b/Examples/Echo.py @@ -82,6 +82,25 @@ def server_callback(message, packet): # that we are going to send a reply to the requester. # Sending the proof is handled automatically, since we # set up the destination to prove all incoming packets. + + reception_stats = "" + if reticulum.is_connected_to_shared_instance: + reception_rssi = reticulum.get_packet_rssi(packet.packet_hash) + reception_snr = reticulum.get_packet_snr(packet.packet_hash) + + if reception_rssi != None: + reception_stats += " [RSSI "+str(reception_rssi)+" dBm]" + + if reception_snr != None: + reception_stats += " [SNR "+str(reception_snr)+" dBm]" + + else: + if packet.rssi != None: + reception_stats += " [RSSI "+str(packet.rssi)+" dBm]" + + if packet.snr != None: + reception_stats += " [SNR "+str(packet.snr)+" dB]" + RNS.log("Received packet from echo client, proof sent") @@ -197,10 +216,30 @@ def packet_delivered(receipt): rtt = round(rtt*1000, 3) rttstring = str(rtt)+" milliseconds" + reception_stats = "" + if reticulum.is_connected_to_shared_instance: + reception_rssi = reticulum.get_packet_rssi(receipt.proof_packet.packet_hash) + reception_snr = reticulum.get_packet_snr(receipt.proof_packet.packet_hash) + + if reception_rssi != None: + reception_stats += " [RSSI "+str(reception_rssi)+" dBm]" + + if reception_snr != None: + reception_stats += " [SNR "+str(reception_snr)+" dB]" + + else: + if receipt.proof_packet != None: + if receipt.proof_packet.rssi != None: + reception_stats += " [RSSI "+str(receipt.proof_packet.rssi)+" dBm]" + + if receipt.proof_packet.snr != None: + reception_stats += " [SNR "+str(receipt.proof_packet.snr)+" dB]" + RNS.log( "Valid reply received from "+ RNS.prettyhexrep(receipt.destination.hash)+ - ", round-trip time is "+rttstring + ", round-trip time is "+rttstring+ + reception_stats ) # This function is called if a packet times out. diff --git a/RNS/Utilities/rnprobe.py b/RNS/Utilities/rnprobe.py index 730c2b5..e40d395 100644 --- a/RNS/Utilities/rnprobe.py +++ b/RNS/Utilities/rnprobe.py @@ -110,7 +110,7 @@ def program_setup(configdir, destination_hexhash, size=DEFAULT_PROBE_SIZE, full_ reception_stats += " [RSSI "+str(reception_rssi)+" dBm]" if reception_snr != None: - reception_stats += " [SNR "+str(reception_snr)+" dBm]" + reception_stats += " [SNR "+str(reception_snr)+" dB]" else: if receipt.proof_packet != None: