Clearing Buffers

Hello, I am just getting started with Carloop and was able to get up and running pretty quickly. However, I have run into an issue when I am trying to read the most recent value on the CANbus. My code transmits a request for a parameter, then I try to read the response.

The code below works however, it appears it gives me the oldest value in the buffer instead of the most recent one. I put in a 1 second for loop that works but is inefficient. Is there a way to clear out the buffer? Or is there another issue with my code.
for (unsigned long start = millis(); millis() - start < 1000;){
carloop.update();
CANMessage messageread;

     if (carloop.can().receive(messageread)){

        if (messageread.id == 0x18EFF82E) {
            Serial.print(messageread.data[4], HEX);
            STread = messageread.data[4], HEX;
        }
    }

}

The output I get in the serial monitor is below (the value is transmitted every 500ms and changed from 0 to 1 prior to calling this function). Thanks in advance for any help.

Take a look at the “VIN request” sample app.
You need to add a loop for the data.

@cachen ,

The source code for the VIN request sample is here:

As @dubb45 says
You need to wait until the message you are looking for arrives.
Also, there could be other messages on the CANbus that are not the message you are interested in.

Thanks for the tips, I found the issue, it was related to multiple parameters being reported using the same message id. The first two bytes of data were identifying the parameter. Once I changed it so I was looking for that message id plus the first two data bytes everything worked as expected.

Thanks for the help.