Programing code failure or wrong GPIO pin?

Here is how the relay module should be wired when the relay coils are powered from an external source.
According to your last photo you have the external power source wired incorrectly. There is no connection from ground to the ESP.

relay module.jpg