work around for :help with rfm9x, dropped packets?

For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Rcayot
 
Posts: 321
Joined: Sat Feb 08, 2020 6:48 pm

work around for :help with rfm9x, dropped packets?

Post by Rcayot »

After working this issue, I feel like the answer lies in that the CRC and ACK fro the rfm9x library is for the payload only, and not the header. The reason for this is that I have packets received that are entirely correct except for the rfm.flags information at packet[3]

So, instead of using the flags field for tagging the different sensor data streams, I would like to be able to send a packet with BOTH the data stream indicator ( 1 through 6) and the data. So instead of:

Code: Select all

while True:
        temperature = str(round((newsensor.temperature), 2))
        rfm9x.flags=1
         if not rfm9x.send_with_ack(temperature.encode("utf-8")):
            print("No Ack T") 
        await asyncio.sleep(interval)
It would be something like:

Code: Select all

while True:
        temperature = str(round((newsensor.temperature), 2))
        #rfm9x.flags=1
        #print(rfm9x.flags, temperature)
temperature_ packet = str(1,temperature)        
if not rfm9x.send_with_ack(temperature_packet.encode("utf-8")):
            print("No Ack T") 
        await asyncio.sleep(interval)
My question is how do I parse the packet into two variables, the number 1, and the value of 'temperature'

Roger

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: work around for :help with rfm9x, dropped packets?

Post by adafruit_support_mike »

Create a data structure with the variables you want to use, then use memcpy() to move binary data from the radio into that structure:

Code: Select all

    struct message {
        uint8_t     id,
        float       temperature,
    } 

    function import_message () {
        message m;
        byte buffer[ sizeof( m ) ];
    
        fill_buffer( buffer );
        memcpy( buffer, &m, sizeof( m ) );
    }

User avatar
Rcayot
 
Posts: 321
Joined: Sat Feb 08, 2020 6:48 pm

Re: work around for :help with rfm9x, dropped packets?

Post by Rcayot »

Mike,

That is C code, I am using circuit python. But your suggestion is a good one. I think I have figured it out.

Roger

Locked
Please be positive and constructive with your questions and comments.

Return to “Wireless: WiFi and Bluetooth”