From 0663c6f704855d48b325b24c2b5a38faadae432d Mon Sep 17 00:00:00 2001 From: humorhenker Date: Mon, 8 Jan 2024 11:03:40 +0100 Subject: [PATCH] adjusted main.py to emulate serial on its own --- main.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index fc3b89d..fef4b67 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,15 @@ from pyLoraRFM9x import LoRa, ModemConfig -from SerialEmulator import SerialEmulator -emulator = SerialEmulator('./ttydevice','./ttyclient') +import serial + +addr = '/tmp/virttty' +conn = serial.serial_for_url(addr) # 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)) - emulator.write(payload.message) + conn.write(payload.message) # Use chip select 1. GPIO pin 5 will be used for interrupts and set reset pin to 25 @@ -17,15 +19,12 @@ lora.on_recv = on_recv # 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!" while True: - message = emulator.read() + message = conn.readline() if message != '': print("new messsage:", message) status = lora.send_to_wait(message, 10, retries=2) if status is True: print("Message sent!") else: - print("No acknowledgment from recipient") - -emulator.stop() \ No newline at end of file + print("No acknowledgment from recipient") \ No newline at end of file