I am struggling with the hex-string to dec value in lambda function.
There are different values in the hex string where a few pairs make up these values.
The first one is in the 6D06 (3-6 character) where I need to read in reverse order by 2 character
so 6D06 needs to become 066D and then converted to the decimal value 1645
(next this needs to be divided by 100 resulting in 16.45 to be stored in a float)
std::string rawhex = format_hex_pretty((uint8_t *) x.c_str(), x.size()).c_str();
ESP_LOGD("raw_hex", "%s", rawhex.c_str());
rawhex.erase(std::remove(rawhex.begin(), rawhex.end(), '.'), rawhex.end());
ESP_LOGD("raw_hex_stripped", "%s", rawhex.c_str());
std::string temp_part_1 = rawhex.substr(4, 2);
std::string temp_part_2 = rawhex.substr(2, 2);
ESP_LOGD("temp_part_1", "%s", temp_part_1.c_str());
ESP_LOGD("temp_part_2", "%s", temp_part_2.c_str());
std::string temp_hex = temp_part_1 + temp_part_2;
ESP_LOGD("temp_hex", "%s", temp_hex.c_str());
int i = std::atoi(temp_hex.c_str());
ESP_LOGD("temp_hex_i", "%i", i);
the output is like this:
[11:51:08][V][text_sensor:016]: āBle reading dataā: Received new state 3m\xaea\xd3
[11:51:08][D][text_sensor:067]: āBle reading dataā: Sending state ā3m\xaea\xd3ā
[11:51:08][D][raw_hex:159]: 33.6D.06.AE.07.D3.08.00.00.21.0E.12 (12)
[11:51:08][D][raw_hex_stripped:162]: 336D06AE07D3080000210E12 (12)
[11:51:08][D][temp_part_1:166]: 06
[11:51:08][D][temp_part_2:167]: 6D
[11:51:08][D][temp_hex:170]: 066D
[11:51:08][D][temp_hex_i:174]: 66
where hex: 066D ā dec: 1645 and not 66
I tried atoi, stoi, QString, stoul and all other suggestions I found on forums regarding C++
the newer methods (like stoi and qstring) in C++ are giving errors that indicate there are not available for the compiler
What would be the best way to get the conversion working?