Skip to content

Commit

Permalink
Merge pull request #212 from nRF24/update-py-examples
Browse files Browse the repository at this point in the history
update python examples per testing
  • Loading branch information
TMRh20 authored Jun 21, 2022
2 parents a3bc47d + 1851ff4 commit f9b1bc4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions examples_RPi/RF24Mesh_Example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import time
import struct
from RF24 import RF24, RF24_PA_MAX
from RF24 import RF24
from RF24Network import RF24Network
from RF24Mesh import RF24Mesh

Expand All @@ -25,7 +25,7 @@ def millis():
mesh.setNodeID(4)
print("starting nodeID", mesh.getNodeID())
if not mesh.begin():
if not radio.isChipConnected():
if radio.isChipConnected():
try:
print("Could not connect to network.\nConnecting to mesh...")
while mesh.renewAddress() == 0o4444:
Expand All @@ -35,7 +35,6 @@ def millis():
sys.exit()
else:
raise OSError("Radio hardware not responding or could not connect to mesh.")
radio.setPALevel(RF24_PA_MAX) # Power Amplifier
radio.printDetails()

TIMER = 0
Expand All @@ -51,9 +50,9 @@ def millis():
if not mesh.write(struct.pack("L", TIMER), ord("M")):
# If a write fails, check connectivity to the mesh network
if not mesh.checkConnection():
# The address could be refreshed per a specified timeframe
# The address could be refreshed per a specified time frame
# or only when sequential writes fail, etc.
print("Renewing Address...")
print("Send fail. Renewing Address...")
while mesh.renewAddress() == 0o4444:
print("Renewing Address...")
else:
Expand All @@ -62,4 +61,5 @@ def millis():
print("Send OK:", TIMER)
time.sleep(0.001) # delay 1 ms
except KeyboardInterrupt:
radio.powerDown() # power radio down before exiting
print("powering down radio and exiting.")
radio.powerDown()
6 changes: 3 additions & 3 deletions examples_RPi/RF24Mesh_Example_Master.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
a Mesh network master node.
"""
import struct
from RF24 import RF24, RF24_PA_MAX
from RF24 import RF24
from RF24Network import RF24Network
from RF24Mesh import RF24Mesh

Expand All @@ -17,7 +17,6 @@
# if mesh.begin() returns false for a master node,
# then radio.begin() returned false.
raise OSError("Radio hardware not responding.")
radio.setPALevel(RF24_PA_MAX) # Power Amplifier
radio.printDetails()

try:
Expand All @@ -29,4 +28,5 @@
header, payload = network.read(struct.calcsize("L"))
print(f"Received message {header.toString()}")
except KeyboardInterrupt:
radio.powerDown() # power radio down before exiting
print("powering down radio and exiting.")
radio.powerDown()

0 comments on commit f9b1bc4

Please sign in to comment.