I may need to go further into the details to get an answer, but I'm basically having issues on the i2c bus due to interferences caused by fans, heater, etc.
It may have been a mistake to go with i2c, I did not expect this behavior initially. Cables guilty for this are probably not shielded.
Anyways, when such a problem occurs, it looks like the ESP is losing communication with i2c devices (at least the LCD screen becomes empty/blank). Is there a way to detect such a thing? Like ping devices ?
Could something as simple as the following do the trick to detect this?
Wire.beginTransmission (<device_id>);
if (Wire.endTransmission () != 0) {
}
That's the way an I2C scanner is detecting devices on the bus.
You will detect a completely failed bus but given your description above your bus is not completely failing but wrong transmissions based on electrical noise.
Seems to be caused by too long I2C bus wires and noisy devices nearby. Try to put the complete I2C bus into a metal casing.
It may also help reducing the I2C speed if the problem is more the bus length than the noisy environment.
I was able to narrow down the problem to a solenoid valve used to flush the toilets. Fixed this by adding a diode (1N4007 that's all I had around) very close to the solenoid.
I'm not sure it's the only problem but I tried everything, and both ESP and LCD keep running without any issue!