rebuild for pylora

This commit is contained in:
Paul 2024-01-08 16:21:07 +01:00
parent e4d10a9f13
commit 6843dc9714
1 changed files with 11 additions and 16 deletions

27
main.py
View File

@ -3,14 +3,9 @@ import serial, subprocess, time
import busio
from digitalio import DigitalInOut, Direction, Pull
import board
#import adafruit_rfm69
import adafruit_rfm9x
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
#rfm = adafruit_rfm69.RFM69(spi, CS, RESET, 868.0)
rfm = adafruit_rfm9x.RFM9x(spi, CS, RESET, 868.0)
from pyLoraRFM9x import LoRa, ModemConfig
addr = '/tmp/rfmtty'
addr_client = '/tmp/rfmtty_client'
@ -22,23 +17,23 @@ time.sleep(1)
ser = serial.serial_for_url(addr)
def on_recv(payload):
print(f'Received lora byte: {payload.message}')
ser.write(payload.message)
lora_address = 2
lora = LoRa(1, 5, lora_address, reset_pin = 25, modem_config=ModemConfig.Bw125Cr45Sf128, tx_power=14, acks=True)
lora.on_recv = on_recv
while True:
packet = None
packet = rfm.receive()
ser_data = bytearray()
while ser.inWaiting() > 0 and len(ser_data) <= 252:
while ser.inWaiting() > 0 and len(ser_data) <= 248:
recieved_byte = ser.read(1)
ser_data += recieved_byte
if ser_data == b'':
pass
else:
print(f'Received serial data: {ser_data}')
rfm.send(ser_data)
if packet is None:
pass
else:
print(f'Received lora byte: {packet}')
ser.write(packet)
lora.send_to_wait(ser_data, 255, retries=2)
socat_proc.kill()