-
Notifications
You must be signed in to change notification settings - Fork 6
Fix configuration for Spreading Factor = 6 #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
542638d
WIP -- fix SF=6 for rfm9x
jerryneedell 752f3e2
WIP -- more fix SF=6 for rfm9x
jerryneedell 9668223
add lora sf examples
jerryneedell f2ff1e4
rfm9x set low_datarate_optimize automatically - revize sf examples
jerryneedell ab48f2e
revise sf example
jerryneedell 4a529c9
fix up spreading factor examples
jerryneedell 073912e
additional fix to spreading factor examples
jerryneedell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
|
||
import time | ||
|
||
import board | ||
import busio | ||
import digitalio | ||
|
||
# Define radio parameters. | ||
RADIO_FREQ_MHZ = 915.0 # Frequency of the radio in Mhz. Must match your | ||
# module! Can be a value like 915.0, 433.0, etc. | ||
|
||
# Define pins connected to the chip, use these if wiring up the breakout according to the guide: | ||
CS = digitalio.DigitalInOut(board.CE1) | ||
RESET = digitalio.DigitalInOut(board.D25) | ||
|
||
# Initialize SPI bus. | ||
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) | ||
|
||
# Initialze RFM radio | ||
# uncommnet the desired import and rfm initialization depending on the radio boards being used | ||
|
||
# Use rfm9x for two RFM9x radios using LoRa | ||
|
||
from adafruit_rfm import rfm9x | ||
|
||
rfm = rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ) | ||
|
||
rfm.radiohead = False # don't appent RadioHead heade | ||
# set spreading factor | ||
rfm.spreading_factor = 7 | ||
print("spreading factor set to :", rfm.spreading_factor) | ||
print("low_datarate_optimize set to: ", rfm.low_datarate_optimize) | ||
# rfm.signal_bandwidth = 500000 | ||
print("signal_bandwidth set to :", rfm.signal_bandwidth) | ||
print("low_datarate_optimize set to: ", rfm.low_datarate_optimize) | ||
if rfm.spreading_factor == 12: | ||
rfm.xmit_timeout = 5 | ||
print("xmit_timeout set to: ", rfm.xmit_timeout) | ||
if rfm.spreading_factor == 12: | ||
rfm.receive_timeout = 5 | ||
elif rfm.spreading_factor > 7: | ||
rfm.receive_timeout = 2 | ||
print("receive_timeout set to: ", rfm.receive_timeout) | ||
rfm.enable_crc = True | ||
# send startup message | ||
message = bytes(f"startup message from base", "UTF-8") | ||
if rfm.spreading_factor == 6: | ||
payload = bytearray(40) | ||
rfm.payload_length = len(payload) | ||
payload[0 : len(message)] = message | ||
rfm.send( | ||
payload, | ||
keep_listening=True, | ||
) | ||
else: | ||
rfm.send( | ||
message, | ||
keep_listening=True, | ||
) | ||
# Wait to receive packets. | ||
print("Waiting for packets...") | ||
# initialize flag and timer | ||
# set a delay before sending the echo packet | ||
# avoide multibples of .5 second to minimize chances of node missing | ||
# the packet between receive attempts | ||
transmit_delay = 0.75 | ||
last_transmit_time = 0 | ||
packet_received = False | ||
while True: | ||
if rfm.payload_ready(): | ||
packet_received = False | ||
packet = rfm.receive(timeout=None) | ||
if packet is not None: | ||
# Received a packet! | ||
# Print out the raw bytes of the packet: | ||
print(f"Received (raw payload): {packet}") | ||
print([hex(x) for x in packet]) | ||
print(f"RSSI: {rfm.last_rssi}") | ||
packet_received = True | ||
last_transmit_time = time.monotonic() | ||
if packet_received and ((time.monotonic() - last_transmit_time) > transmit_delay): | ||
# send back the received packet | ||
if rfm.spreading_factor == 6: | ||
payload = bytearray(40) | ||
rfm.payload_length = len(payload) | ||
payload[0 : len(packet)] = packet | ||
rfm.send( | ||
payload, | ||
keep_listening=True, | ||
) | ||
else: | ||
rfm.send( | ||
packet, | ||
keep_listening=True, | ||
) | ||
packet_received = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries | ||
# SPDX-License-Identifier: MIT | ||
|
||
# Example to send a packet periodically between addressed nodes with ACK | ||
# Author: Jerry Needell | ||
# | ||
import time | ||
|
||
import board | ||
import busio | ||
import digitalio | ||
|
||
# Define radio parameters. | ||
RADIO_FREQ_MHZ = 915.0 # Frequency of the radio in Mhz. Must match your | ||
# module! Can be a value like 915.0, 433.0, etc. | ||
|
||
# Define pins connected to the chip, use these if wiring up the breakout according to the guide: | ||
CS = digitalio.DigitalInOut(board.CE1) | ||
RESET = digitalio.DigitalInOut(board.D25) | ||
|
||
# Initialize SPI bus. | ||
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) | ||
|
||
# Initialze RFM radio | ||
# uncommnet the desired import and rfm initialization depending on the radio boards being used | ||
|
||
# Use rfm9x for two RFM9x radios using LoRa | ||
|
||
from adafruit_rfm import rfm9x | ||
|
||
rfm = rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ) | ||
|
||
rfm.radiohead = False # Do not use RadioHead Header | ||
# set spreading factor | ||
rfm.spreading_factor = 7 | ||
print("spreading factor set to :", rfm.spreading_factor) | ||
print("low_datarate_optimize set to: ", rfm.low_datarate_optimize) | ||
# rfm.signal_bandwidth = 500000 | ||
print("signal_bandwidth set to :", rfm.signal_bandwidth) | ||
print("low_datarate_optimize set to: ", rfm.low_datarate_optimize) | ||
if rfm.spreading_factor == 12: | ||
rfm.xmit_timeout = 5 | ||
print("xmit_timeout set to: ", rfm.xmit_timeout) | ||
if rfm.spreading_factor == 12: | ||
rfm.receive_timeout = 5 | ||
elif rfm.spreading_factor > 7: | ||
rfm.receive_timeout = 2 | ||
print("receive_timeout set to: ", rfm.receive_timeout) | ||
rfm.enable_crc = True | ||
# set the time interval (seconds) for sending packets | ||
transmit_interval = 10 | ||
|
||
# initialize counter | ||
counter = 0 | ||
# send startup message from my_node | ||
message = bytes(f"startup message from node", "UTF-8") | ||
if rfm.spreading_factor == 6: | ||
payload = bytearray(40) | ||
rfm.payload_length = len(payload) | ||
payload[0 : len(message)] = message | ||
rfm.send( | ||
payload, | ||
keep_listening=True, | ||
) | ||
else: | ||
rfm.send( | ||
message, | ||
keep_listening=True, | ||
) | ||
|
||
# Wait to receive packets. | ||
print("Waiting for packets...") | ||
# initialize flag and timer | ||
last_transmit_time = time.monotonic() | ||
while True: | ||
# Look for a new packet: only accept if addresses to my_node | ||
packet = rfm.receive() | ||
# If no packet was received during the timeout then None is returned. | ||
if packet is not None: | ||
# Received a packet! | ||
# Print out the raw bytes of the packet: | ||
print(f"Received (raw payload): {packet}") | ||
print([hex(x) for x in packet]) | ||
print(f"RSSI: {rfm.last_rssi}") | ||
# send reading after any packet received | ||
if time.monotonic() - last_transmit_time > transmit_interval: | ||
# reset timeer | ||
last_transmit_time = time.monotonic() | ||
# send a mesage to destination_node from my_node | ||
message = bytes(f"message from node {counter}", "UTF-8") | ||
if rfm.spreading_factor == 6: | ||
payload = bytearray(40) | ||
rfm.payload_length = len(payload) | ||
payload[0 : len(message)] = message | ||
rfm.send( | ||
payload, | ||
keep_listening=True, | ||
) | ||
else: | ||
rfm.send( | ||
message, | ||
keep_listening=True, | ||
) | ||
|
||
counter += 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.