As part of setup, you need to tell the wire library to use timeouts and to reset the bus if a timeout occurs.
void setup()
...
Wire.begin();
Wire.setWireTimeout(5000, TRUE); // timeout in microseconds, reset
...
and then, after every transaction, you need to test the timeout flag. You will also need to clear it if it gets set
// do some request
if ( Wire.getWireTimeoutFlag() ) {
// react to it
Wire.clearWireTimeoutFlag();
}
Since your code had your slave devices unilaterally sending data on the bus which it totally wrong, I can't say exactly where to place this other than after your transactions.