Hi all,
I need help with my MQTT Payload which contains 10 digits.
I am using the PubSubClient library.
What I want to do is recieve a 10 digit number e.g. "5000302510" then I want to seperate them every 2 digits. Something like this -> "50" "00" "30" "25" "10" and store them in seperate int variables.
If it would help I can also modify the Payload from the Sender side. But I want it to be only one Message which contains the information.
At the Moment I have this code which does not work. The first conversion works so var rec1 holds the right value but everything after that is not correct.
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
String value = "";
byte* payloadMan = payload;
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
payloadMan[0] = payload[0];
payloadMan[1] = payload[1];
payloadMan[2] = '\0';
rec1 = atoi((char *)payloadMan);
payloadMan[0] = payload[2];
payloadMan[1] = payload[3];
payloadMan[2] = '\0';
rec2 = atoi((char *)payloadMan);