I want to control an RGB ring light from my smartphone, I don't go into the details of how the system works but essentially I receive an MQTT message with hue, saturation and brightness values on my ESP8266.
To handle MQTT messages I use this function:
void callback(char* topic, byte* payload, unsigned int length)
{
//Print message
Serial.print("Message arrived: ");
Serial.print(topic);
Serial.print(", ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
if (strcmp(topic, "setHSV/LIGHT") == 0)
{
//Do something
}
}
and when I change the color of the light from my smartphone I get a message like this on the ESP8266: setHSV/LIGHT = 0,0,59
My question is: how do I convert the 3 values I receive into 3 separate int values that I can use to control the LEDs?
Get the first one with atoi of the payload before you use strtok. Get the others with the while loop, but fix the typo where you are looking for a semi-colon rather than a comma.