I have used the Nodemcu firmware and Lua uploader to upload the program.
Step 1: Terminologies Used
It is very confusing to start working with ESP8266 just by googling. It took me three days to understand that there are two types of firmwares and one uploader do not work with other. I have not worked with Espressif firmware as i found Nodemcu(Lua) easy for my requirements.
Links to download nodemcu-flasher:
Links to download Lua downloader:
So, first you are required to add an firmware(operating system) to the ESP8266. Then you can start with coding.
Step 2: Flashing the Firmware
Download firmware from the following link.
Procedure to build your own firmware
Your email:-provide your email id, the built firware link will be sent to your email id.
Select branch to build from: select "dev"
Select modules to include: go with the defaults or select some more.(recommanded default).
Click on "Start your build"
It will take 5 minutes to 15 minutes.
Now open the "ESP8266Flasher.exe". Goto advanced tab change the baud rate to 115200,Flash size 1Mb(depending on your module). Goto congif and select the bin file downloaded from the link received in your meail. GOTO operation and select your COM port(it will be auto select) and click on Flash. If the MAC ID is visible your flash will start otherwise just unplug the USB and connect back and click flash.Blue lights on ESP and USB will start flickering.
Step 3: Writing Code
The above picture might look same as the previous step but the GPIO to GND connection is removed.
Select COM port or justt refresh it, change baud rate to 115200.
Change the file name to "init.lua"(its like startup program).
Copy paste the code in attachment.
Change the following parameter in the code:--(do not remove the " and ' )
1) YOUR WIFI SSID
2) YOUR WIFI PASSWORD
3) GIVE ANY STATIC IP (eg: 192.168.0.007)
4) netmask and gateway of your router(gateway is your router IP eg:192.168.1.1 or 192.168.0.1)
5) GIVE IMAGE URL( open an image from google copy the link and paste it)
Then click "Save to ESP"
Blue light on ESP and USB with start flickering.
Step 4: Connection With the Relay
After uploading(Save to ESP) disconnect the USB and remove the conection with USB. and connect the ESP as per the above diagram. Instead of a different power supply the CP2102 also can be used.
Switch on the power and in your phone or laptop web browser open with STATIC IP you have given in the code.