Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First message does not trigger ack #2

Open
martynwheeler opened this issue Jan 4, 2021 · 3 comments
Open

First message does not trigger ack #2

martynwheeler opened this issue Jan 4, 2021 · 3 comments

Comments

@martynwheeler
Copy link

martynwheeler commented Jan 4, 2021

Hi,

I have your code working now and its seems very good. I have found two slight issues.

  1. If I set acks=True the code still sends an ack back to the client upon receiving a message. This could easily be fixed by changing line 318 from:
if  header_to == self._this_address and header_flags & FLAGS_REQ_ACK and not header_flags & FLAGS_ACK:

to:

if  (header_to == self._this_address and header_flags & FLAGS_REQ_ACK and not header_flags & FLAGS_ACK) and self._ack:
  1. My client (an arduino with the example code from radiohead) always sends the message twice because I think that the ack is not being correctly triggered. It all works with raspi-lora and does not end up sending two messages. My code is below. I am not sure why the ack is not being sent each time I get a message? It always does it on the first retry from the client. Is it possibly to do with the interrupts?

Here is my code:

from pyLoraRFM9x import LoRa, ModemConfig
import time

# This is our callback function that runs when a message is received
def on_recv(payload):
    print("From:", payload.header_from)
    print("ID:", payload.header_id)
    print("Received:", payload.message)
    print("RSSI: {}; SNR: {}".format(payload.rssi, payload.snr))


# Use chip select 1. GPIO pin 5 will be used for interrupts and set reset pin to 25
# The address of this device will be set to 2
lora = LoRa(1, 5, 2, reset_pin = 25, modem_config=ModemConfig.Bw125Cr45Sf128, freq=868, tx_power=20, acks=True)
lora.on_recv = on_recv

lora.set_mode_rx()

try:
    while True:
        pass
except:
   print("some error") 

finally:
   print("clean up") 
   lora.close()

and here is the output:

From: 1
ID: 54
Received: b'Hello World!\x00'
RSSI: -22; SNR: 10.25
SENT ACK
From: 1
ID: 54
Received: b'Hello World!\x00'
RSSI: -21; SNR: 9.75
From: 1
ID: 55
Received: b'Hello World!\x00'
RSSI: -22; SNR: 9.75
SENT ACK
From: 1
ID: 55
Received: b'Hello World!\x00'
RSSI: -22; SNR: 9.75
From: 1
ID: 56
Received: b'Hello World!\x00'
RSSI: -21; SNR: 9.5
SENT ACK
From: 1
ID: 56
Received: b'Hello World!\x00'
RSSI: -20; SNR: 11.25

@epeters13
Copy link
Owner

Thanks for reporting this. I will look into this hopefully soon.
So far I have not used the sending of acknowledgements from the pi, so this feature is rather untested. I have in the past observed some strange behavior as well with the interrupts, especially when sending a reply as part of the ISR.

@martynwheeler
Copy link
Author

martynwheeler commented Jan 5, 2021 via email

@epeters13
Copy link
Owner

@martynwheeler I fixed an issue that caused a too fast state change in the RFM9x modem, leaving it hang in a bad state. Checkout the rpi.GPIO-final commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants