/ examples / rfm69_header.py
rfm69_header.py
 1  # Example to display raw packets including header
 2  # Author: Jerry Needell
 3  #
 4  import board
 5  import busio
 6  import digitalio
 7  import adafruit_rfm69
 8  
 9  # set the time interval (seconds) for sending packets
10  transmit_interval = 10
11  
12  # Define radio parameters.
13  RADIO_FREQ_MHZ = 915.0  # Frequency of the radio in Mhz. Must match your
14  # module! Can be a value like 915.0, 433.0, etc.
15  
16  # Define pins connected to the chip.
17  CS = digitalio.DigitalInOut(board.CE1)
18  RESET = digitalio.DigitalInOut(board.D25)
19  
20  # Initialize SPI bus.
21  spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
22  
23  # Initialze RFM radio
24  rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ)
25  
26  # Optionally set an encryption key (16 byte AES key). MUST match both
27  # on the transmitter and receiver (or be set to None to disable/the default).
28  rfm69.encryption_key = (
29      b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
30  )
31  
32  # Wait to receive packets.
33  print("Waiting for packets...")
34  # initialize flag and timer
35  while True:
36      # Look for a new packet: only accept if addresses to my_node
37      packet = rfm69.receive(with_header=True)
38      # If no packet was received during the timeout then None is returned.
39      if packet is not None:
40          # Received a packet!
41          # Print out the raw bytes of the packet:
42          print("Received (raw header):", [hex(x) for x in packet[0:4]])
43          print("Received (raw payload): {0}".format(packet[4:]))
44          print("RSSI: {0}".format(rfm69.last_rssi))
45          # send reading after any packet received