I am trying to use an rfm69HC to send packet data to another radio (Pibonnet with oled).
The sending unit is a feather RP2040, with an rf69hc breakout, and a BME280 breakout boards.
While trying things like the example simple test etc, there were to me, a few more missed packets recieved by the Pi than optimum. I want to try error correcting etc. No I am using cirvuitpython, and I understand it is a 'best effort'.
My question is why do the examples nrf69_node1_ack.py have both send.with_ack and recieve.with_ack?
What is the purpose of haveing both?
What I want to happen is the radio with the sensor to send the data, with an 'ack' and what happens? I would guess that the recieving board sends an 'ack' acknowledgement back, but do I need a separate recieve.with_ack to actually recieve it or is it part of the send.with_ack to listen for the ack?
Here is my send code:
Code: Select all
# SPDX-FileCopyrightText: 2020 Jerry Needell for Adafruit Industries
# SPDX-License-Identifier: MIT
#modified by Roger Ayotte 11/12/2021
# Example to send a packet periodically between addressed nodes with ACK
import time
import board
import busio
import digitalio
import adafruit_bme280
import adafruit_rfm69
# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
bme280.sea_level_pressure = 1013.25
print("\nTemperature: %0.1f C" % bme280.temperature)
print("Humidity: %0.1f %%" % bme280.relative_humidity)
print("Pressure: %0.1f hPa" % bme280.pressure)
print("Altitude = %0.2f meters" % bme280.altitude)
# set the time interval (seconds) for sending packets
transmit_interval = 10
# 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.
# set GPIO pins as necessary -- this example is for Raspberry Pi
CS = digitalio.DigitalInOut(board.D9)
RESET = digitalio.DigitalInOut(board.D10)
# Initialize SPI bus.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
# Initialze RFM radio
rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ)
# Optionally set an encryption key (16 byte AES key). MUST match both
# on the transmitter and receiver (or be set to None to disable/the default).
rfm69.encryption_key = (
b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
)
# set delay before sending ACK
rfm69.ack_delay = 0.1
# set node addresses
rfm69.node = 1
rfm69.destination = 2
# initialize counter
counter = 0
ack_failed_counter = 0
# send startup message from my_node
rfm69.send_with_ack(bytes("startup message from node {}".format(rfm69.node), "UTF-8"))
# Wait to receive packets.
print("Waiting for packets...")
# initialize flag and timer
time_now = time.monotonic()
while True:
temperature = str(bme280.temperature)
print(temperature)
rfm69.send_with_ack(temperature.encode("utf-8"))
# Look for a new packet: only accept if addresses to my_node
# packet = rfm69.receive(with_ack=True, with_header=True)
# 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("Received (raw header):", [hex(x) for x in packet[0:4]])
print("Received (raw payload): {0}".format(packet[4:]))
print("RSSI: {0}".format(rfm69.last_rssi))
# send reading after any packet received
if time.monotonic() - time_now > transmit_interval:
# reset timeer
time_now = time.monotonic()
counter += 1
# send a mesage to destination_node from my_node
if not rfm69.send_with_ack(
bytes("message from node {} {}".format(rfm69.node, counter), "UTF-8")
):
ack_failed_counter += 1
print(" No Ack: ", counter, ack_failed_counter)
Code: Select all
Temperature: 21.7 C
Humidity: 51.3 %
Pressure: 987.9 hPa
Altitude = 213.18 meters
Waiting for packets...
21.743
21.6812
21.6711
21.6812
21.6865
No Ack: 2 1
21.6711
21.6711
21.6711
21.6711
21.6812
21.6711
21.6762
21.6658
No Ack: 6 2
Code: Select all
# SPDX-FileCopyrightText: 2020 Jerry Needell for Adafruit Industries
# SPDX-License-Identifier: MIT
# Example to receive addressed packed with ACK and send a response
import time
import board
import busio
import digitalio
import adafruit_rfm69
# 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.
# set GPIO pins as necessary - this example is for Raspberry Pi
CS = digitalio.DigitalInOut(board.D9)
RESET = digitalio.DigitalInOut(board.D10)
# Initialize SPI bus.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
# Initialze RFM radio
rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ)
# Optionally set an encryption key (16 byte AES key). MUST match both
# on the transmitter and receiver (or be set to None to disable/the default).
rfm69.encryption_key = (
b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
)
# set delay before transmitting ACK (seconds)
rfm69.ack_delay = 0.1
# set node addresses
rfm69.node = 2
rfm69.destination = 1
# initialize counter
counter = 0
ack_failed_counter = 0
# Wait to receive packets.
print("Waiting for packets...")
while True:
# Look for a new packet: only accept if addresses to my_node
packet = rfm69.receive(with_ack=True, with_header=True)
# 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("Received (raw header):", [hex(x) for x in packet[0:4]])
print("Received (raw payload): {0}".format(packet[4:]))
print("RSSI: {0}".format(rfm69.last_rssi))
# send response 2 sec after any packet received
time.sleep(2)
counter += 1
# send a mesage to destination_node from my_node
if not rfm69.send_with_ack(
bytes("response from node {} {}".format(rfm69.node, counter), "UTF-8")
):
ack_failed_counter += 1
print(" No Ack: ", counter, ack_failed_counter)