Python library to Python 3

This commit is contained in:
Mark Qvist 2020-05-27 16:45:51 +02:00
parent 02525cee55
commit 7a5d687f0e
2 changed files with 118 additions and 79 deletions

View file

@ -1,19 +1,23 @@
# This is a short example program that
# demonstrates the bare minimum of using
# RNode in a Python program. First we'll
# import the RNodeInterface class.
# RNode in a Python program.
#
# The example and the RNode.py library is
# written for Python 3, so be sure to run
# it with: python3 Example.py
# First we'll import the RNodeInterface class.
from RNode import RNodeInterface
# We'll also define which serial port the
# RNode is attached to.
serialPort = "/dev/ttyUSB0"
# TODO: Remove
serialPort = "/dev/tty.usbserial-DN03E0FQ"
# This function gets called every time a
# packet is received
def gotPacket(data, rnode):
print("Received a packet: "+data)
message = data.decode("utf-8")
print("Received a packet: "+message)
print("RSSI: "+str(rnode.r_stat_rssi)+" dBm")
print("SNR: "+str(rnode.r_stat_snr)+" dB")
@ -35,7 +39,9 @@ try:
print("Waiting for packets, hit enter to send a packet, Ctrl-C to exit")
while True:
input()
rnode.send("Hello World!")
message = "Hello World!"
data = message.encode("utf-8")
rnode.send(data)
except KeyboardInterrupt as e:
print("")
exit()