When I receive values over MQTT, they come as strings. What is does is accepting a string, e.g. "23.4" and convert it into raw to send over the interface. What is the modern equivalent of that ?
void StrToRaw (String value, String type, uint8* raw ){
for (int i = 0; i<10; i++) raw[i]=0;
if (type == "TempL") { DPTemp temp_dp("TempL", "DPs", 0x00); DPValue tempDP((float)atof(value.c_str())); temp_dp.encode(raw,tempDP); }
else if (type == "TempS") { DPTempS temps_dp("TempS", "DPs", 0x00); DPValue tempDP((uint8_t)atoi(value.c_str())); temps_dp.encode(raw,tempDP); }
else if (type == "STAT") { DPStat stat_dp("Stat", "DPs", 0x00); DPValue tempDP((bool )atoi(value.c_str())); stat_dp.encode(raw,tempDP); }
else if (type == "CountL"){ DPCount count_dp("CountL", "DPs", 0x00); DPValue tempDP((uint32_t)atoi(value.c_str())); count_dp.encode(raw,tempDP); }
else if (type == "CountS"){ DPCountS counts_dp("CountS", "DPs", 0x00); DPValue tempDP((uint16_t)atoi(value.c_str())); counts_dp.encode(raw,tempDP); }
else if (type == "Mode") { DPMode mode_dp("Mode", "DPs", 0x00); DPValue tempDP((uint8_t)atoi(value.c_str())); mode_dp.encode(raw,tempDP); }
else if (type == "Hours") { DPHours hours_dp("Hours", "DPs", 0x00); DPValue tempDP((uint16_t)atoi(value.c_str())); hours_dp.encode(raw,tempDP); }
else if (type == "CoP") { DPCoP cop_dp("CoP", "DPs", 0x00); DPValue tempDP((uint8_t)atoi(value.c_str())); cop_dp.encode(raw,tempDP); }
}
When I receive values over MQTT, they come as strings. What is does is accepting a string, e.g. "23.4" and convert it into raw to send over the interface. What is the modern equivalent of that ?