So basically I have a numpy array, its shape is (8,64) after array.tobytes()
and len(array)
is 512. And
the send()
function in the adafruit_rfm9x library has a payload limit of 252 bytes. Is there any way to do it?
Parameter in both devices.
RADIO_FREQ_MHZ = 433.0
CS = digitalio.DigitalInOut(board.CE1)
RESET = digitalio.DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)
Send data Function in Device1:
def send_message(key, value):
print(f"Sending {key} to Dev 2...")
if not isinstance(value, bytes):
value = bytes(value, 'utf-8')
MAX_CHUNK_SIZE = 252 # Maximum chunk size
num_chunks = (len(value) + MAX_CHUNK_SIZE - 1)
for i in range(num_chunks):
chunk = value[i * MAX_CHUNK_SIZE: (i + 1) * MAX_CHUNK_SIZE]
rfm9x.send_with_ack(chunk)
print(f"{key} has been sent")
Receive data Function in Device2
def receive_message(key):
print(f"Receiving {key} from Dev 1 ...")
MAX_CHUNK_SIZE = 252
received_data = b''
while True:
data = rfm9x.receive(with_ack=True)
if data is not None:
received_data += data
if len(data) < MAX_CHUNK_SIZE:
break
time.sleep(0.1)
print(f"Received {key}")
return received_data
Device 1:
send_message("Data",nparray.tobytes())
Device 2:
Data= receive_message("Data")
result= np.frombuffer(Data, dtype=np.int8).reshape(8, 64)
I get this error. It looks like the packet isn't even being received properly.
ValueError: cannot reshape array of size 8 into shape (8,64)