adjusted main.py to emulate serial on its own
This commit is contained in:
parent
264dcc6ca5
commit
0663c6f704
13
main.py
13
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,9 +19,8 @@ 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)
|
||||
|
@ -27,5 +28,3 @@ while True:
|
|||
print("Message sent!")
|
||||
else:
|
||||
print("No acknowledgment from recipient")
|
||||
|
||||
emulator.stop()
|
Loading…
Reference in New Issue