mirror of
https://github.com/markqvist/RNode_Firmware.git
synced 2025-05-05 08:05:18 -04:00
Python library to Python 3
This commit is contained in:
parent
02525cee55
commit
7a5d687f0e
2 changed files with 118 additions and 79 deletions
|
@ -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()
|
Loading…
Add table
Add a link
Reference in a new issue