34 lines
818 B
Python
34 lines
818 B
Python
from pyLoraRFM9x import LoRa, ModemConfig
|
|
import serial
|
|
|
|
import busio
|
|
from digitalio import DigitalInOut, Direction, Pull
|
|
import board
|
|
import adafruit_rfm69
|
|
|
|
CS = DigitalInOut(board.CE1)
|
|
RESET = DigitalInOut(board.D25)
|
|
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
|
|
rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, 915.0)
|
|
|
|
addr = '/tmp/virttty'
|
|
ser = serial.serial_for_url(addr)
|
|
|
|
|
|
while True:
|
|
packet = None
|
|
packet = rfm69.receive()
|
|
ser_data = bytearray()
|
|
while ser.inWaiting() > 0:
|
|
recieved_byte = ser.read(1)
|
|
ser_data += recieved_byte
|
|
if ser_data == b'':
|
|
pass
|
|
else:
|
|
print("new message:", ser_data.decode())
|
|
rfm69.send(ser_data)
|
|
if packet is None:
|
|
pass
|
|
else:
|
|
print("Received:", packet.decode())
|
|
ser.write(packet) |