Im unable to parse the payload and always getting into the error section. What am I missing. Im able to connect, receive message, post message, but cant read the payload
void callback(char* topic, byte* payload, unsigned int length) {
byte* bytes;
int i;
writeOled("Message arrived",oledLine);
client.publish(outTopic, "Message received");
Serial.print(topic);
Serial.print("] ");
for (i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
// Switch on the LED if an 1 was received as first character
writeOled("Message Received",oledLine);
//res = String(result);
//writeOled(res,oledLine);
//client.publish(outTopic, result);
if ((char)payload[0] == '0') {
digitalWrite(relay_pin, LOW); // Turn the LED on (Note that LOW is the voltage level
Serial.println("relay_pin -> LOW");
relayState = LOW;
EEPROM.write(0, relayState); // Write state to EEPROM
EEPROM.commit();
writeOled("Garage:Closed",oledLine);
client.publish(outTopic, "Garage Closed");
} else if ((char)payload[0] == '1') {
digitalWrite(relay_pin, HIGH); // Turn the LED off by making the voltage HIGH
Serial.println("relay_pin -> HIGH");
relayState = HIGH;
EEPROM.write(0, relayState); // Write state to EEPROM
EEPROM.commit();
client.publish(outTopic, "Garage Open");
writeOled("Garage:OPEN",oledLine);
} else if ((char)payload[0] == '2') {
relayState = !relayState;
digitalWrite(relay_pin, relayState); // Turn the LED off by making the voltage HIGH
Serial.print("relay_pin -> switched to ");
Serial.println(relayState);
EEPROM.write(0, relayState); // Write state to EEPROM
EEPROM.commit();
client.publish(outTopic, "Dont know what this is...");
}
else {
writeOled("Garage:ERROR",oledLine);
client.publish(outTopic, "I didnt understand something!");
}
writeOled("DONE!!!!",oledLine);
client.publish(outTopic, "I did something!");
}