rfm9x_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_rfm9x 8 9 # Define radio parameters. 10 RADIO_FREQ_MHZ = 915.0 # Frequency of the radio in Mhz. Must match your 11 # module! Can be a value like 915.0, 433.0, etc. 12 13 # Define pins connected to the chip. 14 CS = digitalio.DigitalInOut(board.CE1) 15 RESET = digitalio.DigitalInOut(board.D25) 16 17 # Initialize SPI bus. 18 spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) 19 20 # Initialze RFM radio 21 rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ) 22 23 # Wait to receive packets. 24 print("Waiting for packets...") 25 # initialize flag and timer 26 while True: 27 # Look for a new packet: only accept if addresses to my_node 28 packet = rfm9x.receive(with_header=True) 29 # If no packet was received during the timeout then None is returned. 30 if packet is not None: 31 # Received a packet! 32 # Print out the raw bytes of the packet: 33 print("Received (raw header):", [hex(x) for x in packet[0:4]]) 34 print("Received (raw payload): {0}".format(packet[4:])) 35 print("RSSI: {0}".format(rfm9x.last_rssi)) 36 # send reading after any packet received