I think I found the problem. I think it misbehaved because of an illegal character in the "HOSTNAME". Changed the hostname yesterday and It was still alive this morning even if I have not pinged it.
Hi @neelam, welcome to the forum!
The dimmer example should work. If you want to use only the esp8266 with wifi (no nrf/rfm or other radio), you'll also need to add gateway settings from https://www.mysensors.org/build/esp8266_gateway