Here's another way without using strtok():
char oneReading[25];
char *ptr;
char temp[8];
int rpm;
void setup()
{
Serial.begin(9600);
}
void loop() {
int charsRead;
while (Serial.available() > 0) // Using test input data: 80 5C 66 BE E0 2E
{
charsRead = Serial.readBytesUntil('\n', oneReading, sizeof(oneReading) - 1); // Read until '\n' or 24 chars
oneReading[charsRead] = '\0';
ptr = strstr(oneReading, "BE "); // Look for sentinel
if (ptr != NULL) {
strncpy(temp, ptr + 6, 2); // Flip the digits; take last 2 chars first...
strncpy(&temp[2], ptr + 3, 2); // ...now the first two past the "BE "
temp[4] = '\0'; // Make it a string
rpm = (int) strtol(temp, &ptr, 16);;
Serial.println(rpm);
}
}
}
This assumes that "BE " always preceeds the rpm data and that string is not an earlier hex number.