I have a piece of code that is sending an MQTT message.
The message is the same with the only change being changing action between 'on' and 'off'. I can end off as many times as I like, but when I send 'on' it locks (even if it is the first message)
Here is the code
void update_thing(int pin, String thing, String action) {
Serial.println(thing + " State Requested to " + action);
Serial.println(action.c_str());
if (action == "On") {
digitalWrite(pin, HIGH); // Pin = 5 V, LED Turns On
} else {
digitalWrite(pin, LOW); // Pin = 5 V, LED Turns Off
}
// Generate a new message
sprintf(msg, "{\"state\":{\"reported\":{\"%s\": \"%s\"}}}", thing.c_str(), action.c_str());
if((rc = myClient.publish("$aws/things/myYunLight/shadow/update", msg, strlen(msg), 1, false)) != 0) {
Serial.println("Publish failed!");
Serial.println(rc);
}
}
The issue appears to lie in the msg variable, declared as
char msg[100]; // read-write buffer
and in particular the value fed to action (or even if I remove that and use the text 'on' or 'off'. If I use 'on ' (with a space) it works fine