Hey @tchinou1,
I did the same thing: taking a http request as a HEX String and convert it to 3 INTs.
String color = raw_response.substring(43+3+27,44+3+27+5);//the HEX color in the msg: RRGGBB
Serial.println(color);
String Tcolor;
int Rcolor;
int Gcolor;
int Bcolor;
int temp;
char C_color;
//HEX char to INT - Red color
C_color = color[0];
Rcolor = hexToDec(C_color,1);
C_color = color[1];
Rcolor = (hexToDec(C_color,0)) + Rcolor;
Serial.println(Rcolor);
//HEX char to INT - Green color
C_color = color[2];
Gcolor = hexToDec(C_color,1);
C_color = color[3];
Gcolor = (hexToDec(C_color,0)) + Gcolor;
Serial.println(Gcolor);
//HEX char to INT - Blue color
C_color = color[4];
Bcolor = hexToDec(C_color,1);
C_color = color[5];
Bcolor = (hexToDec(C_color,0)) + Bcolor;
Serial.println(Bcolor);
and
int hexToDec(char hexString,int x) {
int decValue = 0;
int tempvalue =0;
if ((hexString != 'A') && (hexString != 'B') && (hexString != 'C') && (hexString != 'D') && (hexString != 'E') && (hexString != 'F')){
int tempvalue = hexString - '0';
if (x==1){
decValue=tempvalue *16;
} else {
decValue=tempvalue + decValue;
}
}
else {
if (hexString == 'A'){
tempvalue=10; }
if (hexString == 'B'){
tempvalue=11; }
if (hexString == 'C'){
tempvalue=12; }
if (hexString == 'D'){
tempvalue=13; }
if (hexString == 'E'){
tempvalue=14; }
if (hexString == 'F'){
tempvalue=15; }
if (x==1){
decValue=tempvalue *16;
} else {
decValue=tempvalue + decValue;
}
}
return decValue;
}
I’m not sure this is the best way but it’s working
good luck