Haha - I often get frustrated when people ask questions like "is there a better way", when "better" means different things to different people, and here I am doing it myself... oh well.. I guess we all have our moments.
Ok - I will try to be a bit more specific.
I am receiving information via an MQTT callback function using the PubSubClient.h library.
Here is a snippet of that callback function from one of the examples of that library.
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i=0;i<length;i++) {
Serial.print((char)payload[i]);
}
Serial.println();
}
Whenever a slider widget is used on a Web-based dashboard, it will trigger the callback function on my microcontroller. I will then have access to the topic, payload, and length variables.
The topic allows me to identify the specific widget being used on the web-based dashboard. The payload will allow me to retrieve the value of the widget (0-255). And the length will tell me how many characters the payload array is storing.
So I have figured out that when the slider widget changes to a value of 255, the payload array will contain the characters '2', '5', and '5'.
Whereby,
payload[0] = 50
payload[1] = 53
payload[2] = 53
So what I guess I am trying to ask, is there a way to get the value of 255 from the payload array more efficiently than using the for-loop as described in my original question.
I just wanted to make sure that I wasn't missing something obvious. Like if you wanted to reconstruct the payload array into a byte which equals 255, how would you do it ?
Keep in mind that the slider value transmitted can be any value from 0 to 255.