Closed HaViGit closed 1 year ago
Hi @HaViGit - this issue list isn't intended as a general support forum. Please consider using something like StackOverflow for general questions like this.
In this instance, if the payload contains just the string representation of the number you want, you can use the atoi
function:
void callback(char* topic, byte* payload, unsigned int length) {
int value;
// Ensure the payload is a null terminated string for the atoi function to use
payload[length] = '\0'
value = atoi(payload)
}
If you want it as a float, you can use atof
:
void callback(char* topic, byte* payload, unsigned int length) {
double value;
// Ensure the payload is a null terminated string for the atoi function to use
payload[length] = '\0'
value = atof(payload)
}
Sorry if I'm using this list wrong, I'll take note. But anyway thanks for your quick response and solution.
Can someone help me to convert the payload in the code below to a value (int or float)?