epeters13 / pyLoraRFM9x

Fork of the raspi-lora project with improved interrupt handling and reset support
MIT License
6 stars 9 forks source link

Cannot receive messages from Lora client #1

Closed martynwheeler closed 3 years ago

martynwheeler commented 3 years ago

Hi,

I am having an issue receiving data from a lora client with your package. I can send data to a server so the wiring and set up are okay but whenever I try and receive data I get nothing.

Here is my code. I would appreciate any help. Thanks in advance.

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("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=866, tx_power=14, acks=True, receive_all=True)
lora.on_recv = on_recv

while True:
    time.sleep(1)

# Send a message to a recipient device with address 10
# Retry sending the message twice if we don't get an  acknowledgment from the recipient
message = "Hello there!"
status = lora.send_to_wait(message, 255, retries=2)
if status is True:
    print("Message sent!")
else:
    print("No acknowledgment from recipient")

lora.close()