/* ESP32 WiFi Scanning example */
uint8_t A,B = 0;
String resp = "62 48 01 BA 11\r\n";
void setup() {
Serial.begin(115200);
delay(500);
Serial.println(resp);
getAB(resp);
Serial.printf("A = %d , B = %d\n",A,B);
uint16_t data = (A*256+B)/5/100; //formula 7
Serial.printf("Formula 7 Data = %d",data);
}
void loop() {
delay(1);
}
//get A B from response return in global A B variable
void getAB(String elm_rsp) { //41 05 2A 3C 01>
if (elm_rsp == "NO DATA\r\r>") {//pid no data
A = 0;
B = 0;
} else {
//check if pid is 2 or 3 command length.
uint8_t charcnt = 3; // 224801
String strs[8];
uint8_t StringCount = 0;
while (elm_rsp.length() > 0) {//keep reading each char
int index = elm_rsp.indexOf(' ');//check space
if (index == -1) // No space found
{ //only data without space is now in strs {41,05,aa,bb}
strs[StringCount++] = elm_rsp; //last byte
Serial.println(strs[charcnt].c_str());
A = strtol(strs[charcnt].c_str(),NULL,16); //byte 3 save to A
Serial.println(strs[charcnt+1].c_str());
B = strtol(strs[charcnt + 1].c_str(),NULL,16); //byte 4 save to B
break;
} else {//found space
strs[StringCount++] = elm_rsp.substring(0, index);//copy strings from 0 to space to strs
elm_rsp = elm_rsp.substring(index + 1);//copy the rest behind space to elm_rsp
}
} //while
} //else
}//getAB