I have a loop, that iterates through my sensors (items), and then sends their state via MQTT. I am running that code on ESP8266 dev boards, and on few on them, this code works, whereas on the others, it throws an exception after a random amount of time.
Now, trying to debug this, I have discovered, that, if I uncomment Serial.println()
in the line as below (it has to be that exact place, putting it on any other line, doesn't do the trick), code works perfectly stable for days. But as soon as I remove that println
, it starts crashing after more or less 100 seconds. What is happening here? What is Serial.println()
doing, that makes my code stable?
void _loop(String priority)
{
for(std::vector<IItem*>::iterator it = items.begin(); it != items.end(); ++it)
{
if ((*it)->loopPriority == priority)
{
(*it)->loop();
for (std::map<String, String>::iterator pubChannel = (*it)->pubChannels.begin(); pubChannel != (*it)->pubChannels.end(); pubChannel++ )
{
//Serial.println(pubChannel->second);
mqtt.sendMsg(pubChannel->second, (*it)->command(pubChannel->first));
}
}
}
}