adjusted main.py to emulate serial on its own
This commit is contained in:
parent
264dcc6ca5
commit
0663c6f704
15
main.py
15
main.py
|
@ -1,13 +1,15 @@
|
||||||
from pyLoraRFM9x import LoRa, ModemConfig
|
from pyLoraRFM9x import LoRa, ModemConfig
|
||||||
from SerialEmulator import SerialEmulator
|
import serial
|
||||||
emulator = SerialEmulator('./ttydevice','./ttyclient')
|
|
||||||
|
addr = '/tmp/virttty'
|
||||||
|
conn = serial.serial_for_url(addr)
|
||||||
|
|
||||||
# This is our callback function that runs when a message is received
|
# This is our callback function that runs when a message is received
|
||||||
def on_recv(payload):
|
def on_recv(payload):
|
||||||
print("From:", payload.header_from)
|
print("From:", payload.header_from)
|
||||||
print("Received:", payload.message)
|
print("Received:", payload.message)
|
||||||
print("RSSI: {}; SNR: {}".format(payload.rssi, payload.snr))
|
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
|
# 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
|
# 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
|
# Retry sending the message twice if we don't get an acknowledgment from the recipient
|
||||||
message = "Hello there!"
|
|
||||||
while True:
|
while True:
|
||||||
message = emulator.read()
|
message = conn.readline()
|
||||||
if message != '':
|
if message != '':
|
||||||
print("new messsage:", message)
|
print("new messsage:", message)
|
||||||
status = lora.send_to_wait(message, 10, retries=2)
|
status = lora.send_to_wait(message, 10, retries=2)
|
||||||
if status is True:
|
if status is True:
|
||||||
print("Message sent!")
|
print("Message sent!")
|
||||||
else:
|
else:
|
||||||
print("No acknowledgment from recipient")
|
print("No acknowledgment from recipient")
|
||||||
|
|
||||||
emulator.stop()
|
|
Loading…
Reference in New Issue