Compare commits

...
6 Commits
Author SHA1 Message Date
hmrhkr 1a089a38a1 set receive_all and no wait send 2024-01-08 16:50:08 +01:00
hmrhkr c68c360abf typecasting ser_data to bytes 2024-01-08 16:41:17 +01:00
hmrhkr 6843dc9714 rebuild for pylora 2024-01-08 16:21:07 +01:00
hmrhkr e4d10a9f13 added condition to limit send packet size to 252 bytes 2024-01-08 16:00:41 +01:00
hmrhkr 187390e375 removed SerialEmulator.py 2024-01-08 15:27:55 +01:00
hmrhkr a7e38aedb7 populated readme 2024-01-08 15:27:32 +01:00
3 changed files with 23 additions and 51 deletions

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
# Lora 2 Serial
## Mapping rfm9x SPI Device to a Serial File Interface for usage with AX.25 Kiss
creates /tmp/rfmtty and /tmp/rfmtty_client
Attach using kissattach /tmp/rfmtty_client ax0 IP_ADDRESS
with configured axports
https://github.com/dmahony/LoRa-AX25-IP-Network/wiki/Installation-Instructions
http://packet-radio.info/index.php?id=packet-radio-unter-linux-mit-linpac
-35
View File
@@ -1,35 +0,0 @@
import os, subprocess, serial, time
# this script lets you emulate a serial device
# the client program should use the serial port file specifed by client_port
# if the port is a location that the user can't access (ex: /dev/ttyUSB0 often),
# sudo is required
class SerialEmulator(object):
def __init__(self, device_port='./ttydevice', client_port='./ttyclient'):
self.device_port = device_port
self.client_port = client_port
cmd=['/usr/bin/socat','-d','-d','PTY,link=%s,raw,echo=0' %
self.device_port, 'PTY,link=%s,raw,echo=0' % self.client_port]
self.proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
time.sleep(1)
self.serial = serial.Serial(self.device_port, 9600, rtscts=True, dsrdtr=True)
self.err = ''
self.out = ''
def write(self, out):
self.serial.write(out)
def read(self):
line = ''
while self.serial.inWaiting() > 0:
line += self.serial.read(1)
return line
def __del__(self):
self.stop()
def stop(self):
self.proc.kill()
self.out, self.err = self.proc.communicate()
+11 -16
View File
@@ -3,14 +3,9 @@ import serial, subprocess, time
import busio import busio
from digitalio import DigitalInOut, Direction, Pull from digitalio import DigitalInOut, Direction, Pull
import board import board
#import adafruit_rfm69
import adafruit_rfm9x
CS = DigitalInOut(board.CE1) from pyLoraRFM9x import LoRa, ModemConfig
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)
addr = '/tmp/rfmtty' addr = '/tmp/rfmtty'
addr_client = '/tmp/rfmtty_client' addr_client = '/tmp/rfmtty_client'
@@ -22,23 +17,23 @@ time.sleep(1)
ser = serial.serial_for_url(addr) ser = serial.serial_for_url(addr)
def on_recv(payload):
print(f'Received lora data: {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, receive_all=True)
lora.on_recv = on_recv
while True: while True:
packet = None
packet = rfm.receive()
ser_data = bytearray() ser_data = bytearray()
while ser.inWaiting() > 0: while ser.inWaiting() > 0 and len(ser_data) <= 248:
recieved_byte = ser.read(1) recieved_byte = ser.read(1)
ser_data += recieved_byte ser_data += recieved_byte
if ser_data == b'': if ser_data == b'':
pass pass
else: else:
print(f'Received serial data: {ser_data}') print(f'Received serial data: {ser_data}')
rfm.send(ser_data) lora.send(bytes(ser_data), 255)
if packet is None:
pass
else:
print(f'Received lora byte: {packet}')
ser.write(packet)
socat_proc.kill() socat_proc.kill()