How to parse these bytes?

Looking at the adafruit mqtt_esp8266 example sketch.

Line 99 if this sketch casts an array of bytes to chars and prints them to serial (is this accurate so far?)

Adafruit_MQTT_Subscribe *subscription;
  while ((subscription = mqtt.readSubscription(5000))) {
    if (subscription == &onoffbutton) {
      Serial.print(F("Got: "));
      Serial.println((char *)onoffbutton.lastread);
    }
  }

For my purposes this (char *)onoffbutton.lastread is what I'm interested in and will return a standard hex color code like #FF0000

Assuming the # is byte at index zero how do I extract the red, green, and blue parts of the color code separatly and convert them to the three separate rgb decimals so I can process them?

I can probably hack together the conversion hex to byte conversion, but what I really need help understanding is how to access the color's byte pairs. I'm pretty bad at c and it's been a while.

Assuming everything is correct, you can extract the rgb like so:
~~ ...~~
~~ char *str = (char *)onoffbutton.lastread;~~
~~ byte r = str[1];~~
~~ byte g = str[2];~~
~~ byte b = str[3];~~

This is wrong.

So that'll extract each individual byte, right. So given the hex string "#FF7F00" how do I convert the three hex pairs to bytes from 0-255? See my psuedo code below.

char *str = (char *)onoffbutton.lastread; // = "#FF7F00"

byte r = convert_hex_to_decimal( str[1] + str[2] ) ;   // = "FF" = 255
byte g = convert_hex_to_decimal( str[3] + str[4] ) ;  // = "7F" = 127
byte b = convert_hex_to_decimal( str[5] + str[6] ) ;  // = "00" = 0

Here is how I am extracting a 32 bit int into a int8_t:

 if (!PassTwo)
        {
          rx_frame.FIR.B.FF = CAN_frame_std;
          rx_frame.MsgID = 1;
          rx_frame.FIR.B.DLC = 8;
          rx_frame.data.u8[0] = *item & 0xFF;
          rx_frame.data.u8[1] = (*item >> 8) & 0xFF;
          rx_frame.data.u8[2] = (*item >> 16) & 0xFF;
          rx_frame.data.u8[3] = (*item >> 24) & 0xFF;
          PassTwo = true;
        } else {
          rx_frame.data.u8[4] = *item & 0xFF;;
          rx_frame.data.u8[5] = (*item >> 8) & 0xFF;
          rx_frame.data.u8[6] = (*item >> 16) & 0xFF;
          rx_frame.data.u8[7] = (*item >> 24) & 0xFF;
          ESP32Can.CANWriteFrame(&rx_frame); // send items over CAN buss
          PassTwo = false;
        }

Might give you some ideas on how to do do your thing.

Could it be as simple as

      //parse the color
      int r, g, b;
      sscanf((char *)subFeed.lastread, "#%02x%02x%02x", &r, &g, &b);

Here is how I combine 2 bytes to get blah blah blah

int16_t temp = 0;

 fReadSPIdata16bits( hAG, LSM9DS1_REGISTER_OUT_X_L_XL ); // read x accel
    temp = GetHighBits(); temp <<= 8; temp |= GetLowBits();

Here's the longer version:

void HexToColor(const char* hex, byte *container)
{
    char str[3] = {};
    //get r
    str[0] = hex[1];
    str[1] = hex[2];
    container[0] = (byte)strtol(str, NULL, 16);

    //get b
    str[0] = hex[3];
    str[1] = hex[4];
    container[1] = (byte)strtol(str, NULL, 16);

    //get g
    str[0] = hex[5];
    str[1] = hex[6];
    container[2] = (byte)strtol(str, NULL, 16);
}

//usage
{
   ...
   char *hex = (char *)onoffbutton.lastread;
   byte color[3] = {};
   HexToColor(hex, color);
}

Thank you gentlemen!

I can't get my head around c strings and pointers...

theboozler:
I can't get my head around c strings and pointers...

See this tutorial